From 869ed215a3497f2a773c0e791fcac11c57c4bdc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Thu, 12 Jan 2023 14:13:05 +0000 Subject: [PATCH] raw content display --- app/ap_object.py | 8 ++++++++ app/main.py | 22 ++++++++++++++++++++++ app/templates/utils.html | 22 ++++++++++++++++++++-- 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/app/ap_object.py b/app/ap_object.py index 77586aa..f65f7e8 100644 --- a/app/ap_object.py +++ b/app/ap_object.py @@ -184,6 +184,14 @@ class Object: return content + @cached_property + def raw_content(self) -> str | None: + raw_content = self.ap_object.get("content") + if not raw_content: + return None + + return markdown(raw_content) + @property def summary(self) -> str | None: return self.ap_object.get("summary") diff --git a/app/main.py b/app/main.py index b40e89b..de25460 100644 --- a/app/main.py +++ b/app/main.py @@ -1531,6 +1531,28 @@ async def serve_proxy_media_resized( ) +@app.get("/raw_object") +async def serve_raw_object( + request: Request, + ap_id: str, + db_session: AsyncSession = Depends(get_db_session), +) -> PlainTextResponse: + requested_object = await boxes.get_anybox_object_by_ap_id(db_session, ap_id) + if not requested_object or requested_object.is_deleted: + raise HTTPException(status_code=404) + + if not hasattr(requested_object, 'source'): + return PlainTextResponse( + requested_object.ap_object.get("content"), + headers={"Content-Type": "text/plain"}, + ) + + return PlainTextResponse( + requested_object.source, + headers={"Content-Type": "text/plain"}, + ) + + @app.get("/attachments/{content_hash}/{filename}") async def serve_attachment( content_hash: str, diff --git a/app/templates/utils.html b/app/templates/utils.html index d88a881..f65644f 100644 --- a/app/templates/utils.html +++ b/app/templates/utils.html @@ -510,8 +510,17 @@