From 7681682445bf09802917f131aa227b0c820dfe56 Mon Sep 17 00:00:00 2001 From: molvqingtai Date: Wed, 6 Nov 2024 18:17:33 +0800 Subject: [PATCH] chore: storage delete JSONR --- src/domain/Room.ts | 1 - src/domain/impls/Storage.ts | 33 +++++++++++---------------------- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/src/domain/Room.ts b/src/domain/Room.ts index 3f3c64c..421882b 100644 --- a/src/domain/Room.ts +++ b/src/domain/Room.ts @@ -281,7 +281,6 @@ const RoomDomain = Remesh.domain({ name: 'Room.SendSyncHistoryMessageCommand', impl: ({ get }, { peerId, lastMessageTime }: { peerId: string; lastMessageTime: number }) => { const self = get(SelfUserQuery()) - console.log('SendSyncHistoryMessageCommand', peerId, peerRoom.peerId) const historyMessages = get(messageListDomain.query.ListQuery()).filter( (message) => diff --git a/src/domain/impls/Storage.ts b/src/domain/impls/Storage.ts index 1eccd25..feb14ca 100644 --- a/src/domain/impls/Storage.ts +++ b/src/domain/impls/Storage.ts @@ -7,7 +7,11 @@ import { webExtensionDriver } from '@/utils/webExtensionDriver' import { Storage } from '@/domain/externs/Storage' import { EVENT } from '@/constants/event' -import { JSONR } from '@/utils' + +/** + * Waiting to be resolved + * @see https://github.com/unjs/unstorage/issues/277 + * */ export const localStorage = createStorage({ driver: localStorageDriver({ base: `${STORAGE_NAME}:` }) @@ -23,8 +27,8 @@ export const browserSyncStorage = createStorage({ export const LocalStorageImpl = LocalStorageExtern.impl({ name: STORAGE_NAME, - get: async (key) => JSONR.parse(await localStorage.getItem(key)), - set: (key, value) => localStorage.setItem(key, JSONR.stringify(value)), + get: localStorage.getItem, + set: localStorage.setItem, remove: localStorage.removeItem, clear: localStorage.clear, watch: async (callback) => { @@ -46,14 +50,8 @@ export const LocalStorageImpl = LocalStorageExtern.impl({ export const IndexDBStorageImpl = IndexDBStorageExtern.impl({ name: STORAGE_NAME, - get: async (key) => JSONR.parse(await indexDBStorage.getItem(key)), - set: (key, value) => { - /** - * Waiting to be resolved - * @see https://github.com/unjs/unstorage/issues/277 - * */ - return indexDBStorage.setItem(key, JSONR.stringify(value)) - }, + get: indexDBStorage.getItem, + set: indexDBStorage.setItem, remove: indexDBStorage.removeItem, clear: indexDBStorage.clear, watch: indexDBStorage.watch as Storage['watch'], @@ -62,17 +60,8 @@ export const IndexDBStorageImpl = IndexDBStorageExtern.impl({ export const BrowserSyncStorageImpl = BrowserSyncStorageExtern.impl({ name: STORAGE_NAME, - get: async (key) => { - const value: any = await browserSyncStorage.getItem(key) - - // Compatibility with old version data - try { - return JSONR.parse(value) - } catch { - return value - } - }, - set: (key, value) => browserSyncStorage.setItem(key, JSONR.stringify(value)), + get: browserSyncStorage.getItem, + set: browserSyncStorage.setItem, remove: browserSyncStorage.removeItem, clear: browserSyncStorage.clear, watch: browserSyncStorage.watch as Storage['watch'],