[backend] Fix emojis with special characters

This is an adaptation of 3968a6ca07 and ada577bde6

Co-authored-by: Johann150 <johann.galle@protonmail.com>
This commit is contained in:
Laura Hausmann 2024-01-04 23:54:40 +01:00
parent 299a20fb71
commit 197002df8a
Signed by: zotan
GPG key ID: D044E84C5BE01605
2 changed files with 7 additions and 8 deletions

View file

@ -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 };
}

View file

@ -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;