forked from FoundKeyGang/FoundKey
backend: fix activitypub.ts lints
This commit is contained in:
parent
848b9bcdf1
commit
021d523d5f
1 changed files with 11 additions and 11 deletions
|
@ -23,7 +23,7 @@ import Featured from './activitypub/featured.js';
|
||||||
// Init router
|
// Init router
|
||||||
const router = new Router();
|
const router = new Router();
|
||||||
|
|
||||||
function inbox(ctx: Router.RouterContext) {
|
function inbox(ctx: Router.RouterContext): void {
|
||||||
let signature;
|
let signature;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -41,7 +41,7 @@ function inbox(ctx: Router.RouterContext) {
|
||||||
const ACTIVITY_JSON = 'application/activity+json; charset=utf-8';
|
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';
|
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');
|
ctx.response.vary('Accept');
|
||||||
// if no accept header is supplied, koa returns the 1st, so html is used as a dummy
|
// if no accept header is supplied, koa returns the 1st, so html is used as a dummy
|
||||||
// i.e. activitypub requests must be explicit
|
// i.e. activitypub requests must be explicit
|
||||||
|
@ -49,7 +49,7 @@ function isActivityPubReq(ctx: Router.RouterContext) {
|
||||||
return typeof accepted === 'string' && !accepted.match(/html/);
|
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);
|
const accept = ctx.accepts(ACTIVITY_JSON, LD_JSON);
|
||||||
if (accept === LD_JSON) {
|
if (accept === LD_JSON) {
|
||||||
ctx.response.type = LD_JSON;
|
ctx.response.type = LD_JSON;
|
||||||
|
@ -158,7 +158,7 @@ router.get('/users/:user/publickey', async ctx => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// user
|
// user
|
||||||
async function userInfo(ctx: Router.RouterContext, user: User | null) {
|
async function userInfo(ctx: Router.RouterContext, user: User | null): Promise<void> {
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
ctx.status = 404;
|
ctx.status = 404;
|
||||||
return;
|
return;
|
||||||
|
@ -214,6 +214,13 @@ router.get('/emojis/:emoji', async ctx => {
|
||||||
|
|
||||||
// like
|
// like
|
||||||
router.get('/likes/:like', async ctx => {
|
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({
|
const note = await Notes.findOneBy({
|
||||||
id: reaction.noteId,
|
id: reaction.noteId,
|
||||||
visibility: In(['public' as const, 'home' as const]),
|
visibility: In(['public' as const, 'home' as const]),
|
||||||
|
@ -224,13 +231,6 @@ router.get('/likes/:like', async ctx => {
|
||||||
return;
|
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.body = renderActivity(await renderLike(reaction, note));
|
||||||
ctx.set('Cache-Control', 'public, max-age=180');
|
ctx.set('Cache-Control', 'public, max-age=180');
|
||||||
setResponseType(ctx);
|
setResponseType(ctx);
|
||||||
|
|
Loading…
Reference in a new issue