From f1e7db6a88611a62a6ef6446c768ab16bd943173 Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Tue, 19 Sep 2023 03:33:17 +0800 Subject: [PATCH] feat: auto fill upstash backup name --- app/store/sync.ts | 52 +++++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/app/store/sync.ts b/app/store/sync.ts index ff9f650c083..c194162fcb0 100644 --- a/app/store/sync.ts +++ b/app/store/sync.ts @@ -22,27 +22,29 @@ export interface WebDavConfig { export type SyncStore = GetStoreState; -export const useSyncStore = createPersistStore( - { - provider: ProviderType.WebDAV, - useProxy: true, - proxyUrl: corsPath(ApiPath.Cors), - - webdav: { - endpoint: "", - username: "", - password: "", - }, - - upstash: { - endpoint: "", - username: STORAGE_KEY, - apiKey: "", - }, +const DEFAULT_SYNC_STATE = { + provider: ProviderType.WebDAV, + useProxy: true, + proxyUrl: corsPath(ApiPath.Cors), + + webdav: { + endpoint: "", + username: "", + password: "", + }, - lastSyncTime: 0, - lastProvider: "", + upstash: { + endpoint: "", + username: STORAGE_KEY, + apiKey: "", }, + + lastSyncTime: 0, + lastProvider: "", +}; + +export const useSyncStore = createPersistStore( + DEFAULT_SYNC_STATE, (set, get) => ({ coundSync() { const config = get()[get().provider]; @@ -108,6 +110,16 @@ export const useSyncStore = createPersistStore( }), { name: StoreKey.Sync, - version: 1, + version: 1.1, + + migrate(persistedState, version) { + const newState = persistedState as typeof DEFAULT_SYNC_STATE; + + if (version < 1.1) { + newState.upstash.username = STORAGE_KEY; + } + + return newState as any; + }, }, );