From 197002df8a009ba06a8e1e4942f4f8e70a851b86 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Thu, 4 Jan 2024 23:54:40 +0100 Subject: [PATCH] [backend] Fix emojis with special characters This is an adaptation of https://akkoma.dev/FoundKeyGang/FoundKey/commit/3968a6ca07b43074a000ddc936ae400922f6a269 and https://akkoma.dev/FoundKeyGang/FoundKey/commit/ada577bde6296d0f098c3f606a45c47625694587 Co-authored-by: Johann150 --- packages/backend/src/misc/populate-emojis.ts | 11 ++++------- .../src/queue/processors/db/export-custom-emojis.ts | 4 +++- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/backend/src/misc/populate-emojis.ts b/packages/backend/src/misc/populate-emojis.ts index 870dff5cf..b2488e66f 100644 --- a/packages/backend/src/misc/populate-emojis.ts +++ b/packages/backend/src/misc/populate-emojis.ts @@ -41,13 +41,10 @@ function normalizeHost( } function parseEmojiStr(emojiName: string, noteUserHost: string | null) { - const match = emojiName.match(/^(\w+)(?:@([\w.-]+))?$/); - if (!match) return { name: null, host: null }; - - const name = match[1]; - - // ホスト正規化 - const host = toPunyNullable(normalizeHost(match[2], noteUserHost)); + // emojiName may be of the form `emoji@host`, turn it into a suitable form + const match = emojiName.split("@"); + const name = match[0]; + const host = toPunyNullable(normalizeHost(match[1], noteUserHost)); return { name, host }; } diff --git a/packages/backend/src/queue/processors/db/export-custom-emojis.ts b/packages/backend/src/queue/processors/db/export-custom-emojis.ts index 7a19d0b60..1374d6c4e 100644 --- a/packages/backend/src/queue/processors/db/export-custom-emojis.ts +++ b/packages/backend/src/queue/processors/db/export-custom-emojis.ts @@ -68,7 +68,9 @@ export async function exportCustomEmojis( for (const emoji of customEmojis) { const ext = mime.extension(emoji.type); - const fileName = emoji.name + (ext ? `.${ext}` : ""); + // there are some restrictions on file names, so to be safe the files are + // named after their database id instead of the actual emoji name + const fileName = emoji.id + (ext ? '.' + ext : ''); const emojiPath = `${path}/${fileName}`; fs.writeFileSync(emojiPath, "", "binary"); let downloaded = false;