Skip to content

Commit

Permalink
enhance(reversi): render ogp
Browse files Browse the repository at this point in the history
  • Loading branch information
syuilo committed Jan 22, 2024
1 parent 4af3640 commit 5c8888d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
26 changes: 25 additions & 1 deletion packages/backend/src/server/web/ClientServerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -83,13 +84,17 @@ export class ClientServerService {
@Inject(DI.flashsRepository)
private flashsRepository: FlashsRepository,

@Inject(DI.reversiGamesRepository)
private reversiGamesRepository: ReversiGamesRepository,

private flashEntityService: FlashEntityService,
private userEntityService: UserEntityService,
private noteEntityService: NoteEntityService,
private pageEntityService: PageEntityService,
private galleryPostEntityService: GalleryPostEntityService,
private clipEntityService: ClipEntityService,
private channelEntityService: ChannelEntityService,
private reversiGameEntityService: ReversiGameEntityService,
private metaService: MetaService,
private urlPreviewService: UrlPreviewService,
private feedService: FeedService,
Expand Down Expand Up @@ -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) => {
Expand Down
20 changes: 20 additions & 0 deletions packages/backend/src/server/web/views/reversi-game.pug
Original file line number Diff line number Diff line change
@@ -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')

0 comments on commit 5c8888d

Please sign in to comment.