From 83ee9f7e4bbb3d6a70a612c5ab0291c099c23307 Mon Sep 17 00:00:00 2001 From: m5r Date: Thu, 16 Feb 2023 09:23:45 +0100 Subject: [PATCH] also use emojiType as cache key for dynamic asset cache --- src/emoji.ts | 7 ++----- src/og.ts | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/emoji.ts b/src/emoji.ts index b4994e4..3ad843c 100644 --- a/src/emoji.ts +++ b/src/emoji.ts @@ -37,12 +37,9 @@ const apis = { "https://cdn.jsdelivr.net/gh/shuding/fluentui-emoji-unicode/assets/" + code.toLowerCase() + "_flat.svg", }; export type EmojiType = keyof typeof apis; -export function loadEmoji(code: string, type?: EmojiType) { +export function loadEmoji(code: string, type: EmojiType) { // https://github.com/svgmoji/svgmoji - if (!type || !apis[type]) { - type = "twemoji"; - } - const api = apis[type]; + const api = apis[type] ?? apis.twemoji; if (typeof api === "function") { return fetch(api(code)); } diff --git a/src/og.ts b/src/og.ts index fcf58fb..c825ccf 100644 --- a/src/og.ts +++ b/src/og.ts @@ -78,7 +78,7 @@ const loadDynamicAsset = (emojiType: EmojiType = "twemoji") => { } }; return async (...args: Parameters) => { - const cacheKey = JSON.stringify(args); + const cacheKey = JSON.stringify({ ...args, emojiType }); const cachedFont = assetCache.get(cacheKey); if (cachedFont) { return cachedFont;