|
@@ -1,9 +1,10 @@
|
|
|
import { create } from "zustand";
|
|
|
import { persist } from "zustand/middleware";
|
|
|
-import { StoreKey } from "../constant";
|
|
|
+import { DEFAULT_API_HOST, StoreKey } from "../constant";
|
|
|
import { getHeaders } from "../client/api";
|
|
|
import { BOT_HELLO } from "./chat";
|
|
|
import { ALL_MODELS } from "./config";
|
|
|
+import { getClientConfig } from "../config/client";
|
|
|
|
|
|
export interface AccessControlStore {
|
|
|
accessCode: string;
|
|
@@ -15,6 +16,7 @@ export interface AccessControlStore {
|
|
|
|
|
|
updateToken: (_: string) => void;
|
|
|
updateCode: (_: string) => void;
|
|
|
+ updateOpenAiUrl: (_: string) => void;
|
|
|
enabledAccessControl: () => boolean;
|
|
|
isAuthorized: () => boolean;
|
|
|
fetch: () => void;
|
|
@@ -22,6 +24,10 @@ export interface AccessControlStore {
|
|
|
|
|
|
let fetchState = 0; // 0 not fetch, 1 fetching, 2 done
|
|
|
|
|
|
+const DEFAULT_OPENAI_URL =
|
|
|
+ getClientConfig()?.buildMode === "export" ? DEFAULT_API_HOST : "/api/openai/";
|
|
|
+console.log("[API] default openai url", DEFAULT_OPENAI_URL);
|
|
|
+
|
|
|
export const useAccessStore = create<AccessControlStore>()(
|
|
|
persist(
|
|
|
(set, get) => ({
|
|
@@ -29,7 +35,7 @@ export const useAccessStore = create<AccessControlStore>()(
|
|
|
accessCode: "",
|
|
|
needCode: true,
|
|
|
hideUserApiKey: false,
|
|
|
- openaiUrl: "/api/openai/",
|
|
|
+ openaiUrl: DEFAULT_OPENAI_URL,
|
|
|
|
|
|
enabledAccessControl() {
|
|
|
get().fetch();
|
|
@@ -42,6 +48,9 @@ export const useAccessStore = create<AccessControlStore>()(
|
|
|
updateToken(token: string) {
|
|
|
set(() => ({ token }));
|
|
|
},
|
|
|
+ updateOpenAiUrl(url: string) {
|
|
|
+ set(() => ({ openaiUrl: url }));
|
|
|
+ },
|
|
|
isAuthorized() {
|
|
|
get().fetch();
|
|
|
|