何らかの理由によりクライアントの絵文字キャッシュが削除された場合ただちに再取得するように修正 (MisskeyIO#163)

This commit is contained in:
CyberRex 2023-09-09 01:20:45 +09:00 committed by GitHub
parent 545ab80363
commit 4165db331e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View file

@ -7,7 +7,7 @@ import { shallowRef, computed, markRaw, watch } from 'vue';
import * as Misskey from 'misskey-js'; import * as Misskey from 'misskey-js';
import { api, apiGet } from './os'; import { api, apiGet } from './os';
import { useStream } from '@/stream'; import { useStream } from '@/stream';
import { get, set } from '@/scripts/idb-proxy'; import { get, set, exist } from '@/scripts/idb-proxy';
const storageCache = await get('emojis'); const storageCache = await get('emojis');
export const customEmojis = shallowRef<Misskey.entities.CustomEmoji[]>(Array.isArray(storageCache) ? storageCache : []); export const customEmojis = shallowRef<Misskey.entities.CustomEmoji[]>(Array.isArray(storageCache) ? storageCache : []);
@ -54,8 +54,9 @@ export async function fetchCustomEmojis(force = false) {
if (force) { if (force) {
res = await api('emojis', {}); res = await api('emojis', {});
} else { } else {
const emojiCacheExist = await exist('emojis');
const lastFetchedAt = await get('lastEmojisFetchedAt'); 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', {}); res = await apiGet('emojis', {});
} }

View file

@ -9,6 +9,7 @@ import {
get as iget, get as iget,
set as iset, set as iset,
del as idel, del as idel,
keys as ikeys,
} from 'idb-keyval'; } from 'idb-keyval';
const fallbackName = (key: string) => `idbfallback::${key}`; const fallbackName = (key: string) => `idbfallback::${key}`;
@ -40,3 +41,11 @@ export async function del(key: string) {
if (idbAvailable) return idel(key); if (idbAvailable) return idel(key);
return window.localStorage.removeItem(fallbackName(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;
}