2023-06-07 08:58:53 +02:00
|
|
|
#!/usr/bin/env python3
|
2023-06-08 10:54:36 +02:00
|
|
|
"""Creatr App"""
|
2023-07-06 17:49:54 +02:00
|
|
|
from flask import Flask, Response, request, Request, abort, jsonify
|
2023-06-13 08:11:29 +02:00
|
|
|
from demo.utils.checker import inbox_prechecker
|
2023-07-06 17:49:54 +02:00
|
|
|
from demo import config
|
2023-06-07 08:58:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
2023-07-08 10:58:53 +02:00
|
|
|
def is_ap_requested(ap_request: Request) -> bool:
|
|
|
|
"""Check request accept headers."""
|
|
|
|
accept_str = ap_request.headers.get("accept")
|
2023-07-06 17:49:54 +02:00
|
|
|
if accept_str is None:
|
|
|
|
return False
|
2023-07-08 10:58:53 +02:00
|
|
|
for i in [
|
2023-07-06 17:49:54 +02:00
|
|
|
"application/activity+json",
|
|
|
|
"application/ld+json",
|
2023-07-08 10:58:53 +02:00
|
|
|
]:
|
2023-07-06 17:49:54 +02:00
|
|
|
if accept_str.startswith(i):
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2023-06-07 08:58:53 +02:00
|
|
|
@app.route('/')
|
2023-06-08 10:54:36 +02:00
|
|
|
def index():
|
|
|
|
"""Show index page"""
|
2023-06-07 08:58:53 +02:00
|
|
|
return "Hello Fediverse!"
|
2023-06-13 08:11:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
@app.route("/inbox", methods=["POST"])
|
|
|
|
def inbox():
|
|
|
|
"""Process inbox request"""
|
|
|
|
is_verify = inbox_prechecker(request)
|
|
|
|
if is_verify:
|
|
|
|
return "STUB"
|
|
|
|
return "STUB"
|
2023-07-06 17:49:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
@app.route("/.well-known/webfinger")
|
|
|
|
def wellknown_webfinger() -> Response:
|
|
|
|
"""Exposes servers WebFinger data."""
|
|
|
|
resource = request.args.get("resource")
|
|
|
|
|
|
|
|
if resource not in [f"acct:{config.USERNAME}@{config.DOMAIN}", config.ID]:
|
|
|
|
abort(404)
|
|
|
|
|
|
|
|
resp = jsonify(
|
|
|
|
{
|
|
|
|
"subject": f"acct:{config.USERNAME}@{config.DOMAIN}",
|
|
|
|
"aliases": [config.ID],
|
|
|
|
"links": [
|
|
|
|
{
|
|
|
|
"rel": "http://webfinger.net/rel/profile-page",
|
|
|
|
"type": "text/html",
|
|
|
|
"href": config.ID,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"rel": "self",
|
|
|
|
"type": "application/activity+json",
|
|
|
|
"href": config.ID,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
)
|
|
|
|
resp.headers["Access-Control-Allow-Origin"] = "*"
|
|
|
|
resp.headers["Content-Type"] = "application/jrd+json; charset=utf-8"
|
|
|
|
|
|
|
|
return resp
|