mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-15 20:17:22 +00:00
fix: Add query support to media upload API methods
This commit is contained in:
@@ -76,6 +76,7 @@ export class MediaApi extends ModuleApi<MediaApiOptions> {
|
|||||||
filename?: string;
|
filename?: string;
|
||||||
path?: TInput;
|
path?: TInput;
|
||||||
_init?: Omit<RequestInit, "body">;
|
_init?: Omit<RequestInit, "body">;
|
||||||
|
query?: Record<string, any>;
|
||||||
},
|
},
|
||||||
): FetchPromise<ResponseObject<T>> {
|
): FetchPromise<ResponseObject<T>> {
|
||||||
const headers = {
|
const headers = {
|
||||||
@@ -102,14 +103,22 @@ export class MediaApi extends ModuleApi<MediaApiOptions> {
|
|||||||
headers,
|
headers,
|
||||||
};
|
};
|
||||||
if (opts?.path) {
|
if (opts?.path) {
|
||||||
return this.post(opts.path, body, init);
|
return this.request<T>(opts.path, opts?.query, {
|
||||||
|
...init,
|
||||||
|
body,
|
||||||
|
method: "POST",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!name || name.length === 0) {
|
if (!name || name.length === 0) {
|
||||||
throw new Error("Invalid filename");
|
throw new Error("Invalid filename");
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.post<T>(opts?.path ?? ["upload", name], body, init);
|
return this.request<T>(opts?.path ?? ["upload", name], opts?.query, {
|
||||||
|
...init,
|
||||||
|
body,
|
||||||
|
method: "POST",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async upload<T extends FileUploadedEventData>(
|
async upload<T extends FileUploadedEventData>(
|
||||||
@@ -119,6 +128,7 @@ export class MediaApi extends ModuleApi<MediaApiOptions> {
|
|||||||
_init?: Omit<RequestInit, "body">;
|
_init?: Omit<RequestInit, "body">;
|
||||||
path?: TInput;
|
path?: TInput;
|
||||||
fetcher?: ApiFetcher;
|
fetcher?: ApiFetcher;
|
||||||
|
query?: Record<string, any>;
|
||||||
} = {},
|
} = {},
|
||||||
) {
|
) {
|
||||||
if (item instanceof Request || typeof item === "string") {
|
if (item instanceof Request || typeof item === "string") {
|
||||||
@@ -155,11 +165,14 @@ export class MediaApi extends ModuleApi<MediaApiOptions> {
|
|||||||
opts?: {
|
opts?: {
|
||||||
_init?: Omit<RequestInit, "body">;
|
_init?: Omit<RequestInit, "body">;
|
||||||
fetcher?: typeof fetch;
|
fetcher?: typeof fetch;
|
||||||
|
overwrite?: boolean;
|
||||||
},
|
},
|
||||||
): Promise<ResponseObject<FileUploadedEventData & { result: DB["media"] }>> {
|
): Promise<ResponseObject<FileUploadedEventData & { result: DB["media"] }>> {
|
||||||
|
const query = opts?.overwrite !== undefined ? { overwrite: opts.overwrite } : undefined;
|
||||||
return this.upload(item, {
|
return this.upload(item, {
|
||||||
...opts,
|
...opts,
|
||||||
path: ["entity", entity, id, field],
|
path: ["entity", entity, id, field],
|
||||||
|
query,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user