mirror of
https://github.com/movie-web/movie-web.git
synced 2024-11-11 00:25:05 +01:00
Merge branch 'dev' into dev
This commit is contained in:
commit
c96c61e085
@ -19,9 +19,12 @@ export interface ExtensionMakeRequest extends ExtensionBaseRequest {
|
||||
url: string;
|
||||
method: string;
|
||||
headers?: Record<string, string>;
|
||||
body?: string | FormData | URLSearchParams | Record<string, any>;
|
||||
body?: string | Record<string, any>;
|
||||
bodyType?: "string" | "FormData" | "URLSearchParams" | "object";
|
||||
}
|
||||
|
||||
export type ExtensionMakeRequestBodyType = ExtensionMakeRequest["bodyType"];
|
||||
|
||||
export type ExtensionMakeRequestResponse<T> = ExtensionBaseResponse<{
|
||||
response: {
|
||||
statusCode: number;
|
||||
|
17
src/backend/extension/request.ts
Normal file
17
src/backend/extension/request.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { ExtensionMakeRequestBodyType } from "./plasmo";
|
||||
|
||||
export function getBodyTypeFromBody(
|
||||
body: unknown,
|
||||
): ExtensionMakeRequestBodyType {
|
||||
if (typeof body === "string") return "string";
|
||||
if (body instanceof FormData) return "FormData";
|
||||
if (body instanceof URLSearchParams) return "URLSearchParams";
|
||||
return "object";
|
||||
}
|
||||
|
||||
export function convertBodyToObject(body: unknown): any {
|
||||
if (body instanceof FormData || body instanceof URLSearchParams) {
|
||||
return [...body];
|
||||
}
|
||||
return body;
|
||||
}
|
@ -4,6 +4,8 @@ import { sendExtensionRequest } from "@/backend/extension/messaging";
|
||||
import { getApiToken, setApiToken } from "@/backend/helpers/providerApi";
|
||||
import { getProviderApiUrls, getProxyUrls } from "@/utils/proxyUrls";
|
||||
|
||||
import { convertBodyToObject, getBodyTypeFromBody } from "../extension/request";
|
||||
|
||||
function makeLoadbalancedList(getter: () => string[]) {
|
||||
let listIndex = -1;
|
||||
return () => {
|
||||
@ -67,10 +69,12 @@ function makeFinalHeaders(
|
||||
|
||||
export function makeExtensionFetcher() {
|
||||
const fetcher: Fetcher = async (url, ops) => {
|
||||
const result = (await sendExtensionRequest<any>({
|
||||
const result = await sendExtensionRequest<any>({
|
||||
url,
|
||||
...ops,
|
||||
})) as any;
|
||||
body: convertBodyToObject(ops.body),
|
||||
bodyType: getBodyTypeFromBody(ops.body),
|
||||
});
|
||||
if (!result?.success) throw new Error(`extension error: ${result?.error}`);
|
||||
const res = result.response;
|
||||
return {
|
||||
|
Loading…
Reference in New Issue
Block a user