diff --git a/src/index.ts b/src/index.ts index 15274e7..e24a525 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,11 +3,18 @@ import bodyParser from "body-parser"; import { toCollection as getOutbox } from "./outbox.js"; import { getById as getUserById, getNickname, get as getUserByNickname, getId as getUserId, User } from "./user.js"; import { Routes } from "./router.js"; -import { getBySlug as getArticleBySlug, getById } from "./article.js"; -import { userToPerson, TYPE as ACTIVITYPUB_TYPE, handleInboxPost, createArticleObject, CONTEXT, createArticleActivity, TYPE } from "./activity.js"; +import { getBySlug as getArticleBySlug, getById, getByUserId } from "./article.js"; +import { userToPerson, TYPE as ACTIVITYPUB_TYPE, handleInboxPost, createArticleObject, CONTEXT, createArticleActivity } from "./activity.js"; import { handleFollowerGet } from "./follower.js"; import { handleWebfingerGet } from "./net.js"; +const escapeHtml = (unsafe: string) => unsafe + .replaceAll("&", "&") + .replaceAll("<", "<") + .replaceAll(">", ">") + .replaceAll("\"", """) + .replace("'", "'"); + const port = parseInt(process.env.port || "8080"); const app = express(); @@ -95,18 +102,33 @@ app.get(Routes.actor, async (req, res) => { const actor = await getUserByNickname(nickname); if (actor) { - const accept = req.headers["accept"] || ""; - if (accept.includes(ACTIVITYPUB_TYPE)) { + if (req.accepts("html")) { + const posts = (await getByUserId(actor.id)).map((a) => `
+ Bio: ${escapeHtml(actor.bio)} +
+ Posts:
+