From 1a408db3b1abb1624448976e8340abccaa31a702 Mon Sep 17 00:00:00 2001 From: tamaina Date: Fri, 30 Dec 2022 13:37:58 +0000 Subject: [PATCH] fix: use || for emoji url fallback instead of ?? --- packages/backend/src/core/CustomEmojiService.ts | 3 ++- packages/backend/src/core/ReactionService.ts | 3 ++- packages/backend/src/core/activitypub/ApRendererService.ts | 3 ++- packages/backend/src/core/entities/EmojiEntityService.ts | 4 ++-- packages/backend/src/server/web/ClientServerService.ts | 3 ++- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/backend/src/core/CustomEmojiService.ts b/packages/backend/src/core/CustomEmojiService.ts index 61cf81119..f0be95261 100644 --- a/packages/backend/src/core/CustomEmojiService.ts +++ b/packages/backend/src/core/CustomEmojiService.ts @@ -111,7 +111,8 @@ export class CustomEmojiService { if (emoji == null) return null; const isLocal = emoji.host == null; - const emojiUrl = emoji.publicUrl || emoji.originalUrl; // || emoji.originalUrl してるのは後方互換性のため + // || emoji.originalUrl してるのは後方互換性のため(publicUrlはstringなので??はだめ) + const emojiUrl = emoji.publicUrl || emoji.originalUrl; const url = emojiUrl; return { diff --git a/packages/backend/src/core/ReactionService.ts b/packages/backend/src/core/ReactionService.ts index 1775d5422..0c1c3d0a3 100644 --- a/packages/backend/src/core/ReactionService.ts +++ b/packages/backend/src/core/ReactionService.ts @@ -161,7 +161,8 @@ export class ReactionService { reaction: decodedReaction.reaction, emoji: emoji != null ? { name: emoji.host ? `${emoji.name}@${emoji.host}` : `${emoji.name}@.`, - url: emoji.publicUrl ?? emoji.originalUrl, // || emoji.originalUrl してるのは後方互換性のため + // || emoji.originalUrl してるのは後方互換性のため(publicUrlはstringなので??はだめ) + url: emoji.publicUrl || emoji.originalUrl, } : null, userId: user.id, }); diff --git a/packages/backend/src/core/activitypub/ApRendererService.ts b/packages/backend/src/core/activitypub/ApRendererService.ts index 1800840ee..29f216aa1 100644 --- a/packages/backend/src/core/activitypub/ApRendererService.ts +++ b/packages/backend/src/core/activitypub/ApRendererService.ts @@ -172,7 +172,8 @@ export class ApRendererService { icon: { type: 'Image', mediaType: emoji.type ?? 'image/png', - url: emoji.publicUrl ?? emoji.originalUrl, // ?? emoji.originalUrl してるのは後方互換性のため + // || emoji.originalUrl してるのは後方互換性のため(publicUrlはstringなので??はだめ) + url: emoji.publicUrl || emoji.originalUrl, }, }; } diff --git a/packages/backend/src/core/entities/EmojiEntityService.ts b/packages/backend/src/core/entities/EmojiEntityService.ts index f9419c539..f1c7ee903 100644 --- a/packages/backend/src/core/entities/EmojiEntityService.ts +++ b/packages/backend/src/core/entities/EmojiEntityService.ts @@ -32,8 +32,8 @@ export class EmojiEntityService { name: emoji.name, category: emoji.category, host: emoji.host, - // ?? emoji.originalUrl してるのは後方互換性のため - url: opts.omitUrl ? undefined : (emoji.publicUrl ?? emoji.originalUrl), + // || emoji.originalUrl してるのは後方互換性のため(publicUrlはstringなので??はだめ) + url: opts.omitUrl ? undefined : (emoji.publicUrl || emoji.originalUrl), }; } diff --git a/packages/backend/src/server/web/ClientServerService.ts b/packages/backend/src/server/web/ClientServerService.ts index 83a30dbe0..02b779d74 100644 --- a/packages/backend/src/server/web/ClientServerService.ts +++ b/packages/backend/src/server/web/ClientServerService.ts @@ -245,7 +245,8 @@ export class ClientServerService { reply.header('Content-Security-Policy', 'default-src \'none\'; style-src \'unsafe-inline\''); const url = new URL("/proxy/emoji.webp", this.config.url); - url.searchParams.set('url', emoji.publicUrl ?? emoji.originalUrl); // ?? emoji.originalUrl してるのは後方互換性のため + // || emoji.originalUrl してるのは後方互換性のため(publicUrlはstringなので??はだめ) + url.searchParams.set('url', emoji.publicUrl || emoji.originalUrl); url.searchParams.set('emoji', '1'); if ('static' in request.query) url.searchParams.set('static', '1');