Compare commits

...

2 Commits

Author SHA1 Message Date
JiangYingjin
88f8ca822f 新增 webdav 一键填入 2025-03-02 14:04:57 +08:00
JiangYingjin
1cccaa2e80 更新同步模块 2025-03-02 12:25:33 +08:00
10 changed files with 107 additions and 64 deletions

View File

@@ -107,6 +107,7 @@ import {
} from "../constant";
import { Avatar } from "./emoji";
import { ContextPrompts, MaskAvatar, MaskConfig } from "./mask";
import { useSyncStore } from "../store/sync";
import { useMaskStore } from "../store/mask";
import { ChatCommandPrefix, useChatCommand, useCommand } from "../command";
import { prettyObject } from "../utils/format";
@@ -948,6 +949,8 @@ function _Chat() {
const fontSize = config.fontSize;
const fontFamily = config.fontFamily;
const syncStore = useSyncStore();
const [showExport, setShowExport] = useState(false);
const inputRef = useRef<HTMLTextAreaElement>(null);
@@ -1395,45 +1398,27 @@ function _Chat() {
submit: (text) => {
doSubmit(text);
},
code: (text) => {
if (accessStore.disableFastLink) return;
console.log("[Command] got code from url: ", text);
showConfirm(Locale.URLCommand.Code + `code = ${text}`).then((res) => {
if (res) {
accessStore.update((access) => (access.accessCode = text));
}
});
},
// code: (text) => {
// if (accessStore.disableFastLink) return;
// console.log("[Command] got code from url: ", text);
// showConfirm(Locale.URLCommand.Code + `code = ${text}`).then((res) => {
// if (res) {
// accessStore.update((access) => (access.accessCode = text));
// }
// });
// },
settings: (text) => {
if (accessStore.disableFastLink) return;
try {
const payload = JSON.parse(text) as {
key?: string;
url?: string;
code?: string;
username?: string;
password?: string;
};
console.log("[Command] got settings from url: ", payload);
if (payload.key || payload.url) {
showConfirm(
Locale.URLCommand.Settings +
`\n${JSON.stringify(payload, null, 4)}`,
).then((res) => {
if (!res) return;
if (payload.key) {
accessStore.update(
(access) => (access.openaiApiKey = payload.key!),
);
}
if (payload.url) {
accessStore.update((access) => (access.openaiUrl = payload.url!));
}
accessStore.update((access) => (access.useCustomConfig = true));
});
}
if (payload.code) {
accessStore.update((access) => (access.accessCode = payload.code!));
if (accessStore.isAuthorized()) {
@@ -1443,6 +1428,22 @@ function _Chat() {
setUserInput(" ");
}
}
if (payload.username) {
syncStore.update(
(config) => (config.webdav.username = payload.username!),
);
}
if (payload.password) {
syncStore.update(
(config) => (config.webdav.password = payload.password!),
);
}
if (payload.username && payload.password) {
syncStore.sync();
}
} catch {
console.error("[Command] failed to get settings from url: ", text);
}

View File

@@ -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 />}

View File

@@ -757,6 +757,7 @@ const cn = {
Export: "导出",
Import: "导入",
Sync: "同步",
Overwrite: "覆盖",
Config: "配置",
},
Exporter: {

View File

@@ -762,6 +762,7 @@ const en: LocaleType = {
Edit: "Edit",
Export: "Export",
Import: "Import",
Overwrite: "Overwrite",
Sync: "Sync",
Config: "Config",
},

View File

@@ -589,6 +589,7 @@ const fr: PartialLocaleType = {
Edit: "Modifier",
Export: "Exporter",
Import: "Importer",
Overwrite: "Remplacer",
Sync: "Synchroniser",
Config: "Configurer",
},

View File

@@ -590,6 +590,7 @@ const it: PartialLocaleType = {
Edit: "Modifica",
Export: "Esporta",
Import: "Importa",
Overwrite: "Sostituisci",
Sync: "Sincronizza",
Config: "Configura",
},

View File

@@ -505,6 +505,7 @@ const pt: PartialLocaleType = {
Edit: "Editar",
Export: "Exportar",
Import: "Importar",
Overwrite: "Substituir",
Sync: "Sincronizar",
Config: "Configurar",
},

View File

@@ -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();

View File

@@ -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() {

16
nextchat.json Normal file
View File

@@ -0,0 +1,16 @@
{
"name": "nextchat",
"cwd": "/www/nextchat",
"script": "server.js",
"env": {
"PORT": 8032,
"CODE": "scut",
"BASE_URL": "https://oneapi.jyj.cx",
"OPENAI_API_KEY": "sk-jiangyj",
"HIDE_USER_API_KEY": true,
"CUSTOM_MODELS": "-all,gemini-2.0-pro-exp-02-05@openai,gemini-2.0-flash-thinking-exp-01-21@openai,gemini-2.0-flash-exp@openai,gemini-2.0-flash@openai,gemini-2.0-flash-lite@openai,gpt-4o-2024-11-20@openai,o3-mini@openai,deepseek-ai/deepseek-v3@openai,deepseek-ai/deepseek-r1@openai,deepseek-chat@openai,deepseek-reasoner@openai,ep-20250124104315-zsg4p@openai",
"DEFAULT_MODEL": "gemini-2.0-pro-exp-02-05@openai",
"WHITE_WEBDAV_ENDPOINTS": "https://dav.jyj.cx",
"VISION_MODELS": "gemini-2.0-flash-thinking-exp-01-21@openai,gemini-2.0-pro-exp-02-05@openai,gemini-2.0-flash-exp@openai,gemini-2.0-flash@openai,gemini-2.0-flash-lite@openai,gpt-4o-2024-11-20@openai,o3-mini@openai,deepseek-ai/DeepSeek-V3@openai,deepseek-ai/DeepSeek-R1@openai,deepseek-chat@openai,deepseek-reasoner@openai,ep-20250124104315-zsg4p@openai"
}
}