From e2d814a456cba71c873b53c379fcc5037e9c467a Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sun, 22 Jul 2018 21:34:42 +0200 Subject: [PATCH] Use the toot namespace/AP extension --- app.py | 18 ++++++++---------- config.py | 7 ++----- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/app.py b/app.py index 5791b18..b927d47 100644 --- a/app.py +++ b/app.py @@ -276,9 +276,9 @@ def domain(url): @app.template_filter() def url_or_id(d): - if 'url' in d: - return d['url'] - return d['id'] + if "url" in d: + return d["url"] + return d["id"] @app.template_filter() @@ -355,6 +355,7 @@ def is_img(filename): def add_response_headers(headers={}): """This decorator adds the headers passed in to the response""" + def decorator(f): @wraps(f) def decorated_function(*args, **kwargs): @@ -363,13 +364,15 @@ def add_response_headers(headers={}): for header, value in headers.items(): h[header] = value return resp + return decorated_function + return decorator def noindex(f): """This decorator passes X-Robots-Tag: noindex, nofollow""" - return add_response_headers({'X-Robots-Tag': 'noindex, nofollow'})(f) + return add_response_headers({"X-Robots-Tag": "noindex, nofollow"})(f) def login_required(f): @@ -415,7 +418,7 @@ def api_required(f): def jsonify(**data): if "@context" not in data: - data["@context"] = config.CTX_AS + data["@context"] = config.DEFAULT_CTX return Response( response=json.dumps(data), headers={ @@ -978,11 +981,6 @@ def wellknown_nodeinfo(): ) -# @app.route('/fake_feed') -# def fake_feed(): -# return 'https://lol3.tun.a4.io/fake_feedhttps://lol3.tun.a4.io/fake' - - @app.route("/.well-known/webfinger") def wellknown_webfinger(): """Enable WebFinger support, required for Mastodon interopability.""" diff --git a/config.py b/config.py index 10b0bb5..d824611 100644 --- a/config.py +++ b/config.py @@ -9,6 +9,7 @@ import sass import yaml from itsdangerous import JSONWebSignatureSerializer from little_boxes import strtobool +from little_boxes.activitypub import DEFAULT_CTX from pymongo import MongoClient from utils.key import KEY_DIR @@ -46,10 +47,6 @@ VERSION = ( DEBUG_MODE = strtobool(os.getenv("MICROBLOGPUB_DEBUG", "false")) - -CTX_AS = "https://www.w3.org/ns/activitystreams" -CTX_SECURITY = "https://w3id.org/security/v1" -AS_PUBLIC = "https://www.w3.org/ns/activitystreams#Public" HEADERS = [ "application/activity+json", "application/ld+json;profile=https://www.w3.org/ns/activitystreams", @@ -129,7 +126,7 @@ def _admin_jwt_token() -> str: ADMIN_API_KEY = get_secret_key("admin_api_key", _admin_jwt_token) ME = { - "@context": [CTX_AS, CTX_SECURITY], + "@context": DEFAULT_CTX, "type": "Person", "id": ID, "following": ID + "/following",