reverts changes to emoji data loader

This commit is contained in:
ChaosExAnima 2025-11-13 16:35:49 +01:00
parent 2661a53333
commit 547716fcaa
No known key found for this signature in database
GPG Key ID: 8F2B333100FB6117

View File

@ -7,7 +7,7 @@ import {
loadLatestEtag, loadLatestEtag,
putLatestEtag, putLatestEtag,
} from './database'; } from './database';
import { toSupportedLocale } from './locale'; import { toSupportedLocale, toSupportedLocaleOrCustom } from './locale';
import type { CustomEmojiData, LocaleOrCustom } from './types'; import type { CustomEmojiData, LocaleOrCustom } from './types';
import { emojiLogger } from './utils'; import { emojiLogger } from './utils';
@ -15,8 +15,7 @@ const log = emojiLogger('loader');
export async function importEmojiData(localeString: string) { export async function importEmojiData(localeString: string) {
const locale = toSupportedLocale(localeString); const locale = toSupportedLocale(localeString);
const path = await localeToPath(locale); const emojis = await fetchAndCheckEtag<CompactEmoji[]>(locale);
const emojis = await fetchAndCheckEtag<CompactEmoji[]>(locale, path);
if (!emojis) { if (!emojis) {
return; return;
} }
@ -26,10 +25,7 @@ export async function importEmojiData(localeString: string) {
} }
export async function importCustomEmojiData() { export async function importCustomEmojiData() {
const emojis = await fetchAndCheckEtag<CustomEmojiData[]>( const emojis = await fetchAndCheckEtag<CustomEmojiData[]>('custom');
'custom',
'api/v1/custom_emojis',
);
if (!emojis) { if (!emojis) {
return; return;
} }
@ -39,13 +35,19 @@ export async function importCustomEmojiData() {
async function fetchAndCheckEtag<ResultType extends object[]>( async function fetchAndCheckEtag<ResultType extends object[]>(
localeOrCustom: LocaleOrCustom, localeOrCustom: LocaleOrCustom,
path: string,
): Promise<ResultType | null> { ): Promise<ResultType | null> {
const locale = toSupportedLocaleOrCustom(localeOrCustom);
// Use location.origin as this script may be loaded from a CDN domain. // Use location.origin as this script may be loaded from a CDN domain.
const url = new URL(location.origin); 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, { const response = await fetch(url, {
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@ -78,10 +80,11 @@ async function fetchAndCheckEtag<ResultType extends object[]>(
return data; return data;
} }
const modules = import.meta.glob( const modules = import.meta.glob<string>(
'../../../../../node_modules/emojibase-data/**/compact.json', '../../../../../node_modules/emojibase-data/**/compact.json',
{ {
as: 'url', query: '?url',
import: 'default',
}, },
); );