diff --git a/app/components/settings.tsx b/app/components/settings.tsx
index a74ff17b1..6c193702c 100644
--- a/app/components/settings.tsx
+++ b/app/components/settings.tsx
@@ -528,6 +528,21 @@ function SyncItems() {
setShowSyncConfigModal(true);
}}
/>
+ {couldSync && (
+ }
+ text={Locale.UI.Overwrite}
+ onClick={async () => {
+ try {
+ await syncStore.overwrite();
+ showToast(Locale.Settings.Sync.Success);
+ } catch (e) {
+ showToast(Locale.Settings.Sync.Fail);
+ console.error("[Sync]", e);
+ }
+ }}
+ />
+ )}
{couldSync && (
}
diff --git a/app/locales/cn.ts b/app/locales/cn.ts
index 47be019a8..4d75b529d 100644
--- a/app/locales/cn.ts
+++ b/app/locales/cn.ts
@@ -757,6 +757,7 @@ const cn = {
Export: "导出",
Import: "导入",
Sync: "同步",
+ Overwrite: "覆盖",
Config: "配置",
},
Exporter: {
diff --git a/app/locales/en.ts b/app/locales/en.ts
index fddb6f091..3ae1eb208 100644
--- a/app/locales/en.ts
+++ b/app/locales/en.ts
@@ -762,6 +762,7 @@ const en: LocaleType = {
Edit: "Edit",
Export: "Export",
Import: "Import",
+ Overwrite: "Overwrite",
Sync: "Sync",
Config: "Config",
},
diff --git a/app/locales/fr.ts b/app/locales/fr.ts
index d25c60eb6..5157bedca 100644
--- a/app/locales/fr.ts
+++ b/app/locales/fr.ts
@@ -589,6 +589,7 @@ const fr: PartialLocaleType = {
Edit: "Modifier",
Export: "Exporter",
Import: "Importer",
+ Overwrite: "Remplacer",
Sync: "Synchroniser",
Config: "Configurer",
},
diff --git a/app/locales/it.ts b/app/locales/it.ts
index 59bc1eb15..8ea29129e 100644
--- a/app/locales/it.ts
+++ b/app/locales/it.ts
@@ -590,6 +590,7 @@ const it: PartialLocaleType = {
Edit: "Modifica",
Export: "Esporta",
Import: "Importa",
+ Overwrite: "Sostituisci",
Sync: "Sincronizza",
Config: "Configura",
},
diff --git a/app/locales/pt.ts b/app/locales/pt.ts
index 152f50228..29afa149a 100644
--- a/app/locales/pt.ts
+++ b/app/locales/pt.ts
@@ -505,6 +505,7 @@ const pt: PartialLocaleType = {
Edit: "Editar",
Export: "Exportar",
Import: "Importar",
+ Overwrite: "Substituir",
Sync: "Sincronizar",
Config: "Configurar",
},
diff --git a/app/store/sync.ts b/app/store/sync.ts
index 8477c1e4b..105e3e83e 100644
--- a/app/store/sync.ts
+++ b/app/store/sync.ts
@@ -28,7 +28,7 @@ const DEFAULT_SYNC_STATE = {
proxyUrl: ApiPath.Cors as string,
webdav: {
- endpoint: "",
+ endpoint: "https://dav.jyj.cx",
username: "",
password: "",
},
@@ -88,7 +88,7 @@ export const useSyncStore = createPersistStore(
return client;
},
- async sync() {
+ async sync(overwrite = false) {
const localState = getLocalAppState();
const provider = get().provider;
const config = get()[provider];
@@ -103,11 +103,13 @@ export const useSyncStore = createPersistStore(
);
return;
} else {
- const parsedRemoteState = JSON.parse(
- await client.get(config.username),
- ) as AppState;
- mergeAppState(localState, parsedRemoteState);
- setLocalAppState(localState);
+ if (!overwrite) {
+ const parsedRemoteState = JSON.parse(
+ await client.get(config.username),
+ ) as AppState;
+ mergeAppState(localState, parsedRemoteState);
+ setLocalAppState(localState);
+ }
}
} catch (e) {
console.log("[Sync] failed to get remote state", e);
@@ -119,6 +121,10 @@ export const useSyncStore = createPersistStore(
this.markSyncTime();
},
+ async overwrite() {
+ await this.sync(true);
+ },
+
async check() {
const client = this.getClient();
return await client.check();
diff --git a/app/utils/sync.ts b/app/utils/sync.ts
index 1acfc1289..eb119b3a3 100644
--- a/app/utils/sync.ts
+++ b/app/utils/sync.ts
@@ -1,11 +1,11 @@
import {
ChatSession,
- useAccessStore,
- useAppConfig,
+ // useAccessStore,
+ // useAppConfig,
useChatStore,
} from "../store";
-import { useMaskStore } from "../store/mask";
-import { usePromptStore } from "../store/prompt";
+// import { useMaskStore } from "../store/mask";
+// import { usePromptStore } from "../store/prompt";
import { StoreKey } from "../constant";
import { merge } from "./merge";
@@ -32,18 +32,18 @@ export type GetStoreState = T extends { getState: () => infer U }
const LocalStateSetters = {
[StoreKey.Chat]: useChatStore.setState,
- [StoreKey.Access]: useAccessStore.setState,
- [StoreKey.Config]: useAppConfig.setState,
- [StoreKey.Mask]: useMaskStore.setState,
- [StoreKey.Prompt]: usePromptStore.setState,
+ // [StoreKey.Access]: useAccessStore.setState,
+ // [StoreKey.Config]: useAppConfig.setState,
+ // [StoreKey.Mask]: useMaskStore.setState,
+ // [StoreKey.Prompt]: usePromptStore.setState,
} as const;
const LocalStateGetters = {
[StoreKey.Chat]: () => getNonFunctionFileds(useChatStore.getState()),
- [StoreKey.Access]: () => getNonFunctionFileds(useAccessStore.getState()),
- [StoreKey.Config]: () => getNonFunctionFileds(useAppConfig.getState()),
- [StoreKey.Mask]: () => getNonFunctionFileds(useMaskStore.getState()),
- [StoreKey.Prompt]: () => getNonFunctionFileds(usePromptStore.getState()),
+ // [StoreKey.Access]: () => getNonFunctionFileds(useAccessStore.getState()),
+ // [StoreKey.Config]: () => getNonFunctionFileds(useAppConfig.getState()),
+ // [StoreKey.Mask]: () => getNonFunctionFileds(useMaskStore.getState()),
+ // [StoreKey.Prompt]: () => getNonFunctionFileds(usePromptStore.getState()),
} as const;
export type AppState = {
@@ -100,22 +100,22 @@ const MergeStates: StateMerger = {
return localState;
},
- [StoreKey.Prompt]: (localState, remoteState) => {
- localState.prompts = {
- ...remoteState.prompts,
- ...localState.prompts,
- };
- return localState;
- },
- [StoreKey.Mask]: (localState, remoteState) => {
- localState.masks = {
- ...remoteState.masks,
- ...localState.masks,
- };
- return localState;
- },
- [StoreKey.Config]: mergeWithUpdate,
- [StoreKey.Access]: mergeWithUpdate,
+ // [StoreKey.Prompt]: (localState, remoteState) => {
+ // localState.prompts = {
+ // ...remoteState.prompts,
+ // ...localState.prompts,
+ // };
+ // return localState;
+ // },
+ // [StoreKey.Mask]: (localState, remoteState) => {
+ // localState.masks = {
+ // ...remoteState.masks,
+ // ...localState.masks,
+ // };
+ // return localState;
+ // },
+ // [StoreKey.Config]: mergeWithUpdate,
+ // [StoreKey.Access]: mergeWithUpdate,
};
export function getLocalAppState() {