diff --git a/app/components/settings.tsx b/app/components/settings.tsx
index 6ae8859..82a12f9 100644
--- a/app/components/settings.tsx
+++ b/app/components/settings.tsx
@@ -396,6 +396,21 @@ function SyncConfigModal(props: { onClose?: () => void }) {
}}
>
+
+ {
+ syncStore.update(
+ (config) =>
+ (config.enableOverwriteRemote = e.currentTarget.checked),
+ );
+ }}
+ >
+
0;
-
- if (!remoteFilteredTopic) {
- localState[StoreKey.Chat].sessions[
- localState[StoreKey.Chat].currentSessionIndex
- ].mask = {
- ...currentSession.mask,
- name: remoteCurrentSession.mask.name,
- };
+ // 除了基本的双向同步以外,还需要实现以下的同步方式
+ // 1. 覆盖远程所有数据
+ // 2. 覆盖本地所有数据
+ // 3. 仅同步用户数据(聊天、自定义面具以及提示)
+
+ // 1. 覆盖远程所有数据(这时不需要从远程下载)
+ if (get().enableOverwriteRemote) {
+ } else {
+ const tmpRemoteState = JSON.parse(
+ await client.get(config.username),
+ ) as AppState;
+ // 3. 仅同步用户数据(替换remoteState中的access-control、app-config为localState中的值)
+ const remoteState = { ...tmpRemoteState };
+ if (get().onlysyncuserdata) {
+ // 如果onlysyncuserdata为true,不同步access-control、app-config。需要生成一个新的用于合并的变量,因为remoteState是只读的
+ remoteState[StoreKey.Access] = localState[StoreKey.Access];
+ remoteState[StoreKey.Config] = localState[StoreKey.Config];
+ }
+ // 2. 覆盖本地所有数据(这时不需要上传到远程,覆盖完直接返回)
+ if (get().enableOverwriteLocal) {
+ setLocalAppState(tmpRemoteState);
+ this.markSyncTime();
+ set({ syncing: false });
+ return true; // Add the return statement here
}
+ mergeAppState(localState, remoteState);
+ const sessions = localState[StoreKey.Chat].sessions;
+ const currentSession =
+ sessions[localState[StoreKey.Chat].currentSessionIndex];
+ const filteredTopic =
+ currentSession.topic === "New Conversation" &&
+ currentSession.messages.length === 0;
+
+ if (filteredTopic) {
+ const remoteSessions = remoteState[StoreKey.Chat].sessions;
+ const remoteCurrentSession =
+ remoteSessions[remoteState[StoreKey.Chat].currentSessionIndex];
+ const remoteFilteredTopic =
+ remoteCurrentSession.topic === "New Conversation" &&
+ remoteCurrentSession.messages.length > 0;
+
+ if (!remoteFilteredTopic) {
+ localState[StoreKey.Chat].sessions[
+ localState[StoreKey.Chat].currentSessionIndex
+ ].mask = {
+ ...currentSession.mask,
+ name: remoteCurrentSession.mask.name,
+ };
+ }
+ }
+ setLocalAppState(localState);
}
-
- setLocalAppState(localState);
} catch (e) {
console.log("[Sync] failed to get remote state", e);
-
}
await client.set(config.username, JSON.stringify(localState));
this.markSyncTime();
set({ syncing: false });
-
return true; // Add the return statement here
},