[feat] hide headers in web by proxy
This commit is contained in:
@@ -4,7 +4,7 @@ import { DataBase, setDatabase, type character } from "../storage/database";
|
|||||||
import { pluginProcess } from "./plugins";
|
import { pluginProcess } from "./plugins";
|
||||||
import { language } from "../../lang";
|
import { language } from "../../lang";
|
||||||
import { stringlizeChat, unstringlizeChat } from "./stringlize";
|
import { stringlizeChat, unstringlizeChat } from "./stringlize";
|
||||||
import { globalFetch, isTauri } from "../storage/globalApi";
|
import { globalFetch, isNodeServer, isTauri } from "../storage/globalApi";
|
||||||
import { sleep } from "../util";
|
import { sleep } from "../util";
|
||||||
import { createDeep } from "./deepai";
|
import { createDeep } from "./deepai";
|
||||||
|
|
||||||
@@ -167,15 +167,28 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model'
|
|||||||
|
|
||||||
if(db.useStreaming && arg.useStreaming){
|
if(db.useStreaming && arg.useStreaming){
|
||||||
body.stream = true
|
body.stream = true
|
||||||
const da = await fetch(replacerURL, {
|
const da = ((!isTauri) && (!isNodeServer))
|
||||||
body: JSON.stringify(body),
|
? await fetch(`/proxy?url=${encodeURIComponent(replacerURL)}`, {
|
||||||
method: "POST",
|
body: JSON.stringify(body),
|
||||||
headers: {
|
headers: {
|
||||||
"Authorization": "Bearer " + db.openAIKey,
|
"risu-header": encodeURIComponent(JSON.stringify({
|
||||||
"Content-Type": "application/json"
|
"Authorization": "Bearer " + db.openAIKey,
|
||||||
},
|
"Content-Type": "application/json"
|
||||||
signal: abortSignal
|
})),
|
||||||
})
|
"Content-Type": "application/json"
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
signal: abortSignal
|
||||||
|
})
|
||||||
|
: await fetch(replacerURL, {
|
||||||
|
body: JSON.stringify(body),
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Authorization": "Bearer " + db.openAIKey,
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
},
|
||||||
|
signal: abortSignal
|
||||||
|
})
|
||||||
|
|
||||||
if(da.status !== 200){
|
if(da.status !== 200){
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -373,7 +373,7 @@ export async function loadData() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const knownHostes = ["localhost","127.0.0.1","api.openai.com"]
|
const knownHostes = ["localhost","127.0.0.1"]
|
||||||
|
|
||||||
export async function globalFetch(url:string, arg:{body?:any,headers?:{[key:string]:string}, rawResponse?:boolean, method?:"POST"|"GET", abortSignal?:AbortSignal} = {}): Promise<{
|
export async function globalFetch(url:string, arg:{body?:any,headers?:{[key:string]:string}, rawResponse?:boolean, method?:"POST"|"GET", abortSignal?:AbortSignal} = {}): Promise<{
|
||||||
ok: boolean;
|
ok: boolean;
|
||||||
|
|||||||
Reference in New Issue
Block a user