diff --git a/app/javascript/mastodon/features/emoji/loader.ts b/app/javascript/mastodon/features/emoji/loader.ts index 654e9e25203..330c5e6a2ac 100644 --- a/app/javascript/mastodon/features/emoji/loader.ts +++ b/app/javascript/mastodon/features/emoji/loader.ts @@ -7,7 +7,7 @@ import { loadLatestEtag, putLatestEtag, } from './database'; -import { toSupportedLocale } from './locale'; +import { toSupportedLocale, toSupportedLocaleOrCustom } from './locale'; import type { CustomEmojiData, LocaleOrCustom } from './types'; import { emojiLogger } from './utils'; @@ -15,8 +15,7 @@ const log = emojiLogger('loader'); export async function importEmojiData(localeString: string) { const locale = toSupportedLocale(localeString); - const path = await localeToPath(locale); - const emojis = await fetchAndCheckEtag(locale, path); + const emojis = await fetchAndCheckEtag(locale); if (!emojis) { return; } @@ -26,10 +25,7 @@ export async function importEmojiData(localeString: string) { } export async function importCustomEmojiData() { - const emojis = await fetchAndCheckEtag( - 'custom', - 'api/v1/custom_emojis', - ); + const emojis = await fetchAndCheckEtag('custom'); if (!emojis) { return; } @@ -39,13 +35,19 @@ export async function importCustomEmojiData() { async function fetchAndCheckEtag( localeOrCustom: LocaleOrCustom, - path: string, ): Promise { + const locale = toSupportedLocaleOrCustom(localeOrCustom); + // Use location.origin as this script may be loaded from a CDN domain. const url = new URL(location.origin); - url.pathname = path; + if (locale === 'custom') { + url.pathname = '/api/v1/custom_emojis'; + } else { + const modulePath = await localeToPath(locale); + url.pathname = modulePath; + } - const oldEtag = await loadLatestEtag(localeOrCustom); + const oldEtag = await loadLatestEtag(locale); const response = await fetch(url, { headers: { 'Content-Type': 'application/json', @@ -78,10 +80,11 @@ async function fetchAndCheckEtag( return data; } -const modules = import.meta.glob( +const modules = import.meta.glob( '../../../../../node_modules/emojibase-data/**/compact.json', { - as: 'url', + query: '?url', + import: 'default', }, );