mirror of
https://github.com/movie-web/movie-web.git
synced 2025-01-22 04:31:40 +00:00
add rawProxiedFetch
This commit is contained in:
parent
c7651950ce
commit
bcff5a8972
|
@ -1,4 +1,4 @@
|
||||||
import { ofetch } from "ofetch";
|
import { FetchOptions, FetchResponse, ofetch } from "ofetch";
|
||||||
|
|
||||||
import { conf } from "@/setup/config";
|
import { conf } from "@/setup/config";
|
||||||
|
|
||||||
|
@ -59,3 +59,36 @@ export function proxiedFetch<T>(url: string, ops: P<T>[1] = {}): R<T> {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function rawProxiedFetch<T>(
|
||||||
|
url: string,
|
||||||
|
ops: FetchOptions = {}
|
||||||
|
): Promise<FetchResponse<T>> {
|
||||||
|
let combinedUrl = ops?.baseURL ?? "";
|
||||||
|
if (
|
||||||
|
combinedUrl.length > 0 &&
|
||||||
|
combinedUrl.endsWith("/") &&
|
||||||
|
url.startsWith("/")
|
||||||
|
)
|
||||||
|
combinedUrl += url.slice(1);
|
||||||
|
else if (
|
||||||
|
combinedUrl.length > 0 &&
|
||||||
|
!combinedUrl.endsWith("/") &&
|
||||||
|
!url.startsWith("/")
|
||||||
|
)
|
||||||
|
combinedUrl += `/${url}`;
|
||||||
|
else combinedUrl += url;
|
||||||
|
|
||||||
|
const parsedUrl = new URL(combinedUrl);
|
||||||
|
Object.entries(ops?.params ?? {}).forEach(([k, v]) => {
|
||||||
|
parsedUrl.searchParams.set(k, v);
|
||||||
|
});
|
||||||
|
|
||||||
|
return baseFetch.raw(getProxyUrl(), {
|
||||||
|
...ops,
|
||||||
|
baseURL: undefined,
|
||||||
|
params: {
|
||||||
|
destination: parsedUrl.toString(),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue