perf(embed): improve embed performance (#14613)
* wip * wip * wip * refactor * refactor --------- Co-authored-by: かっこかり <67428053+kakkokari-gtyih@users.noreply.github.com>
This commit is contained in:
		| @@ -785,6 +785,72 @@ export class ClientServerService { | ||||
| 		//#endregion | ||||
|  | ||||
| 		//#region embed pages | ||||
| 		fastify.get<{ Params: { user: string; } }>('/embed/user-timeline/:user', async (request, reply) => { | ||||
| 			reply.removeHeader('X-Frame-Options'); | ||||
|  | ||||
| 			const user = await this.usersRepository.findOneBy({ | ||||
| 				id: request.params.user, | ||||
| 			}); | ||||
|  | ||||
| 			if (user == null) return; | ||||
| 			if (user.host != null) return; | ||||
|  | ||||
| 			const _user = await this.userEntityService.pack(user); | ||||
|  | ||||
| 			reply.header('Cache-Control', 'public, max-age=3600'); | ||||
| 			return await reply.view('base-embed', { | ||||
| 				title: this.meta.name ?? 'Misskey', | ||||
| 				...await this.generateCommonPugData(this.meta), | ||||
| 				embedCtx: htmlSafeJsonStringify({ | ||||
| 					user: _user, | ||||
| 				}), | ||||
| 			}); | ||||
| 		}); | ||||
|  | ||||
| 		fastify.get<{ Params: { note: string; } }>('/embed/notes/:note', async (request, reply) => { | ||||
| 			reply.removeHeader('X-Frame-Options'); | ||||
|  | ||||
| 			const note = await this.notesRepository.findOneBy({ | ||||
| 				id: request.params.note, | ||||
| 			}); | ||||
|  | ||||
| 			if (note == null) return; | ||||
| 			if (note.visibility !== 'public') return; | ||||
| 			if (note.userHost != null) return; | ||||
|  | ||||
| 			const _note = await this.noteEntityService.pack(note, null, { detail: true }); | ||||
|  | ||||
| 			reply.header('Cache-Control', 'public, max-age=3600'); | ||||
| 			return await reply.view('base-embed', { | ||||
| 				title: this.meta.name ?? 'Misskey', | ||||
| 				...await this.generateCommonPugData(this.meta), | ||||
| 				embedCtx: htmlSafeJsonStringify({ | ||||
| 					note: _note, | ||||
| 				}), | ||||
| 			}); | ||||
| 		}); | ||||
|  | ||||
| 		fastify.get<{ Params: { clip: string; } }>('/embed/clips/:clip', async (request, reply) => { | ||||
| 			reply.removeHeader('X-Frame-Options'); | ||||
|  | ||||
| 			const clip = await this.clipsRepository.findOneBy({ | ||||
| 				id: request.params.clip, | ||||
| 			}); | ||||
|  | ||||
| 			if (clip == null) return; | ||||
|  | ||||
| 			const _clip = await this.clipEntityService.pack(clip); | ||||
|  | ||||
| 			reply.header('Cache-Control', 'public, max-age=3600'); | ||||
| 			return await reply.view('base-embed', { | ||||
| 				title: this.meta.name ?? 'Misskey', | ||||
| 				...await this.generateCommonPugData(this.meta), | ||||
| 				embedCtx: htmlSafeJsonStringify({ | ||||
| 					clip: _clip, | ||||
| 				}), | ||||
| 			}); | ||||
| 		}); | ||||
|  | ||||
| 		fastify.get('/embed/*', async (request, reply) => { | ||||
| 			reply.removeHeader('X-Frame-Options'); | ||||
|  | ||||
|   | ||||
| @@ -43,6 +43,9 @@ html(class='embed') | ||||
| 		script(type='application/json' id='misskey_meta' data-generated-at=now) | ||||
| 			!= metaJson | ||||
|  | ||||
| 		script(type='application/json' id='misskey_embedCtx' data-generated-at=now) | ||||
| 			!= embedCtx | ||||
|  | ||||
| 		script | ||||
| 			include ../boot.embed.js | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 syuilo
					syuilo