Tune AP URL negotiating with Accept (#3824)
This commit is contained in:
		
							parent
							
								
									96515c4544
								
							
						
					
					
						commit
						41e3a9a004
					
				|  | @ -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; | ||||
|  |  | |||
|  | @ -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; | ||||
| 		} | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue