This commit is contained in:
Wang Guan
2024-11-06 21:01:36 +11:00
committed by GitHub
6 changed files with 90 additions and 6 deletions

View File

@@ -27,18 +27,22 @@ const DEFAULT_SYNC_STATE = {
useProxy: true,
proxyUrl: ApiPath.Cors as string,
webdav: {
[ProviderType.WebDAV]: {
endpoint: "",
username: "",
password: "",
},
upstash: {
[ProviderType.UpStash]: {
endpoint: "",
username: STORAGE_KEY,
apiKey: "",
},
autoSync: {
onStart: false,
},
lastSyncTime: 0,
lastProvider: "",
};
@@ -46,9 +50,14 @@ const DEFAULT_SYNC_STATE = {
export const useSyncStore = createPersistStore(
DEFAULT_SYNC_STATE,
(set, get) => ({
cloudSync() {
cloudSync(): boolean {
const config = get()[get().provider];
return Object.values(config).every((c) => c.toString().length > 0);
if (!config) {
return false;
}
return Object.values(config).every(
(c) => c != null && c.toString().length > 0,
);
},
markSyncTime() {
@@ -126,7 +135,7 @@ export const useSyncStore = createPersistStore(
}),
{
name: StoreKey.Sync,
version: 1.2,
version: 1.3,
migrate(persistedState, version) {
const newState = persistedState as typeof DEFAULT_SYNC_STATE;
@@ -144,6 +153,10 @@ export const useSyncStore = createPersistStore(
}
}
if (version < 1.3) {
newState.autoSync = { ...DEFAULT_SYNC_STATE.autoSync };
}
return newState as any;
},
},