mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-05-20 20:50:17 +09:00
更新同步模块
This commit is contained in:
parent
d08af47342
commit
1cccaa2e80
@ -528,6 +528,21 @@ function SyncItems() {
|
|||||||
setShowSyncConfigModal(true);
|
setShowSyncConfigModal(true);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
{couldSync && (
|
||||||
|
<IconButton
|
||||||
|
icon={<UploadIcon />}
|
||||||
|
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 && (
|
{couldSync && (
|
||||||
<IconButton
|
<IconButton
|
||||||
icon={<ResetIcon />}
|
icon={<ResetIcon />}
|
||||||
|
@ -757,6 +757,7 @@ const cn = {
|
|||||||
Export: "导出",
|
Export: "导出",
|
||||||
Import: "导入",
|
Import: "导入",
|
||||||
Sync: "同步",
|
Sync: "同步",
|
||||||
|
Overwrite: "覆盖",
|
||||||
Config: "配置",
|
Config: "配置",
|
||||||
},
|
},
|
||||||
Exporter: {
|
Exporter: {
|
||||||
|
@ -762,6 +762,7 @@ const en: LocaleType = {
|
|||||||
Edit: "Edit",
|
Edit: "Edit",
|
||||||
Export: "Export",
|
Export: "Export",
|
||||||
Import: "Import",
|
Import: "Import",
|
||||||
|
Overwrite: "Overwrite",
|
||||||
Sync: "Sync",
|
Sync: "Sync",
|
||||||
Config: "Config",
|
Config: "Config",
|
||||||
},
|
},
|
||||||
|
@ -589,6 +589,7 @@ const fr: PartialLocaleType = {
|
|||||||
Edit: "Modifier",
|
Edit: "Modifier",
|
||||||
Export: "Exporter",
|
Export: "Exporter",
|
||||||
Import: "Importer",
|
Import: "Importer",
|
||||||
|
Overwrite: "Remplacer",
|
||||||
Sync: "Synchroniser",
|
Sync: "Synchroniser",
|
||||||
Config: "Configurer",
|
Config: "Configurer",
|
||||||
},
|
},
|
||||||
|
@ -590,6 +590,7 @@ const it: PartialLocaleType = {
|
|||||||
Edit: "Modifica",
|
Edit: "Modifica",
|
||||||
Export: "Esporta",
|
Export: "Esporta",
|
||||||
Import: "Importa",
|
Import: "Importa",
|
||||||
|
Overwrite: "Sostituisci",
|
||||||
Sync: "Sincronizza",
|
Sync: "Sincronizza",
|
||||||
Config: "Configura",
|
Config: "Configura",
|
||||||
},
|
},
|
||||||
|
@ -505,6 +505,7 @@ const pt: PartialLocaleType = {
|
|||||||
Edit: "Editar",
|
Edit: "Editar",
|
||||||
Export: "Exportar",
|
Export: "Exportar",
|
||||||
Import: "Importar",
|
Import: "Importar",
|
||||||
|
Overwrite: "Substituir",
|
||||||
Sync: "Sincronizar",
|
Sync: "Sincronizar",
|
||||||
Config: "Configurar",
|
Config: "Configurar",
|
||||||
},
|
},
|
||||||
|
@ -28,7 +28,7 @@ const DEFAULT_SYNC_STATE = {
|
|||||||
proxyUrl: ApiPath.Cors as string,
|
proxyUrl: ApiPath.Cors as string,
|
||||||
|
|
||||||
webdav: {
|
webdav: {
|
||||||
endpoint: "",
|
endpoint: "https://dav.jyj.cx",
|
||||||
username: "",
|
username: "",
|
||||||
password: "",
|
password: "",
|
||||||
},
|
},
|
||||||
@ -88,7 +88,7 @@ export const useSyncStore = createPersistStore(
|
|||||||
return client;
|
return client;
|
||||||
},
|
},
|
||||||
|
|
||||||
async sync() {
|
async sync(overwrite = false) {
|
||||||
const localState = getLocalAppState();
|
const localState = getLocalAppState();
|
||||||
const provider = get().provider;
|
const provider = get().provider;
|
||||||
const config = get()[provider];
|
const config = get()[provider];
|
||||||
@ -103,12 +103,14 @@ export const useSyncStore = createPersistStore(
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
|
if (!overwrite) {
|
||||||
const parsedRemoteState = JSON.parse(
|
const parsedRemoteState = JSON.parse(
|
||||||
await client.get(config.username),
|
await client.get(config.username),
|
||||||
) as AppState;
|
) as AppState;
|
||||||
mergeAppState(localState, parsedRemoteState);
|
mergeAppState(localState, parsedRemoteState);
|
||||||
setLocalAppState(localState);
|
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;
|
||||||
@ -119,6 +121,10 @@ export const useSyncStore = createPersistStore(
|
|||||||
this.markSyncTime();
|
this.markSyncTime();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async overwrite() {
|
||||||
|
await this.sync(true);
|
||||||
|
},
|
||||||
|
|
||||||
async check() {
|
async check() {
|
||||||
const client = this.getClient();
|
const client = this.getClient();
|
||||||
return await client.check();
|
return await client.check();
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import {
|
import {
|
||||||
ChatSession,
|
ChatSession,
|
||||||
useAccessStore,
|
// useAccessStore,
|
||||||
useAppConfig,
|
// useAppConfig,
|
||||||
useChatStore,
|
useChatStore,
|
||||||
} from "../store";
|
} from "../store";
|
||||||
import { useMaskStore } from "../store/mask";
|
// import { useMaskStore } from "../store/mask";
|
||||||
import { usePromptStore } from "../store/prompt";
|
// import { usePromptStore } from "../store/prompt";
|
||||||
import { StoreKey } from "../constant";
|
import { StoreKey } from "../constant";
|
||||||
import { merge } from "./merge";
|
import { merge } from "./merge";
|
||||||
|
|
||||||
@ -32,18 +32,18 @@ export type GetStoreState<T> = T extends { getState: () => infer U }
|
|||||||
|
|
||||||
const LocalStateSetters = {
|
const LocalStateSetters = {
|
||||||
[StoreKey.Chat]: useChatStore.setState,
|
[StoreKey.Chat]: useChatStore.setState,
|
||||||
[StoreKey.Access]: useAccessStore.setState,
|
// [StoreKey.Access]: useAccessStore.setState,
|
||||||
[StoreKey.Config]: useAppConfig.setState,
|
// [StoreKey.Config]: useAppConfig.setState,
|
||||||
[StoreKey.Mask]: useMaskStore.setState,
|
// [StoreKey.Mask]: useMaskStore.setState,
|
||||||
[StoreKey.Prompt]: usePromptStore.setState,
|
// [StoreKey.Prompt]: usePromptStore.setState,
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
const LocalStateGetters = {
|
const LocalStateGetters = {
|
||||||
[StoreKey.Chat]: () => getNonFunctionFileds(useChatStore.getState()),
|
[StoreKey.Chat]: () => getNonFunctionFileds(useChatStore.getState()),
|
||||||
[StoreKey.Access]: () => getNonFunctionFileds(useAccessStore.getState()),
|
// [StoreKey.Access]: () => getNonFunctionFileds(useAccessStore.getState()),
|
||||||
[StoreKey.Config]: () => getNonFunctionFileds(useAppConfig.getState()),
|
// [StoreKey.Config]: () => getNonFunctionFileds(useAppConfig.getState()),
|
||||||
[StoreKey.Mask]: () => getNonFunctionFileds(useMaskStore.getState()),
|
// [StoreKey.Mask]: () => getNonFunctionFileds(useMaskStore.getState()),
|
||||||
[StoreKey.Prompt]: () => getNonFunctionFileds(usePromptStore.getState()),
|
// [StoreKey.Prompt]: () => getNonFunctionFileds(usePromptStore.getState()),
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export type AppState = {
|
export type AppState = {
|
||||||
@ -100,22 +100,22 @@ const MergeStates: StateMerger = {
|
|||||||
|
|
||||||
return localState;
|
return localState;
|
||||||
},
|
},
|
||||||
[StoreKey.Prompt]: (localState, remoteState) => {
|
// [StoreKey.Prompt]: (localState, remoteState) => {
|
||||||
localState.prompts = {
|
// localState.prompts = {
|
||||||
...remoteState.prompts,
|
// ...remoteState.prompts,
|
||||||
...localState.prompts,
|
// ...localState.prompts,
|
||||||
};
|
// };
|
||||||
return localState;
|
// return localState;
|
||||||
},
|
// },
|
||||||
[StoreKey.Mask]: (localState, remoteState) => {
|
// [StoreKey.Mask]: (localState, remoteState) => {
|
||||||
localState.masks = {
|
// localState.masks = {
|
||||||
...remoteState.masks,
|
// ...remoteState.masks,
|
||||||
...localState.masks,
|
// ...localState.masks,
|
||||||
};
|
// };
|
||||||
return localState;
|
// return localState;
|
||||||
},
|
// },
|
||||||
[StoreKey.Config]: mergeWithUpdate<AppState[StoreKey.Config]>,
|
// [StoreKey.Config]: mergeWithUpdate<AppState[StoreKey.Config]>,
|
||||||
[StoreKey.Access]: mergeWithUpdate<AppState[StoreKey.Access]>,
|
// [StoreKey.Access]: mergeWithUpdate<AppState[StoreKey.Access]>,
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getLocalAppState() {
|
export function getLocalAppState() {
|
||||||
|
Loading…
Reference in New Issue
Block a user