Merge branch 'ChatGPTNextWeb:main' into main

This commit is contained in:
Aloxaf 2024-05-13 16:32:56 +08:00 committed by GitHub
commit cf4082aa81
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 5 deletions

View File

@ -97,11 +97,18 @@ export const useSyncStore = createPersistStore(
const client = this.getClient(); const client = this.getClient();
try { try {
const remoteState = JSON.parse( const remoteState = await client.get(config.username);
await client.get(config.username), if (!remoteState || remoteState === "") {
) as AppState; await client.set(config.username, JSON.stringify(localState));
mergeAppState(localState, remoteState); console.log("[Sync] Remote state is empty, using local state instead.");
setLocalAppState(localState); return
} else {
const parsedRemoteState = JSON.parse(
await client.get(config.username),
) as AppState;
mergeAppState(localState, parsedRemoteState);
setLocalAppState(localState);
}
} catch (e) { } catch (e) {
console.log("[Sync] failed to get remote state", e); console.log("[Sync] failed to get remote state", e);
throw e; throw e;