This commit is contained in:
lloydzhou
2024-10-23 11:40:06 +08:00
parent 06f897f32f
commit 8455fefc8a
11 changed files with 447 additions and 1 deletions

View File

@@ -13,6 +13,7 @@ import {
MOONSHOT_BASE_URL,
STABILITY_BASE_URL,
IFLYTEK_BASE_URL,
XAI_BASE_URL,
} from "../constant";
import { getHeaders } from "../client/api";
import { getClientConfig } from "../config/client";
@@ -44,6 +45,8 @@ 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_ACCESS_STATE = {
accessCode: "",
useCustomConfig: false,
@@ -101,6 +104,10 @@ const DEFAULT_ACCESS_STATE = {
iflytekApiKey: "",
iflytekApiSecret: "",
// moonshot
xaiUrl: DEFAULT_XAI_URL,
xaiApiKey: "",
// server config
needCode: true,
hideUserApiKey: false,
@@ -169,6 +176,10 @@ export const useAccessStore = createPersistStore(
return ensure(get(), ["iflytekApiKey"]);
},
isValidXAI() {
return ensure(get(), ["xaiApiKey"]);
},
isAuthorized() {
this.fetch();
@@ -184,6 +195,7 @@ export const useAccessStore = createPersistStore(
this.isValidTencent() ||
this.isValidMoonshot() ||
this.isValidIflytek() ||
this.isValidXAI() ||
!this.enabledAccessControl() ||
(this.enabledAccessControl() && ensure(get(), ["accessCode"]))
);