From 4165db331e3aa1e893f5127f0944bb1ed1d50866 Mon Sep 17 00:00:00 2001 From: CyberRex Date: Sat, 9 Sep 2023 01:20:45 +0900 Subject: [PATCH] =?UTF-8?q?=E4=BD=95=E3=82=89=E3=81=8B=E3=81=AE=E7=90=86?= =?UTF-8?q?=E7=94=B1=E3=81=AB=E3=82=88=E3=82=8A=E3=82=AF=E3=83=A9=E3=82=A4?= =?UTF-8?q?=E3=82=A2=E3=83=B3=E3=83=88=E3=81=AE=E7=B5=B5=E6=96=87=E5=AD=97?= =?UTF-8?q?=E3=82=AD=E3=83=A3=E3=83=83=E3=82=B7=E3=83=A5=E3=81=8C=E5=89=8A?= =?UTF-8?q?=E9=99=A4=E3=81=95=E3=82=8C=E3=81=9F=E5=A0=B4=E5=90=88=E3=81=9F?= =?UTF-8?q?=E3=81=A0=E3=81=A1=E3=81=AB=E5=86=8D=E5=8F=96=E5=BE=97=E3=81=99?= =?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3=20(Missk?= =?UTF-8?q?eyIO#163)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/frontend/src/custom-emojis.ts | 5 +++-- packages/frontend/src/scripts/idb-proxy.ts | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/frontend/src/custom-emojis.ts b/packages/frontend/src/custom-emojis.ts index 771f21c5b4..d08b8814e8 100644 --- a/packages/frontend/src/custom-emojis.ts +++ b/packages/frontend/src/custom-emojis.ts @@ -7,7 +7,7 @@ import { shallowRef, computed, markRaw, watch } from 'vue'; import * as Misskey from 'misskey-js'; import { api, apiGet } from './os'; import { useStream } from '@/stream'; -import { get, set } from '@/scripts/idb-proxy'; +import { get, set, exist } from '@/scripts/idb-proxy'; const storageCache = await get('emojis'); export const customEmojis = shallowRef(Array.isArray(storageCache) ? storageCache : []); @@ -54,8 +54,9 @@ export async function fetchCustomEmojis(force = false) { if (force) { res = await api('emojis', {}); } else { + const emojiCacheExist = await exist('emojis'); const lastFetchedAt = await get('lastEmojisFetchedAt'); - if (lastFetchedAt && (now - lastFetchedAt) < 1000 * 60 * 60) return; + if (lastFetchedAt && (now - lastFetchedAt) < 1000 * 60 * 60 && emojiCacheExist) return; res = await apiGet('emojis', {}); } diff --git a/packages/frontend/src/scripts/idb-proxy.ts b/packages/frontend/src/scripts/idb-proxy.ts index a20cfcb1d0..b1410e4d68 100644 --- a/packages/frontend/src/scripts/idb-proxy.ts +++ b/packages/frontend/src/scripts/idb-proxy.ts @@ -9,6 +9,7 @@ import { get as iget, set as iset, del as idel, + keys as ikeys, } from 'idb-keyval'; const fallbackName = (key: string) => `idbfallback::${key}`; @@ -40,3 +41,11 @@ export async function del(key: string) { if (idbAvailable) return idel(key); return window.localStorage.removeItem(fallbackName(key)); } + +export async function exist(key: string) { + if (idbAvailable) { + const keys = await ikeys(); + return keys.includes(key); + } + return window.localStorage.getItem(fallbackName(key)) !== null; +}