From 7f419a990422226fac16fa652ffd2cdf2d1bb0c3 Mon Sep 17 00:00:00 2001 From: Chaiwat Suttipongsakul Date: Tue, 29 Jan 2019 11:08:52 +0700 Subject: [PATCH] json/atom/rss feed --- activitypub.py | 10 +++++----- app.py | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/activitypub.py b/activitypub.py index 51557fa..9185745 100644 --- a/activitypub.py +++ b/activitypub.py @@ -523,8 +523,8 @@ def gen_feed(): fg.logo(ME.get("icon", {}).get("url")) fg.language("en") for item in DB.activities.find( - {"box": Box.OUTBOX.value, "type": "Create"}, limit=50 - ): + {"box": Box.OUTBOX.value, "type": "Create", "meta.deleted": False}, limit=10 + ).sort("_id", -1): fe = fg.add_entry() fe.id(item["activity"]["object"].get("url")) fe.link(href=item["activity"]["object"].get("url")) @@ -537,11 +537,11 @@ def json_feed(path: str) -> Dict[str, Any]: """JSON Feed (https://jsonfeed.org/) document.""" data = [] for item in DB.activities.find( - {"box": Box.OUTBOX.value, "type": "Create"}, limit=50 - ): + {"box": Box.OUTBOX.value, "type": "Create", "meta.deleted": False}, limit=10 + ).sort("_id", -1): data.append( { - "id": item["id"], + "id": item["activity"]["id"], "url": item["activity"]["object"].get("url"), "content_html": item["activity"]["object"]["content"], "content_text": html2text(item["activity"]["object"]["content"]), diff --git a/app.py b/app.py index 30c8241..5e682d0 100644 --- a/app.py +++ b/app.py @@ -2167,3 +2167,29 @@ def token_endpoint(): "client_id": payload["client_id"], } ) + + +@app.route("/feed.json") +def json_feed(): + return Response( + response=json.dumps( + activitypub.json_feed("/feed.json") + ), + headers={"Content-Type": "application/json"}, + ) + + +@app.route("/feed.atom") +def atom_feed(): + return Response( + response=activitypub.gen_feed().atom_str(), + headers={"Content-Type": "application/atom+xml"}, + ) + + +@app.route("/feed.rss") +def rss_feed(): + return Response( + response=activitypub.gen_feed().rss_str(), + headers={"Content-Type": "application/rss+xml"}, + )