From 021d523d5f62506aec248ae2b454a9f1974549d8 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Wed, 16 Nov 2022 19:38:32 -0500 Subject: [PATCH] backend: fix activitypub.ts lints --- packages/backend/src/server/activitypub.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/backend/src/server/activitypub.ts b/packages/backend/src/server/activitypub.ts index 6cc767496..2dc4ea1e7 100644 --- a/packages/backend/src/server/activitypub.ts +++ b/packages/backend/src/server/activitypub.ts @@ -23,7 +23,7 @@ import Featured from './activitypub/featured.js'; // Init router const router = new Router(); -function inbox(ctx: Router.RouterContext) { +function inbox(ctx: Router.RouterContext): void { let signature; try { @@ -41,7 +41,7 @@ function inbox(ctx: Router.RouterContext) { const ACTIVITY_JSON = 'application/activity+json; charset=utf-8'; const LD_JSON = 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"; charset=utf-8'; -function isActivityPubReq(ctx: Router.RouterContext) { +function isActivityPubReq(ctx: Router.RouterContext): boolean { ctx.response.vary('Accept'); // if no accept header is supplied, koa returns the 1st, so html is used as a dummy // i.e. activitypub requests must be explicit @@ -49,7 +49,7 @@ function isActivityPubReq(ctx: Router.RouterContext) { return typeof accepted === 'string' && !accepted.match(/html/); } -export function setResponseType(ctx: Router.RouterContext) { +export function setResponseType(ctx: Router.RouterContext): void { const accept = ctx.accepts(ACTIVITY_JSON, LD_JSON); if (accept === LD_JSON) { ctx.response.type = LD_JSON; @@ -158,7 +158,7 @@ router.get('/users/:user/publickey', async ctx => { }); // user -async function userInfo(ctx: Router.RouterContext, user: User | null) { +async function userInfo(ctx: Router.RouterContext, user: User | null): Promise { if (user == null) { ctx.status = 404; return; @@ -214,6 +214,13 @@ router.get('/emojis/:emoji', async ctx => { // like router.get('/likes/:like', async ctx => { + const reaction = await NoteReactions.findOneBy({ id: ctx.params.like }); + + if (reaction == null) { + ctx.status = 404; + return; + } + const note = await Notes.findOneBy({ id: reaction.noteId, visibility: In(['public' as const, 'home' as const]), @@ -224,13 +231,6 @@ router.get('/likes/:like', async ctx => { return; } - const reaction = await NoteReactions.findOneBy({ id: ctx.params.like }); - - if (reaction == null) { - ctx.status = 404; - return; - } - ctx.body = renderActivity(await renderLike(reaction, note)); ctx.set('Cache-Control', 'public, max-age=180'); setResponseType(ctx);