[refactor] proxy url by header
This commit is contained in:
@@ -12,7 +12,9 @@ async function fetchProxy(request) {
|
|||||||
let response = null;
|
let response = null;
|
||||||
let rurl = new URL(request.url);
|
let rurl = new URL(request.url);
|
||||||
|
|
||||||
const urlParam = rurl.searchParams.get('url')
|
const nheader = request.headers.get('risu-url') ? decodeURIComponent(request.headers.get('risu-url')) : null
|
||||||
|
|
||||||
|
const urlParam = nheader ?? rurl.searchParams.get('url')
|
||||||
|
|
||||||
if(!urlParam){
|
if(!urlParam){
|
||||||
return new Response('Access denied', {
|
return new Response('Access denied', {
|
||||||
|
|||||||
@@ -181,13 +181,14 @@ 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 = ((!isTauri) && (!isNodeServer))
|
const da = ((!isTauri) && (!isNodeServer))
|
||||||
? await fetch(`/proxy2?url=${encodeURIComponent(replacerURL)}`, {
|
? await fetch(`/proxy2`, {
|
||||||
body: JSON.stringify(body),
|
body: JSON.stringify(body),
|
||||||
headers: {
|
headers: {
|
||||||
"risu-header": encodeURIComponent(JSON.stringify({
|
"risu-header": encodeURIComponent(JSON.stringify({
|
||||||
"Authorization": "Bearer " + db.openAIKey,
|
"Authorization": "Bearer " + db.openAIKey,
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
})),
|
})),
|
||||||
|
"risu-url": encodeURIComponent(replacerURL),
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
},
|
},
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|||||||
@@ -617,12 +617,13 @@ export async function globalFetch(url:string, arg:{plainFetchForce?:boolean,body
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(arg.rawResponse){
|
if(arg.rawResponse){
|
||||||
const furl = `/proxy2?url=${encodeURIComponent(url)}`
|
const furl = `/proxy2`
|
||||||
|
|
||||||
const da = await fetch(furl, {
|
const da = await fetch(furl, {
|
||||||
body: body,
|
body: body,
|
||||||
headers: {
|
headers: {
|
||||||
"risu-header": encodeURIComponent(JSON.stringify(arg.headers)),
|
"risu-header": encodeURIComponent(JSON.stringify(arg.headers)),
|
||||||
|
"risu-url": encodeURIComponent(url),
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
},
|
},
|
||||||
method: method,
|
method: method,
|
||||||
@@ -637,12 +638,13 @@ export async function globalFetch(url:string, arg:{plainFetchForce?:boolean,body
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
const furl = `/proxy2?url=${encodeURIComponent(url)}`
|
const furl = `/proxy2`
|
||||||
|
|
||||||
const da = await fetch(furl, {
|
const da = await fetch(furl, {
|
||||||
body: body,
|
body: body,
|
||||||
headers: {
|
headers: {
|
||||||
"risu-header": encodeURIComponent(JSON.stringify(arg.headers)),
|
"risu-header": encodeURIComponent(JSON.stringify(arg.headers)),
|
||||||
|
"risu-url": encodeURIComponent(url),
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
},
|
},
|
||||||
method: method
|
method: method
|
||||||
|
|||||||
Reference in New Issue
Block a user