mirror of
https://github.com/movie-web/movie-web.git
synced 2024-12-28 14:11:51 +01:00
cleanup
This commit is contained in:
parent
f9a70b196b
commit
ad8c6709a1
@ -15,25 +15,16 @@ export type ExtensionHelloResponse = ExtensionBaseResponse<{
|
|||||||
hasPermission: boolean;
|
hasPermission: boolean;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
export type ExtensionMakeRequestBody =
|
|
||||||
| {
|
|
||||||
bodyType: "string";
|
|
||||||
value: string;
|
|
||||||
}
|
|
||||||
| {
|
|
||||||
bodyType: "FormData" | "URLSearchParams" | "object";
|
|
||||||
value: Record<string, any>;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type ExtensionMakeRequestBodyType = ExtensionMakeRequestBody["bodyType"];
|
|
||||||
|
|
||||||
export interface ExtensionMakeRequest extends ExtensionBaseRequest {
|
export interface ExtensionMakeRequest extends ExtensionBaseRequest {
|
||||||
url: string;
|
url: string;
|
||||||
method: string;
|
method: string;
|
||||||
headers?: Record<string, string>;
|
headers?: Record<string, string>;
|
||||||
body?: ExtensionMakeRequestBody;
|
body?: string | Record<string, any>;
|
||||||
|
bodyType?: "string" | "FormData" | "URLSearchParams" | "object";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type ExtensionMakeRequestBodyType = ExtensionMakeRequest["bodyType"];
|
||||||
|
|
||||||
export type ExtensionMakeRequestResponse<T> = ExtensionBaseResponse<{
|
export type ExtensionMakeRequestResponse<T> = ExtensionBaseResponse<{
|
||||||
response: {
|
response: {
|
||||||
statusCode: number;
|
statusCode: number;
|
||||||
|
@ -7,7 +7,7 @@ export function getBodyTypeFromBody(
|
|||||||
if (body instanceof FormData) return "FormData";
|
if (body instanceof FormData) return "FormData";
|
||||||
if (body instanceof URLSearchParams) return "URLSearchParams";
|
if (body instanceof URLSearchParams) return "URLSearchParams";
|
||||||
if (typeof body === "object") return "object";
|
if (typeof body === "object") return "object";
|
||||||
return "string";
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function convertBodyToObject(body: unknown): any {
|
export function convertBodyToObject(body: unknown): any {
|
||||||
|
@ -69,14 +69,11 @@ function makeFinalHeaders(
|
|||||||
|
|
||||||
export function makeExtensionFetcher() {
|
export function makeExtensionFetcher() {
|
||||||
const fetcher: Fetcher = async (url, ops) => {
|
const fetcher: Fetcher = async (url, ops) => {
|
||||||
const opsWithoutBody = { ...ops, body: undefined };
|
|
||||||
const result = await sendExtensionRequest<any>({
|
const result = await sendExtensionRequest<any>({
|
||||||
url,
|
url,
|
||||||
...opsWithoutBody,
|
...ops,
|
||||||
...(ops.body && {
|
body: convertBodyToObject(ops.body),
|
||||||
body: convertBodyToObject(ops.body),
|
bodyType: getBodyTypeFromBody(ops.body),
|
||||||
bodyType: getBodyTypeFromBody(ops.body),
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
if (!result?.success) throw new Error(`extension error: ${result?.error}`);
|
if (!result?.success) throw new Error(`extension error: ${result?.error}`);
|
||||||
const res = result.response;
|
const res = result.response;
|
||||||
|
Loading…
Reference in New Issue
Block a user