fix(ci): 质量检查 - 同步格式、前端断言与存储降级

This commit is contained in:
cn-derekdu
2026-09-19 06:49:19 +00:00
committed by ddCat
parent 8b68c6ef12
commit 5f73916e17
12 changed files with 57 additions and 46 deletions

View File

@@ -8,19 +8,26 @@ localforage.config({
storeName: "app_state",
});
// localforage 需要 localStorage / indexedDB 等浏览器存储驱动;测试进程等环境可能只有 window 而无存储 API,
// 此时直接跳过读写,避免 localforage 内部回退并输出 "No available storage method found"。
function browserStorageAvailable(): boolean {
if (typeof window === "undefined") return false;
return typeof window.localStorage !== "undefined" || typeof window.indexedDB !== "undefined";
}
export function localForageStorageForScope(scope?: string): StateStorage {
const keyFor = (name: string) => scopedStorageKey(name, scope);
return {
getItem: async (name) => {
if (typeof window === "undefined") return null;
if (!browserStorageAvailable()) return null;
return (await localforage.getItem<string>(keyFor(name))) || null;
},
setItem: async (name, value) => {
if (typeof window === "undefined") return;
if (!browserStorageAvailable()) return;
await localforage.setItem(keyFor(name), value);
},
removeItem: async (name) => {
if (typeof window === "undefined") return;
if (!browserStorageAvailable()) return;
await localforage.removeItem(keyFor(name));
},
};