mirror of
https://github.com/mastodon/mastodon.git
synced 2025-11-27 18:10:58 +00:00
reverts changes to emoji data loader
This commit is contained in:
parent
2661a53333
commit
547716fcaa
|
|
@ -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<CompactEmoji[]>(locale, path);
|
||||
const emojis = await fetchAndCheckEtag<CompactEmoji[]>(locale);
|
||||
if (!emojis) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -26,10 +25,7 @@ export async function importEmojiData(localeString: string) {
|
|||
}
|
||||
|
||||
export async function importCustomEmojiData() {
|
||||
const emojis = await fetchAndCheckEtag<CustomEmojiData[]>(
|
||||
'custom',
|
||||
'api/v1/custom_emojis',
|
||||
);
|
||||
const emojis = await fetchAndCheckEtag<CustomEmojiData[]>('custom');
|
||||
if (!emojis) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -39,13 +35,19 @@ export async function importCustomEmojiData() {
|
|||
|
||||
async function fetchAndCheckEtag<ResultType extends object[]>(
|
||||
localeOrCustom: LocaleOrCustom,
|
||||
path: string,
|
||||
): Promise<ResultType | null> {
|
||||
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<ResultType extends object[]>(
|
|||
return data;
|
||||
}
|
||||
|
||||
const modules = import.meta.glob(
|
||||
const modules = import.meta.glob<string>(
|
||||
'../../../../../node_modules/emojibase-data/**/compact.json',
|
||||
{
|
||||
as: 'url',
|
||||
query: '?url',
|
||||
import: 'default',
|
||||
},
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user