From 41e3a9a004b53fb81f8250d6d0fc369445e69037 Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Wed, 2 Jan 2019 18:07:32 +0900 Subject: [PATCH] Tune AP URL negotiating with Accept (#3824) --- src/server/activitypub.ts | 6 ++++-- src/server/web/index.ts | 28 +++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/server/activitypub.ts b/src/server/activitypub.ts index 42d90ab91..9adc3dd94 100644 --- a/src/server/activitypub.ts +++ b/src/server/activitypub.ts @@ -83,7 +83,7 @@ router.get('/notes/:note', async (ctx, next) => { } ctx.body = pack(await renderNote(note, false)); - ctx.set('Cache-Control', 'private, max-age=0, must-revalidate'); + ctx.set('Cache-Control', 'public, max-age=180'); setResponseType(ctx); }); @@ -162,7 +162,9 @@ async function userInfo(ctx: Router.IRouterContext, user: IUser) { setResponseType(ctx); } -router.get('/users/:user', async ctx => { +router.get('/users/:user', async (ctx, next) => { + if (!isActivityPubReq(ctx)) return await next(); + if (!ObjectID.isValid(ctx.params.user)) { ctx.status = 404; return; diff --git a/src/server/web/index.ts b/src/server/web/index.ts index 998fd2adf..59b8390ab 100644 --- a/src/server/web/index.ts +++ b/src/server/web/index.ts @@ -148,6 +148,27 @@ router.get('/@:user', async (ctx, next) => { } }); +router.get('/users/:user', async ctx => { + if (!ObjectID.isValid(ctx.params.user)) { + ctx.status = 404; + return; + } + + const userId = new ObjectID(ctx.params.user); + + const user = await User.findOne({ + _id: userId, + host: null + }); + + if (user === null) { + ctx.status = 404; + return; + } + + ctx.redirect(`/@${user.username}${ user.host == null ? '' : '@' + user.host}`); +}); + // Note router.get('/notes/:note', async ctx => { if (ObjectID.isValid(ctx.params.note)) { @@ -159,7 +180,12 @@ router.get('/notes/:note', async ctx => { note: _note, summary: getNoteSummary(_note) }); - ctx.set('Cache-Control', 'private, max-age=0, must-revalidate'); + + if (['public', 'home'].includes(note.visibility)) { + ctx.set('Cache-Control', 'public, max-age=180'); + } else { + ctx.set('Cache-Control', 'private, max-age=0, must-revalidate'); + } return; }