[feat] added tokens for reverse proxy
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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`
|
||||||
|
|
||||||
|
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, {
|
const da = await fetch(furl, {
|
||||||
body: body,
|
body: body,
|
||||||
headers: {
|
headers: headers,
|
||||||
"risu-header": encodeURIComponent(JSON.stringify(arg.headers)),
|
|
||||||
"risu-url": encodeURIComponent(url),
|
|
||||||
"Content-Type": "application/json"
|
|
||||||
},
|
|
||||||
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`
|
||||||
|
|
||||||
|
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, {
|
const da = await fetch(furl, {
|
||||||
body: body,
|
body: body,
|
||||||
headers: {
|
headers: headers,
|
||||||
"risu-header": encodeURIComponent(JSON.stringify(arg.headers)),
|
|
||||||
"risu-url": encodeURIComponent(url),
|
|
||||||
"Content-Type": "application/json"
|
|
||||||
},
|
|
||||||
method: method
|
method: method
|
||||||
})
|
})
|
||||||
const daText = await da.text()
|
const daText = await da.text()
|
||||||
|
|||||||
Reference in New Issue
Block a user