mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 12:37:20 +00:00
improved typing, renamed functions for clarity
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import type { FileListObject } from "media";
|
||||
import { type BaseModuleApiOptions, ModuleApi, type PrimaryFieldType } from "modules/ModuleApi";
|
||||
import type { FileWithPath } from "ui/elements/media/file-selector";
|
||||
|
||||
@@ -10,34 +11,34 @@ export class MediaApi extends ModuleApi<MediaApiOptions> {
|
||||
};
|
||||
}
|
||||
|
||||
getFiles() {
|
||||
return this.get(["files"]);
|
||||
listFiles() {
|
||||
return this.get<FileListObject[]>(["files"]);
|
||||
}
|
||||
|
||||
getFileResponse(filename: string) {
|
||||
return this.get(["file", filename], undefined, {
|
||||
getFile(filename: string) {
|
||||
return this.get<ReadableStream<Uint8Array>>(["file", filename], undefined, {
|
||||
headers: {
|
||||
Accept: "*/*"
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async getFile(filename: string): Promise<Blob> {
|
||||
const { res } = await this.getFileResponse(filename);
|
||||
if (!res.ok || !res.body) {
|
||||
throw new Error("Failed to fetch file");
|
||||
}
|
||||
return await res.blob();
|
||||
}
|
||||
|
||||
async getFileStream(filename: string): Promise<ReadableStream<Uint8Array>> {
|
||||
const { res } = await this.getFileResponse(filename);
|
||||
const { res } = await this.getFile(filename);
|
||||
if (!res.ok || !res.body) {
|
||||
throw new Error("Failed to fetch file");
|
||||
}
|
||||
return res.body;
|
||||
}
|
||||
|
||||
async download(filename: string): Promise<File> {
|
||||
const { res } = await this.getFile(filename);
|
||||
if (!res.ok || !res.body) {
|
||||
throw new Error("Failed to fetch file");
|
||||
}
|
||||
return (await res.blob()) as File;
|
||||
}
|
||||
|
||||
getFileUploadUrl(file: FileWithPath): string {
|
||||
return this.getUrl(`/upload/${file.path}`);
|
||||
}
|
||||
@@ -52,7 +53,7 @@ export class MediaApi extends ModuleApi<MediaApiOptions> {
|
||||
});
|
||||
}
|
||||
|
||||
uploadFile(body: File | ReadableStream, filename?: string) {
|
||||
protected uploadFile(body: File | ReadableStream, filename?: string) {
|
||||
let type: string = "application/octet-stream";
|
||||
let name: string = filename || "";
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user