mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-10-10 03:56:37 +08:00
update user host
This commit is contained in:
parent
7d7f3716be
commit
22ec525618
@ -3,12 +3,13 @@ import { NextRequest } from "next/server";
|
|||||||
const OPENAI_URL = "api.openai.com";
|
const OPENAI_URL = "api.openai.com";
|
||||||
const DEFAULT_PROTOCOL = "https";
|
const DEFAULT_PROTOCOL = "https";
|
||||||
const PROTOCOL = process.env.PROTOCOL ?? DEFAULT_PROTOCOL;
|
const PROTOCOL = process.env.PROTOCOL ?? DEFAULT_PROTOCOL;
|
||||||
const BASE_URL = process.env.BASE_URL ?? OPENAI_URL;
|
|
||||||
|
|
||||||
export async function requestOpenai(req: NextRequest) {
|
export async function requestOpenai(req: NextRequest) {
|
||||||
const apiKey = req.headers.get("token");
|
const apiKey = req.headers.get("token");
|
||||||
const openaiPath = req.headers.get("path");
|
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);
|
console.log("[Proxy] ", openaiPath);
|
||||||
|
|
||||||
return fetch(`${PROTOCOL}://${BASE_URL}/${openaiPath}`, {
|
return fetch(`${PROTOCOL}://${BASE_URL}/${openaiPath}`, {
|
||||||
|
@ -372,6 +372,20 @@ export function Settings(props: { closeSettings: () => void }) {
|
|||||||
<></>
|
<></>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
<SettingItem
|
||||||
|
title={Locale.Settings.Host.Title}
|
||||||
|
subTitle={Locale.Settings.Host.SubTitle}
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
value={accessStore.host}
|
||||||
|
type="text"
|
||||||
|
placeholder={Locale.Settings.Host.Placeholder}
|
||||||
|
onChange={(e) => {
|
||||||
|
accessStore.updateHost(e.currentTarget.value);
|
||||||
|
}}
|
||||||
|
></input>
|
||||||
|
</SettingItem>
|
||||||
|
|
||||||
<SettingItem
|
<SettingItem
|
||||||
title={Locale.Settings.Token.Title}
|
title={Locale.Settings.Token.Title}
|
||||||
subTitle={Locale.Settings.Token.SubTitle}
|
subTitle={Locale.Settings.Token.SubTitle}
|
||||||
|
@ -97,6 +97,11 @@ const cn = {
|
|||||||
Title: "历史消息长度压缩阈值",
|
Title: "历史消息长度压缩阈值",
|
||||||
SubTitle: "当未压缩的历史消息超过该值时,将进行压缩",
|
SubTitle: "当未压缩的历史消息超过该值时,将进行压缩",
|
||||||
},
|
},
|
||||||
|
Host: {
|
||||||
|
Title: "Personal Host",
|
||||||
|
SubTitle: "使用自己的 Host 可绕过受控访问限制",
|
||||||
|
Placeholder: "api.openai.com",
|
||||||
|
},
|
||||||
Token: {
|
Token: {
|
||||||
Title: "API Key",
|
Title: "API Key",
|
||||||
SubTitle: "使用自己的 Key 可绕过受控访问限制",
|
SubTitle: "使用自己的 Key 可绕过受控访问限制",
|
||||||
|
@ -99,6 +99,11 @@ const en: LocaleType = {
|
|||||||
SubTitle:
|
SubTitle:
|
||||||
"Will compress if uncompressed messages length exceeds the value",
|
"Will compress if uncompressed messages length exceeds the value",
|
||||||
},
|
},
|
||||||
|
Host: {
|
||||||
|
Title: "Personal Host",
|
||||||
|
SubTitle: "Use your host to ignore access code limit",
|
||||||
|
Placeholder: "api.openai.com",
|
||||||
|
},
|
||||||
Token: {
|
Token: {
|
||||||
Title: "API Key",
|
Title: "API Key",
|
||||||
SubTitle: "Use your key to ignore access code limit",
|
SubTitle: "Use your key to ignore access code limit",
|
||||||
|
@ -99,6 +99,11 @@ const es: LocaleType = {
|
|||||||
SubTitle:
|
SubTitle:
|
||||||
"Se comprimirán los mensajes si la longitud de los mensajes no comprimidos supera el valor",
|
"Se comprimirán los mensajes si la longitud de los mensajes no comprimidos supera el valor",
|
||||||
},
|
},
|
||||||
|
Host: {
|
||||||
|
Title: "Clave de Host",
|
||||||
|
SubTitle: "Utiliza tu clave para ignorar el límite de código de acceso",
|
||||||
|
Placeholder: "api.openai.com",
|
||||||
|
},
|
||||||
Token: {
|
Token: {
|
||||||
Title: "Clave de API",
|
Title: "Clave de API",
|
||||||
SubTitle: "Utiliza tu clave para ignorar el límite de código de acceso",
|
SubTitle: "Utiliza tu clave para ignorar el límite de código de acceso",
|
||||||
|
@ -99,6 +99,12 @@ const it: LocaleType = {
|
|||||||
SubTitle:
|
SubTitle:
|
||||||
"Comprimerà se la lunghezza dei messaggi non compressi supera il valore",
|
"Comprimerà se la lunghezza dei messaggi non compressi supera il valore",
|
||||||
},
|
},
|
||||||
|
Host: {
|
||||||
|
Title: "Chiave Host",
|
||||||
|
SubTitle:
|
||||||
|
"Utilizzare la chiave per ignorare il limite del codice di accesso",
|
||||||
|
Placeholder: "api.openai.com",
|
||||||
|
},
|
||||||
Token: {
|
Token: {
|
||||||
Title: "Chiave API",
|
Title: "Chiave API",
|
||||||
SubTitle:
|
SubTitle:
|
||||||
|
@ -97,6 +97,11 @@ const tw: LocaleType = {
|
|||||||
Title: "歷史訊息長度壓縮閾值",
|
Title: "歷史訊息長度壓縮閾值",
|
||||||
SubTitle: "當未壓縮的歷史訊息超過該值時,將進行壓縮",
|
SubTitle: "當未壓縮的歷史訊息超過該值時,將進行壓縮",
|
||||||
},
|
},
|
||||||
|
Host: {
|
||||||
|
Title: "Personal Host",
|
||||||
|
SubTitle: "使用自己的 Host 可規避受控訪問限制",
|
||||||
|
Placeholder: "api.openai.com",
|
||||||
|
},
|
||||||
Token: {
|
Token: {
|
||||||
Title: "API Key",
|
Title: "API Key",
|
||||||
SubTitle: "使用自己的 Key 可規避受控訪問限制",
|
SubTitle: "使用自己的 Key 可規避受控訪問限制",
|
||||||
|
@ -38,6 +38,7 @@ function getHeaders() {
|
|||||||
|
|
||||||
if (accessStore.token && accessStore.token.length > 0) {
|
if (accessStore.token && accessStore.token.length > 0) {
|
||||||
headers["token"] = accessStore.token;
|
headers["token"] = accessStore.token;
|
||||||
|
headers["userhost"] = accessStore.host;
|
||||||
}
|
}
|
||||||
|
|
||||||
return headers;
|
return headers;
|
||||||
|
@ -5,7 +5,9 @@ import { queryMeta } from "../utils";
|
|||||||
export interface AccessControlStore {
|
export interface AccessControlStore {
|
||||||
accessCode: string;
|
accessCode: string;
|
||||||
token: string;
|
token: string;
|
||||||
|
host: string;
|
||||||
|
|
||||||
|
updateHost: (_: string) => void;
|
||||||
updateToken: (_: string) => void;
|
updateToken: (_: string) => void;
|
||||||
updateCode: (_: string) => void;
|
updateCode: (_: string) => void;
|
||||||
enabledAccessControl: () => boolean;
|
enabledAccessControl: () => boolean;
|
||||||
@ -18,6 +20,7 @@ export const useAccessStore = create<AccessControlStore>()(
|
|||||||
(set, get) => ({
|
(set, get) => ({
|
||||||
token: "",
|
token: "",
|
||||||
accessCode: "",
|
accessCode: "",
|
||||||
|
host: "",
|
||||||
enabledAccessControl() {
|
enabledAccessControl() {
|
||||||
return queryMeta("access") === "enabled";
|
return queryMeta("access") === "enabled";
|
||||||
},
|
},
|
||||||
@ -27,10 +30,13 @@ export const useAccessStore = create<AccessControlStore>()(
|
|||||||
updateToken(token: string) {
|
updateToken(token: string) {
|
||||||
set((state) => ({ token }));
|
set((state) => ({ token }));
|
||||||
},
|
},
|
||||||
|
updateHost(host: string) {
|
||||||
|
set((state) => ({ host }));
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
name: ACCESS_KEY,
|
name: ACCESS_KEY,
|
||||||
version: 1,
|
version: 1,
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user