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

View File

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