From c380a178f0388537ccf8a68f7c2c00deee3ea1f8 Mon Sep 17 00:00:00 2001 From: Moon Man Date: Sun, 31 Dec 2023 12:21:29 -0500 Subject: [PATCH] attempt at html and note instead of article and markdown --- src/activity.ts | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/activity.ts b/src/activity.ts index d522a5e..9b1024e 100644 --- a/src/activity.ts +++ b/src/activity.ts @@ -1,4 +1,5 @@ import { readFileSync } from "node:fs"; +import markdownit from "markdown-it"; import { Article } from "./article.js"; import { User, getByActor } from "./user.js"; import { fillRoute } from "./router.js"; @@ -13,6 +14,8 @@ export const CONTEXT = "https://www.w3.org/ns/activitystreams"; export const PUBLIC = CONTEXT + "#Public"; export const TYPE = "application/activity+json"; +const md = markdownit(); + export const handleInboxPost = async (req: Request, res: Response) => { try { if (!req.body) { @@ -34,9 +37,13 @@ export const handleInboxPost = async (req: Request, res: Response) => { return; } - console.log("inbox POST:", req.url, req.body); + console.log("inbox POST:", activity.type); - if (activity.type === "Follow") { + if (activity.type === "Delete") { + res.status(202).end(); + return; + } + else if (activity.type === "Follow") { console.log(JSON.stringify(activity, null, 4)); const actor = await getByActor(activity.object); @@ -151,13 +158,17 @@ export const createArticleActivity = (article: Article, user: User) => { id: objectId, actor, attributedTo: actor, - type: "Article", + type: "Note", context, - content, + content: md.render(content), to: [PUBLIC], cc: [followers], url: canonicalUrl, - mediaType: "text/markdown", + mediaType: "text/html", + source: { + mediaType: "text/markdown", + content + }, published }; @@ -177,13 +188,17 @@ export const createArticleObject = (article: Article, nickname: string) => { id: objectId, actor, attributedTo: actor, - type: "Article", + type: "Note", context, - content, + content: md.render(content), to: [PUBLIC], cc: [followers], url: canonicalUrl, - mediaType: "text/markdown", + mediaType: "text/html", + source: { + mediaType: "text/markdown", + content + }, published }