Skip to content

Commit

Permalink
feat: add riri's proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
Delusoire committed Jul 1, 2024
1 parent 8d886c5 commit a90cc95
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,59 @@ export const proxy = (
}

const _headers = new Headers();
_headers.set("X-Set-Headers", JSON.stringify(Object.fromEntries(headers.entries())));
_headers.set("X-Set-Headers", JSON.stringify(Object.fromEntries(headers)));

init.headers = _headers;

if (input instanceof Request) {
// @ts-ignore
input.duplex = "half";
}

const request = new Request(url, input instanceof Request ? input : undefined);
return [request, init];
};

export const proxy2 = (
input: RequestInfo | URL,
init: RequestInit = {},
): [Request, RequestInit] => {
let url: URL | string;
if (typeof input === "string") {
url = new URL(input);
} else if (input instanceof Request) {
url = new URL(input.url);
} else if (input instanceof URL) {
url = input;
} else {
throw "Unsupported input type";
}
url = `https://cors-proxy.spicetify.app/${url}`;

let headers: Headers;
if (init.headers) {
headers = new Headers(init.headers);
} else if (input instanceof Request) {
headers = input.headers;
} else {
headers = new Headers();
}

const _headers = new Headers();
for (
const [kp, k] of [
["X-Cookie", "Cookie"],
["X-Referer", "Referer"],
["X-Origin", "Origin"],
["X-User-Agent", "User-Agent"],
["X-X-Real-Ip", "X-Real-Ip"],
]
) {
const v = headers.get(k);
if (v) {
_headers.set(kp, v);
}
}

init.headers = _headers;

Expand Down

0 comments on commit a90cc95

Please sign in to comment.