From ada577bde6296d0f098c3f606a45c47625694587 Mon Sep 17 00:00:00 2001 From: Johann150 Date: Thu, 4 Jan 2024 21:31:04 +0100 Subject: [PATCH] server: fix/document strange requirements for emoji packs The change in the emoji export logic should fix the case where emoji packs exported with Foundkey should be used in any other Misskey fork. I've opted not to change the import logic and instead document the strange behaviour because it would also not be accepted by Misskey. --- docs/emoji.md | 3 +++ .../src/queue/processors/db/export-custom-emojis.ts | 8 +++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/emoji.md b/docs/emoji.md index abfd13632..143563f86 100644 --- a/docs/emoji.md +++ b/docs/emoji.md @@ -74,6 +74,9 @@ The fields of `Meta` are currently not used or checked when importing emoji, exc For each `Emoji`: - `downloaded`: should always be true. If the field is missing or not truthy, the emoji will not be imported. - `fileName`: name of the image file inside the packed file. + The filename has to match the following ECMAScript RegExp: `/^[a-zA-Z0-9_]+?([a-zA-Z0-9\.]+)?$/` + (i.e. composed of latin letters, digits, underscores or dots, not starting with a dot and not ending with an underscore) + If the file does not match this RegExp, the respective emoji will not be imported! - `emoji`: data associated with the emoji as it was stored in the database. Currently most of these fields are not even checked for existence. The following are currently used: - `name`: name of the emoji for the user, e.g. `blobfox` if a user should type in `:blobfox:` to get the emoji. 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 9aa503e43..f526b90dc 100644 --- a/packages/backend/src/queue/processors/db/export-custom-emojis.ts +++ b/packages/backend/src/queue/processors/db/export-custom-emojis.ts @@ -58,12 +58,10 @@ export async function exportCustomEmojis(job: Bull.Job, done: () => void): Promi }); for (const emoji of customEmojis) { - if (!/^[a-zA-Z0-9_]+$/.test(emoji.name)) { - this.logger.error(`invalid emoji name: ${emoji.name}, skipping in emoji export`); - continue; - } 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;