mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2026-02-19 12:54:27 +08:00
Compare commits
2 Commits
d08af47342
...
88f8ca822f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
88f8ca822f | ||
|
|
1cccaa2e80 |
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
16
nextchat.json
Normal file
16
nextchat.json
Normal 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"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user