From 22ec52561865f883ec08b57d71e1d1ddc34c4005 Mon Sep 17 00:00:00 2001
From: Junlai <1462011227@qq.com>
Date: Tue, 4 Apr 2023 03:34:33 +0000
Subject: [PATCH] update user host
---
app/api/common.ts | 5 +++--
app/components/settings.tsx | 14 ++++++++++++++
app/locales/cn.ts | 5 +++++
app/locales/en.ts | 5 +++++
app/locales/es.ts | 5 +++++
app/locales/it.ts | 6 ++++++
app/locales/tw.ts | 5 +++++
app/requests.ts | 1 +
app/store/access.ts | 10 ++++++++--
9 files changed, 52 insertions(+), 4 deletions(-)
diff --git a/app/api/common.ts b/app/api/common.ts
index 842eeacaf..d67d7cea8 100644
--- a/app/api/common.ts
+++ b/app/api/common.ts
@@ -3,12 +3,13 @@ import { NextRequest } from "next/server";
const OPENAI_URL = "api.openai.com";
const DEFAULT_PROTOCOL = "https";
const PROTOCOL = process.env.PROTOCOL ?? DEFAULT_PROTOCOL;
-const BASE_URL = process.env.BASE_URL ?? OPENAI_URL;
export async function requestOpenai(req: NextRequest) {
const apiKey = req.headers.get("token");
const openaiPath = req.headers.get("path");
-
+ const userHost = req.headers.get("userhost");
+ const BASE_URL = userHost ?? process.env.BASE_URL ?? OPENAI_URL;
+ console.log("[BASE_URL] ", openaiPath);
console.log("[Proxy] ", openaiPath);
return fetch(`${PROTOCOL}://${BASE_URL}/${openaiPath}`, {
diff --git a/app/components/settings.tsx b/app/components/settings.tsx
index 4645f3191..5f7ceb5ad 100644
--- a/app/components/settings.tsx
+++ b/app/components/settings.tsx
@@ -372,6 +372,20 @@ export function Settings(props: { closeSettings: () => void }) {
<>>
)}
+
+ {
+ accessStore.updateHost(e.currentTarget.value);
+ }}
+ >
+
+
0) {
headers["token"] = accessStore.token;
+ headers["userhost"] = accessStore.host;
}
return headers;
diff --git a/app/store/access.ts b/app/store/access.ts
index 9c61dfa01..ff636330a 100644
--- a/app/store/access.ts
+++ b/app/store/access.ts
@@ -5,7 +5,9 @@ import { queryMeta } from "../utils";
export interface AccessControlStore {
accessCode: string;
token: string;
+ host: string;
+ updateHost: (_: string) => void;
updateToken: (_: string) => void;
updateCode: (_: string) => void;
enabledAccessControl: () => boolean;
@@ -18,6 +20,7 @@ export const useAccessStore = create()(
(set, get) => ({
token: "",
accessCode: "",
+ host: "",
enabledAccessControl() {
return queryMeta("access") === "enabled";
},
@@ -27,10 +30,13 @@ export const useAccessStore = create()(
updateToken(token: string) {
set((state) => ({ token }));
},
+ updateHost(host: string) {
+ set((state) => ({ host }));
+ },
}),
{
name: ACCESS_KEY,
version: 1,
- }
- )
+ },
+ ),
);