enhance: embedページではstoreの保存先を完全に分離するように
This commit is contained in:
@@ -2,8 +2,9 @@
|
||||
* SPDX-FileCopyrightText: syuilo and misskey-project
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import { isEmbedPage, initEmbedPageLocalStorage } from "@/scripts/embed-page.js";
|
||||
|
||||
type Keys =
|
||||
export type Keys =
|
||||
'v' |
|
||||
'lastVersion' |
|
||||
'instance' |
|
||||
@@ -38,12 +39,33 @@ type Keys =
|
||||
`aiscript:${string}` |
|
||||
'lastEmojisFetchedAt' | // DEPRECATED, stored in indexeddb (13.9.0~)
|
||||
'emojis' | // DEPRECATED, stored in indexeddb (13.9.0~);
|
||||
`channelLastReadedAt:${string}`
|
||||
`channelLastReadedAt:${string}` |
|
||||
`idbfallback::${string}`
|
||||
|
||||
// セッション毎に廃棄されるLocalStorage代替(embedなどで使用)
|
||||
const safeSessionStorage = new Map<Keys, string>();
|
||||
|
||||
export const miLocalStorage = {
|
||||
getItem: (key: Keys): string | null => window.localStorage.getItem(key),
|
||||
setItem: (key: Keys, value: string): void => window.localStorage.setItem(key, value),
|
||||
removeItem: (key: Keys): void => window.localStorage.removeItem(key),
|
||||
getItem: (key: Keys): string | null => {
|
||||
if (isEmbedPage()) {
|
||||
return safeSessionStorage.get(key) ?? null;
|
||||
}
|
||||
return window.localStorage.getItem(key);
|
||||
},
|
||||
setItem: (key: Keys, value: string): void => {
|
||||
if (isEmbedPage()) {
|
||||
safeSessionStorage.set(key, value);
|
||||
} else {
|
||||
window.localStorage.setItem(key, value);
|
||||
}
|
||||
},
|
||||
removeItem: (key: Keys): void => {
|
||||
if (isEmbedPage()) {
|
||||
safeSessionStorage.delete(key);
|
||||
} else {
|
||||
window.localStorage.removeItem(key);
|
||||
}
|
||||
},
|
||||
getItemAsJson: (key: Keys): any | undefined => {
|
||||
const item = miLocalStorage.getItem(key);
|
||||
if (item === null) {
|
||||
@@ -51,5 +73,12 @@ export const miLocalStorage = {
|
||||
}
|
||||
return JSON.parse(item);
|
||||
},
|
||||
setItemAsJson: (key: Keys, value: any): void => window.localStorage.setItem(key, JSON.stringify(value)),
|
||||
setItemAsJson: (key: Keys, value: any): void => {
|
||||
miLocalStorage.setItem(key, JSON.stringify(value));
|
||||
},
|
||||
};
|
||||
|
||||
if (isEmbedPage()) {
|
||||
initEmbedPageLocalStorage();
|
||||
if (_DEV_) console.warn('Using safeSessionStorage as localStorage alternative');
|
||||
}
|
||||
|
Reference in New Issue
Block a user