From 5c8888d6a82e3b2072bfcfbf1620ce6f3d0bb214 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 22 Jan 2024 17:59:12 +0900 Subject: [PATCH] enhance(reversi): render ogp --- .../src/server/web/ClientServerService.ts | 26 ++++++++++++++++++- .../src/server/web/views/reversi-game.pug | 20 ++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 packages/backend/src/server/web/views/reversi-game.pug diff --git a/packages/backend/src/server/web/ClientServerService.ts b/packages/backend/src/server/web/ClientServerService.ts index 2de5156fec..65b21694f8 100644 --- a/packages/backend/src/server/web/ClientServerService.ts +++ b/packages/backend/src/server/web/ClientServerService.ts @@ -31,12 +31,13 @@ import { PageEntityService } from '@/core/entities/PageEntityService.js'; import { GalleryPostEntityService } from '@/core/entities/GalleryPostEntityService.js'; import { ClipEntityService } from '@/core/entities/ClipEntityService.js'; import { ChannelEntityService } from '@/core/entities/ChannelEntityService.js'; -import type { ChannelsRepository, ClipsRepository, FlashsRepository, GalleryPostsRepository, MiMeta, NotesRepository, PagesRepository, UserProfilesRepository, UsersRepository } from '@/models/_.js'; +import type { ChannelsRepository, ClipsRepository, FlashsRepository, GalleryPostsRepository, MiMeta, NotesRepository, PagesRepository, ReversiGamesRepository, UserProfilesRepository, UsersRepository } from '@/models/_.js'; import type Logger from '@/logger.js'; import { deepClone } from '@/misc/clone.js'; import { bindThis } from '@/decorators.js'; import { FlashEntityService } from '@/core/entities/FlashEntityService.js'; import { RoleService } from '@/core/RoleService.js'; +import { ReversiGameEntityService } from '@/core/entities/ReversiGameEntityService.js'; import { FeedService } from './FeedService.js'; import { UrlPreviewService } from './UrlPreviewService.js'; import { ClientLoggerService } from './ClientLoggerService.js'; @@ -83,6 +84,9 @@ export class ClientServerService { @Inject(DI.flashsRepository) private flashsRepository: FlashsRepository, + @Inject(DI.reversiGamesRepository) + private reversiGamesRepository: ReversiGamesRepository, + private flashEntityService: FlashEntityService, private userEntityService: UserEntityService, private noteEntityService: NoteEntityService, @@ -90,6 +94,7 @@ export class ClientServerService { private galleryPostEntityService: GalleryPostEntityService, private clipEntityService: ClipEntityService, private channelEntityService: ChannelEntityService, + private reversiGameEntityService: ReversiGameEntityService, private metaService: MetaService, private urlPreviewService: UrlPreviewService, private feedService: FeedService, @@ -686,6 +691,25 @@ export class ClientServerService { return await renderBase(reply); } }); + + // Reversi game + fastify.get<{ Params: { channel: string; } }>('/reversi/g/:game', async (request, reply) => { + const game = await this.reversiGamesRepository.findOneBy({ + id: request.params.game, + }); + + if (game) { + const _game = await this.reversiGameEntityService.packDetail(game); + const meta = await this.metaService.fetch(); + reply.header('Cache-Control', 'public, max-age=3600'); + return await reply.view('reversi-game', { + game: _game, + ...this.generateCommonPugData(meta), + }); + } else { + return await renderBase(reply); + } + }); //#endregion fastify.get('/_info_card_', async (request, reply) => { diff --git a/packages/backend/src/server/web/views/reversi-game.pug b/packages/backend/src/server/web/views/reversi-game.pug new file mode 100644 index 0000000000..0b5ffb2bb0 --- /dev/null +++ b/packages/backend/src/server/web/views/reversi-game.pug @@ -0,0 +1,20 @@ +extends ./base + +block vars + - const user1 = game.user1; + - const user2 = game.user2; + - const title = `${user1.username} vs ${user2.username}`; + - const url = `${config.url}/reversi/g/${game.id}`; + +block title + = `${title} | ${instanceName}` + +block desc + meta(name='description' content='⚫⚪Misskey Reversi⚪⚫') + +block og + meta(property='og:type' content='article') + meta(property='og:title' content= title) + meta(property='og:description' content='⚫⚪Misskey Reversi⚪⚫') + meta(property='og:url' content= url) + meta(property='twitter:card' content='summary')