From 912791b3ab6a7cb6cbfda2aa9e15d95115770a5e Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 29 Dec 2022 10:14:44 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=B5=B5=E6=96=87=E5=AD=97URL?= =?UTF-8?q?=E3=82=92=E5=BC=95=E3=81=8D=E5=9B=9E=E3=81=99=E3=81=AE=E3=82=92?= =?UTF-8?q?=E3=82=84=E3=82=81=E3=82=8B=20(#9423)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/core/entities/EmojiEntityService.ts | 8 +++-- packages/backend/src/models/schema/emoji.ts | 2 +- .../backend/src/server/api/endpoints/meta.ts | 3 +- .../src/server/web/ClientServerService.ts | 32 ++++++++++++++++++- packages/frontend/src/components/MkNote.vue | 6 ++-- .../src/components/MkNoteDetailed.vue | 6 ++-- .../frontend/src/components/MkNoteSimple.vue | 2 +- .../frontend/src/components/MkNoteSub.vue | 2 +- .../src/components/MkNotification.vue | 14 ++++---- packages/frontend/src/components/MkPoll.vue | 2 +- .../src/components/MkReactionIcon.vue | 3 +- .../src/components/MkReactionTooltip.vue | 3 +- .../components/MkReactionsViewer.details.vue | 3 +- .../components/MkReactionsViewer.reaction.vue | 2 +- .../src/components/MkSubNoteContent.vue | 2 +- .../frontend/src/components/MkUserInfo.vue | 2 +- .../frontend/src/components/MkUserPreview.vue | 2 +- .../src/components/global/MkEmoji.vue | 16 ++++------ .../global/MkMisskeyFlavoredMarkdown.vue | 3 +- .../src/components/global/MkUserName.vue | 2 +- packages/frontend/src/components/mfm.ts | 5 --- packages/frontend/src/instance.ts | 1 + packages/frontend/src/pages/about-misskey.vue | 2 +- .../frontend/src/pages/follow-requests.vue | 2 +- packages/frontend/src/pages/user/home.vue | 6 ++-- .../frontend/src/pages/user/reactions.vue | 2 +- .../frontend/src/pages/welcome.timeline.vue | 2 +- .../src/ui/_common_/statusbar-user-list.vue | 2 +- 28 files changed, 79 insertions(+), 58 deletions(-) diff --git a/packages/backend/src/core/entities/EmojiEntityService.ts b/packages/backend/src/core/entities/EmojiEntityService.ts index 08d83a275..f9419c539 100644 --- a/packages/backend/src/core/entities/EmojiEntityService.ts +++ b/packages/backend/src/core/entities/EmojiEntityService.ts @@ -6,8 +6,8 @@ import type { Packed } from '@/misc/schema.js'; import type { } from '@/models/entities/Blocking.js'; import type { User } from '@/models/entities/User.js'; import type { Emoji } from '@/models/entities/Emoji.js'; -import { UserEntityService } from './UserEntityService.js'; import { bindThis } from '@/decorators.js'; +import { UserEntityService } from './UserEntityService.js'; @Injectable() export class EmojiEntityService { @@ -22,6 +22,7 @@ export class EmojiEntityService { @bindThis public async pack( src: Emoji['id'] | Emoji, + opts: { omitUrl?: boolean } = {}, ): Promise> { const emoji = typeof src === 'object' ? src : await this.emojisRepository.findOneByOrFail({ id: src }); @@ -32,15 +33,16 @@ export class EmojiEntityService { category: emoji.category, host: emoji.host, // ?? emoji.originalUrl してるのは後方互換性のため - url: emoji.publicUrl ?? emoji.originalUrl, + url: opts.omitUrl ? undefined : (emoji.publicUrl ?? emoji.originalUrl), }; } @bindThis public packMany( emojis: any[], + opts: { omitUrl?: boolean } = {}, ) { - return Promise.all(emojis.map(x => this.pack(x))); + return Promise.all(emojis.map(x => this.pack(x, opts))); } } diff --git a/packages/backend/src/models/schema/emoji.ts b/packages/backend/src/models/schema/emoji.ts index e97fdd5ef..9a52609b6 100644 --- a/packages/backend/src/models/schema/emoji.ts +++ b/packages/backend/src/models/schema/emoji.ts @@ -31,7 +31,7 @@ export const packedEmojiSchema = { }, url: { type: 'string', - optional: false, nullable: false, + optional: true, nullable: false, }, }, } as const; diff --git a/packages/backend/src/server/api/endpoints/meta.ts b/packages/backend/src/server/api/endpoints/meta.ts index 05da01197..66c9f0620 100644 --- a/packages/backend/src/server/api/endpoints/meta.ts +++ b/packages/backend/src/server/api/endpoints/meta.ts @@ -309,6 +309,7 @@ export const paramDef = { type: 'object', properties: { detail: { type: 'boolean', default: true }, + omitEmojiUrl: { type: 'boolean', default: false }, }, required: [], } as const; @@ -390,7 +391,7 @@ export default class extends Endpoint { backgroundImageUrl: instance.backgroundImageUrl, logoImageUrl: instance.logoImageUrl, maxNoteTextLength: MAX_NOTE_TEXT_LENGTH, // 後方互換性のため - emojis: await this.emojiEntityService.packMany(emojis), + emojis: await this.emojiEntityService.packMany(emojis, { omitUrl: ps.omitEmojiUrl }), defaultLightTheme: instance.defaultLightTheme, defaultDarkTheme: instance.defaultDarkTheme, ads: ads.map(ad => ({ diff --git a/packages/backend/src/server/web/ClientServerService.ts b/packages/backend/src/server/web/ClientServerService.ts index 2b3f0ce0f..af1ff91ac 100644 --- a/packages/backend/src/server/web/ClientServerService.ts +++ b/packages/backend/src/server/web/ClientServerService.ts @@ -26,7 +26,7 @@ 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, GalleryPostsRepository, NotesRepository, PagesRepository, UserProfilesRepository, UsersRepository } from '@/models/index.js'; +import type { ChannelsRepository, ClipsRepository, EmojisRepository, GalleryPostsRepository, NotesRepository, PagesRepository, UserProfilesRepository, UsersRepository } from '@/models/index.js'; import { deepClone } from '@/misc/clone.js'; import { bindThis } from '@/decorators.js'; import manifest from './manifest.json' assert { type: 'json' }; @@ -70,6 +70,9 @@ export class ClientServerService { @Inject(DI.pagesRepository) private pagesRepository: PagesRepository, + @Inject(DI.emojisRepository) + private emojisRepository: EmojisRepository, + private userEntityService: UserEntityService, private noteEntityService: NoteEntityService, private pageEntityService: PageEntityService, @@ -217,6 +220,33 @@ export class ClientServerService { return reply.sendFile('/apple-touch-icon.png', staticAssets); }); + fastify.get<{ Params: { path: string } }>('/emoji/:path(.*)', async (request, reply) => { + const path = request.params.path; + + if (!path.match(/^[a-zA-Z0-9\-_@\.]+?\.webp$/)) { + reply.code(404); + return; + } + + const name = path.split('@')[0].replace('.webp', ''); + const host = path.split('@')[1]?.replace('.webp', ''); + + const emoji = await this.emojisRepository.findOneBy({ + host: host == null ? IsNull() : host, + name: name, + }); + + if (emoji == null) { + reply.code(404); + return; + } + + reply.header('Content-Security-Policy', 'default-src \'none\'; style-src \'unsafe-inline\''); + + // ?? emoji.originalUrl してるのは後方互換性のため + return await reply.redirect(301, emoji.publicUrl ?? emoji.originalUrl); + }); + fastify.get<{ Params: { path: string } }>('/fluent-emoji/:path(.*)', async (request, reply) => { const path = request.params.path; diff --git a/packages/frontend/src/components/MkNote.vue b/packages/frontend/src/components/MkNote.vue index 65e3161c7..e2e542f51 100644 --- a/packages/frontend/src/components/MkNote.vue +++ b/packages/frontend/src/components/MkNote.vue @@ -37,20 +37,20 @@

- +

({{ i18n.ts.private }}) - + RN:
{{ $t('translatedFrom', { x: translation.sourceLang }) }}: - +
diff --git a/packages/frontend/src/components/MkNoteDetailed.vue b/packages/frontend/src/components/MkNoteDetailed.vue index c7b7f49b2..c3c49420c 100644 --- a/packages/frontend/src/components/MkNoteDetailed.vue +++ b/packages/frontend/src/components/MkNoteDetailed.vue @@ -48,20 +48,20 @@

- +

({{ i18n.ts.private }}) - + RN:
{{ $t('translatedFrom', { x: translation.sourceLang }) }}: - +
diff --git a/packages/frontend/src/components/MkNoteSimple.vue b/packages/frontend/src/components/MkNoteSimple.vue index 354de1a61..fc6bf40e9 100644 --- a/packages/frontend/src/components/MkNoteSimple.vue +++ b/packages/frontend/src/components/MkNoteSimple.vue @@ -5,7 +5,7 @@

- +

diff --git a/packages/frontend/src/components/MkNoteSub.vue b/packages/frontend/src/components/MkNoteSub.vue index 0dbaae59e..efaf35f5e 100644 --- a/packages/frontend/src/components/MkNoteSub.vue +++ b/packages/frontend/src/components/MkNoteSub.vue @@ -6,7 +6,7 @@

- +

diff --git a/packages/frontend/src/components/MkNotification.vue b/packages/frontend/src/components/MkNotification.vue index cb2f38455..c8b197a85 100644 --- a/packages/frontend/src/components/MkNotification.vue +++ b/packages/frontend/src/components/MkNotification.vue @@ -34,31 +34,31 @@ - + - + - + - + - + - + - + {{ i18n.ts.youGotNewFollower }}
diff --git a/packages/frontend/src/components/MkPoll.vue b/packages/frontend/src/components/MkPoll.vue index a1b927e42..f2e3a8ee4 100644 --- a/packages/frontend/src/components/MkPoll.vue +++ b/packages/frontend/src/components/MkPoll.vue @@ -5,7 +5,7 @@
- + ({{ $t('_poll.votesCount', { n: choice.votes }) }}) diff --git a/packages/frontend/src/components/MkReactionIcon.vue b/packages/frontend/src/components/MkReactionIcon.vue index 5638c9a81..6e9d2b1a6 100644 --- a/packages/frontend/src/components/MkReactionIcon.vue +++ b/packages/frontend/src/components/MkReactionIcon.vue @@ -1,5 +1,5 @@ diff --git a/packages/frontend/src/components/MkReactionTooltip.vue b/packages/frontend/src/components/MkReactionTooltip.vue index 310d5954f..34ebc4da2 100644 --- a/packages/frontend/src/components/MkReactionTooltip.vue +++ b/packages/frontend/src/components/MkReactionTooltip.vue @@ -1,7 +1,7 @@ diff --git a/packages/frontend/src/components/MkSubNoteContent.vue b/packages/frontend/src/components/MkSubNoteContent.vue index 210923be4..a2d1d8ae4 100644 --- a/packages/frontend/src/components/MkSubNoteContent.vue +++ b/packages/frontend/src/components/MkSubNoteContent.vue @@ -4,7 +4,7 @@ ({{ i18n.ts.private }}) ({{ i18n.ts.deleted }}) - + RN: ...
diff --git a/packages/frontend/src/components/MkUserInfo.vue b/packages/frontend/src/components/MkUserInfo.vue index 036cbea30..6071fef66 100644 --- a/packages/frontend/src/components/MkUserInfo.vue +++ b/packages/frontend/src/components/MkUserInfo.vue @@ -9,7 +9,7 @@ {{ $ts.followsYou }}
- +
{{ i18n.ts.noAccountDescription }}
diff --git a/packages/frontend/src/components/MkUserPreview.vue b/packages/frontend/src/components/MkUserPreview.vue index 4de2e8baa..d367d7b5c 100644 --- a/packages/frontend/src/components/MkUserPreview.vue +++ b/packages/frontend/src/components/MkUserPreview.vue @@ -11,7 +11,7 @@

- +
diff --git a/packages/frontend/src/components/global/MkEmoji.vue b/packages/frontend/src/components/global/MkEmoji.vue index ce1299a39..9a8418758 100644 --- a/packages/frontend/src/components/global/MkEmoji.vue +++ b/packages/frontend/src/components/global/MkEmoji.vue @@ -1,5 +1,5 @@