mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-10-15 14:33:43 +08:00
修改密钥加密逻辑
This commit is contained in:
@@ -23,35 +23,24 @@ import { createPersistStore } from "../utils/store";
|
||||
import { ensure } from "../utils/clone";
|
||||
import { DEFAULT_CONFIG } from "./config";
|
||||
import { getModelProvider } from "../utils/model";
|
||||
import { encrypt, decrypt } from "../utils/aws";
|
||||
|
||||
let fetchState = 0; // 0 not fetch, 1 fetching, 2 done
|
||||
|
||||
const isApp = getClientConfig()?.buildMode === "export";
|
||||
|
||||
const DEFAULT_OPENAI_URL = isApp ? OPENAI_BASE_URL : ApiPath.OpenAI;
|
||||
|
||||
const DEFAULT_GOOGLE_URL = isApp ? GEMINI_BASE_URL : ApiPath.Google;
|
||||
|
||||
const DEFAULT_ANTHROPIC_URL = isApp ? ANTHROPIC_BASE_URL : ApiPath.Anthropic;
|
||||
|
||||
const DEFAULT_BAIDU_URL = isApp ? BAIDU_BASE_URL : ApiPath.Baidu;
|
||||
|
||||
const DEFAULT_BYTEDANCE_URL = isApp ? BYTEDANCE_BASE_URL : ApiPath.ByteDance;
|
||||
|
||||
const DEFAULT_ALIBABA_URL = isApp ? ALIBABA_BASE_URL : ApiPath.Alibaba;
|
||||
|
||||
const DEFAULT_TENCENT_URL = isApp ? TENCENT_BASE_URL : ApiPath.Tencent;
|
||||
|
||||
const DEFAULT_MOONSHOT_URL = isApp ? MOONSHOT_BASE_URL : ApiPath.Moonshot;
|
||||
|
||||
const DEFAULT_STABILITY_URL = isApp ? STABILITY_BASE_URL : ApiPath.Stability;
|
||||
|
||||
const DEFAULT_IFLYTEK_URL = isApp ? IFLYTEK_BASE_URL : ApiPath.Iflytek;
|
||||
|
||||
const DEFAULT_XAI_URL = isApp ? XAI_BASE_URL : ApiPath.XAI;
|
||||
|
||||
const DEFAULT_CHATGLM_URL = isApp ? CHATGLM_BASE_URL : ApiPath.ChatGLM;
|
||||
|
||||
const DEFAULT_BEDROCK_URL = isApp ? BEDROCK_BASE_URL : ApiPath.Bedrock;
|
||||
|
||||
const DEFAULT_ACCESS_STATE = {
|
||||
@@ -141,17 +130,14 @@ const DEFAULT_ACCESS_STATE = {
|
||||
|
||||
export const useAccessStore = createPersistStore(
|
||||
{ ...DEFAULT_ACCESS_STATE },
|
||||
|
||||
(set, get) => ({
|
||||
enabledAccessControl() {
|
||||
this.fetch();
|
||||
|
||||
return get().needCode;
|
||||
},
|
||||
|
||||
edgeVoiceName() {
|
||||
this.fetch();
|
||||
|
||||
return get().edgeTTSVoiceName;
|
||||
},
|
||||
|
||||
@@ -253,7 +239,6 @@ export const useAccessStore = createPersistStore(
|
||||
DEFAULT_CONFIG.modelConfig.model = model;
|
||||
DEFAULT_CONFIG.modelConfig.providerName = providerName as any;
|
||||
}
|
||||
|
||||
return res;
|
||||
})
|
||||
.then((res: DangerConfig) => {
|
||||
@@ -267,6 +252,31 @@ export const useAccessStore = createPersistStore(
|
||||
fetchState = 2;
|
||||
});
|
||||
},
|
||||
|
||||
// Override the set method to encrypt AWS credentials before storage
|
||||
set: (partial: { [key: string]: any }) => {
|
||||
if (partial.awsAccessKey) {
|
||||
partial.awsAccessKey = encrypt(partial.awsAccessKey);
|
||||
}
|
||||
if (partial.awsSecretKey) {
|
||||
partial.awsSecretKey = encrypt(partial.awsSecretKey);
|
||||
}
|
||||
if (partial.awsRegion) {
|
||||
partial.awsRegion = encrypt(partial.awsRegion);
|
||||
}
|
||||
set(partial);
|
||||
},
|
||||
|
||||
// Add getter to decrypt AWS credentials when needed
|
||||
get: () => {
|
||||
const state = get();
|
||||
return {
|
||||
...state,
|
||||
awsRegion: state.awsRegion ? decrypt(state.awsRegion) : "",
|
||||
awsAccessKey: state.awsAccessKey ? decrypt(state.awsAccessKey) : "",
|
||||
awsSecretKey: state.awsSecretKey ? decrypt(state.awsSecretKey) : "",
|
||||
};
|
||||
},
|
||||
}),
|
||||
{
|
||||
name: StoreKey.Access,
|
||||
|
Reference in New Issue
Block a user