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) => `
  • ${escapeHtml(a.title)}
  • `).join(""); + + const body = ` + + username: ${escapeHtml(actor.nickname)} +
    + Name: ${escapeHtml(actor.name)} +

    + Bio: ${escapeHtml(actor.bio)} +

    + Posts:
    +

    + `; + + res.set("Content-Type", "text/html; charset=utf-8"); + res.send(body); + } + else { const obj = userToPerson(actor); const body = JSON.stringify(obj, null, 4); res.set("Content-Type", ACTIVITYPUB_TYPE); res.send(body); } - else { - // TODO: html version. - res.status(403).send("todo"); - } } else { res.status(404).send("actor not found");