This commit is contained in:
tamaina
2021-02-24 18:40:24 +09:00
parent 0b88e08d81
commit 19481de459
6 changed files with 28 additions and 5 deletions

View File

@@ -1,4 +1,4 @@
import { get } from 'idb-keyval';
import { get } from '@/scripts/idb-proxy';
export async function getAccountFromId(id: string) {
const accounts = await get('accounts') as { token: string; id: string; }[];

View File

@@ -0,0 +1,23 @@
// FirefoxのプライベートモードなどではindexedDBが使用不可能なので、使う
import {
get as iget,
set as iset,
del as idel
} from 'idb-keyval';
const fallbackName = (key: string) => `idbfallback::${key}`;
export async function get(key: string) {
if (window.indexedDB) return iget(key);
return JSON.parse(localStorage.getItem(fallbackName(key)) || 'null');
}
export async function set(key: string, val: any) {
if (window.indexedDB) return iset(key, val);
return localStorage.setItem(fallbackName(key), JSON.stringify(val));
}
export async function del(key: string) {
if (window.indexedDB) return idel(key);
return localStorage.removeItem(fallbackName(key));
}