better accept handling, maybe
This commit is contained in:
parent
8dafbfc0d9
commit
a292552a3f
20
src/index.ts
20
src/index.ts
|
@ -41,13 +41,16 @@ app.get(Routes.object, async (req, res) => {
|
||||||
const obj = createArticleObject(article, nickname);
|
const obj = createArticleObject(article, nickname);
|
||||||
obj["@context"] = CONTEXT;
|
obj["@context"] = CONTEXT;
|
||||||
|
|
||||||
|
console.log(`returning object id: ${article.id} as json`);
|
||||||
res.append("Content-Type", ACTIVITYPUB_TYPE);
|
res.append("Content-Type", ACTIVITYPUB_TYPE);
|
||||||
res.send(JSON.stringify(obj, null, 4));
|
res.send(JSON.stringify(obj, null, 4));
|
||||||
}
|
}
|
||||||
else if (req.accepts(["text/plain", "text/markdown"])) {
|
else if (req.accepts(["text/plain", "text/markdown"])) {
|
||||||
|
console.log(`redirecting object id: ${article.id} to markdown`);
|
||||||
res.redirect(`/${article.slug}.md`);
|
res.redirect(`/${article.slug}.md`);
|
||||||
}
|
}
|
||||||
else {
|
else if (req.accepts("html")) {
|
||||||
|
console.log(`redirecting object id: ${article.id} to html`);
|
||||||
res.redirect(`/${article.slug}.html`);
|
res.redirect(`/${article.slug}.html`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,15 +79,21 @@ app.get(Routes.activity, async (req, res) => {
|
||||||
const user = await getUserById(article.users_id) as User;
|
const user = await getUserById(article.users_id) as User;
|
||||||
const activity = createArticleActivity(article, user);
|
const activity = createArticleActivity(article, user);
|
||||||
|
|
||||||
|
console.log(`returning activity id: ${id} as json`);
|
||||||
res.append("Content-Type", ACTIVITYPUB_TYPE);
|
res.append("Content-Type", ACTIVITYPUB_TYPE);
|
||||||
res.send(JSON.stringify(activity, null, 4));
|
res.send(JSON.stringify(activity, null, 4));
|
||||||
}
|
}
|
||||||
else if (req.accepts(["text/plain", "text/markdown"])) {
|
else if (req.accepts(["text/plain", "text/markdown"])) {
|
||||||
|
console.log(`redirecting activity id: ${id} to markdown`);
|
||||||
res.redirect(`/${article.slug}.md`);
|
res.redirect(`/${article.slug}.md`);
|
||||||
}
|
}
|
||||||
else {
|
else if (req.accepts("html")) {
|
||||||
|
console.log(`redirecting activity id: ${id} to html`);
|
||||||
res.redirect(`/${article.slug}.html`);
|
res.redirect(`/${article.slug}.html`);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
res.status(406).end();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
res.status(404).end();
|
res.status(404).end();
|
||||||
|
@ -121,10 +130,12 @@ app.get(Routes.actor, async (req, res) => {
|
||||||
const obj = userToPerson(actor);
|
const obj = userToPerson(actor);
|
||||||
const body = JSON.stringify(obj, null, 4);
|
const body = JSON.stringify(obj, null, 4);
|
||||||
|
|
||||||
|
console.log(`returning actor: ${nickname} as json`);
|
||||||
res.set("Content-Type", ACTIVITYPUB_TYPE);
|
res.set("Content-Type", ACTIVITYPUB_TYPE);
|
||||||
res.send(body);
|
res.send(body);
|
||||||
}
|
}
|
||||||
else {
|
else if (req.accepts("html")) {
|
||||||
|
console.log(`returning actor: ${nickname} as html`);
|
||||||
const posts = (await getByUserId(actor.id)).map((a) => `<li><a href="/${a.slug}.html">${escapeHtml(a.title)}</a></li>`).join("");
|
const posts = (await getByUserId(actor.id)).map((a) => `<li><a href="/${a.slug}.html">${escapeHtml(a.title)}</a></li>`).join("");
|
||||||
|
|
||||||
const body = `<!DOCTYPE html>
|
const body = `<!DOCTYPE html>
|
||||||
|
@ -144,6 +155,9 @@ app.get(Routes.actor, async (req, res) => {
|
||||||
res.set("Content-Type", "text/html; charset=utf-8");
|
res.set("Content-Type", "text/html; charset=utf-8");
|
||||||
res.send(body);
|
res.send(body);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
res.status(406).end();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
res.status(404).send("actor not found");
|
res.status(404).send("actor not found");
|
||||||
|
|
Loading…
Reference in New Issue