[feat] added tokens for reverse proxy

This commit is contained in:
kwaroran
2023-07-22 01:04:29 +09:00
parent 3250831c1a
commit 873f9cf6f8
2 changed files with 32 additions and 14 deletions

View File

@@ -201,7 +201,8 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model'
headers: { headers: {
"risu-header": encodeURIComponent(JSON.stringify(headers)), "risu-header": encodeURIComponent(JSON.stringify(headers)),
"risu-url": encodeURIComponent(replacerURL), "risu-url": encodeURIComponent(replacerURL),
"Content-Type": "application/json" "Content-Type": "application/json",
"x-risu-tk": "use"
}, },
method: "POST", method: "POST",
signal: abortSignal signal: abortSignal
@@ -268,7 +269,7 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model'
const res = await globalFetch(replacerURL, { const res = await globalFetch(replacerURL, {
body: body, body: body,
headers: headers, headers: headers,
abortSignal abortSignal,
}) })
const dat = res.data as any const dat = res.data as any

View File

@@ -437,10 +437,18 @@ export async function loadData() {
const knownHostes = ["localhost","127.0.0.1"] const knownHostes = ["localhost","127.0.0.1"]
export async function globalFetch(url:string, arg:{plainFetchForce?:boolean,body?:any,headers?:{[key:string]:string}, rawResponse?:boolean, method?:"POST"|"GET", abortSignal?:AbortSignal} = {}): Promise<{ export async function globalFetch(url:string, arg:{
plainFetchForce?:boolean,
body?:any,
headers?:{[key:string]:string},
rawResponse?:boolean,
method?:"POST"|"GET",
abortSignal?:AbortSignal,
useRisuToken?:boolean
} = {}): Promise<{
ok: boolean; ok: boolean;
data: any; data: any;
headers:{[key:string]:string} headers:{[key:string]:string},
}> { }> {
try { try {
const db = get(DataBase) const db = get(DataBase)
@@ -625,13 +633,18 @@ export async function globalFetch(url:string, arg:{plainFetchForce?:boolean,body
if(arg.rawResponse){ if(arg.rawResponse){
const furl = ((!isTauri) && (!isNodeServer)) ? `${hubURL}/proxy2` : `/proxy2` const furl = ((!isTauri) && (!isNodeServer)) ? `${hubURL}/proxy2` : `/proxy2`
const da = await fetch(furl, { let headers = {
body: body,
headers: {
"risu-header": encodeURIComponent(JSON.stringify(arg.headers)), "risu-header": encodeURIComponent(JSON.stringify(arg.headers)),
"risu-url": encodeURIComponent(url), "risu-url": encodeURIComponent(url),
"Content-Type": "application/json" "Content-Type": "application/json",
}, }
if(arg.useRisuToken){
headers["x-risu-tk"] = "use"
}
const da = await fetch(furl, {
body: body,
headers: headers,
method: method, method: method,
signal: arg.abortSignal signal: arg.abortSignal
}) })
@@ -646,13 +659,17 @@ export async function globalFetch(url:string, arg:{plainFetchForce?:boolean,body
else{ else{
const furl = ((!isTauri) && (!isNodeServer)) ? `${hubURL}/proxy2` : `/proxy2` const furl = ((!isTauri) && (!isNodeServer)) ? `${hubURL}/proxy2` : `/proxy2`
const da = await fetch(furl, { let headers = {
body: body,
headers: {
"risu-header": encodeURIComponent(JSON.stringify(arg.headers)), "risu-header": encodeURIComponent(JSON.stringify(arg.headers)),
"risu-url": encodeURIComponent(url), "risu-url": encodeURIComponent(url),
"Content-Type": "application/json" "Content-Type": "application/json"
}, }
if(arg.useRisuToken){
headers["x-risu-tk"] = "use"
}
const da = await fetch(furl, {
body: body,
headers: headers,
method: method method: method
}) })
const daText = await da.text() const daText = await da.text()