mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-05-19 20:20:16 +09:00
更新同步模块
This commit is contained in:
parent
d08af47342
commit
1cccaa2e80
@ -528,6 +528,21 @@ function SyncItems() {
|
||||
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 && (
|
||||
<IconButton
|
||||
icon={<ResetIcon />}
|
||||
|
@ -757,6 +757,7 @@ const cn = {
|
||||
Export: "导出",
|
||||
Import: "导入",
|
||||
Sync: "同步",
|
||||
Overwrite: "覆盖",
|
||||
Config: "配置",
|
||||
},
|
||||
Exporter: {
|
||||
|
@ -762,6 +762,7 @@ const en: LocaleType = {
|
||||
Edit: "Edit",
|
||||
Export: "Export",
|
||||
Import: "Import",
|
||||
Overwrite: "Overwrite",
|
||||
Sync: "Sync",
|
||||
Config: "Config",
|
||||
},
|
||||
|
@ -589,6 +589,7 @@ const fr: PartialLocaleType = {
|
||||
Edit: "Modifier",
|
||||
Export: "Exporter",
|
||||
Import: "Importer",
|
||||
Overwrite: "Remplacer",
|
||||
Sync: "Synchroniser",
|
||||
Config: "Configurer",
|
||||
},
|
||||
|
@ -590,6 +590,7 @@ const it: PartialLocaleType = {
|
||||
Edit: "Modifica",
|
||||
Export: "Esporta",
|
||||
Import: "Importa",
|
||||
Overwrite: "Sostituisci",
|
||||
Sync: "Sincronizza",
|
||||
Config: "Configura",
|
||||
},
|
||||
|
@ -505,6 +505,7 @@ const pt: PartialLocaleType = {
|
||||
Edit: "Editar",
|
||||
Export: "Exportar",
|
||||
Import: "Importar",
|
||||
Overwrite: "Substituir",
|
||||
Sync: "Sincronizar",
|
||||
Config: "Configurar",
|
||||
},
|
||||
|
@ -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();
|
||||
|
@ -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> = 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<AppState[StoreKey.Config]>,
|
||||
[StoreKey.Access]: mergeWithUpdate<AppState[StoreKey.Access]>,
|
||||
// [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<AppState[StoreKey.Config]>,
|
||||
// [StoreKey.Access]: mergeWithUpdate<AppState[StoreKey.Access]>,
|
||||
};
|
||||
|
||||
export function getLocalAppState() {
|
||||
|
Loading…
Reference in New Issue
Block a user