78 lines
1.5 KiB
TypeScript
78 lines
1.5 KiB
TypeScript
import { APIClient } from "./ApiClient";
|
|
|
|
export interface IsoFile {
|
|
filename: string;
|
|
size: number;
|
|
}
|
|
|
|
export class IsoFilesApi {
|
|
/**
|
|
* Upload a new ISO file to the server
|
|
*/
|
|
static async Upload(
|
|
file: File,
|
|
progress: (progress: number) => void
|
|
): Promise<void> {
|
|
const fd = new FormData();
|
|
fd.append("file", file);
|
|
|
|
await APIClient.exec({
|
|
method: "POST",
|
|
uri: "/iso/upload",
|
|
formData: fd,
|
|
upProgress: progress,
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Upload iso from URL
|
|
*/
|
|
static async UploadFromURL(url: string, filename: string): Promise<void> {
|
|
await APIClient.exec({
|
|
method: "POST",
|
|
uri: "/iso/upload_from_url",
|
|
jsonData: { url: url, filename: filename },
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Get iso files list
|
|
*/
|
|
static async GetList(): Promise<IsoFile[]> {
|
|
return (
|
|
await APIClient.exec({
|
|
method: "GET",
|
|
uri: "/iso/list",
|
|
})
|
|
).data;
|
|
}
|
|
|
|
/**
|
|
* Download an ISO file
|
|
*/
|
|
static async Download(
|
|
file: IsoFile,
|
|
progress: (p: number) => void
|
|
): Promise<Blob> {
|
|
return (
|
|
await APIClient.exec({
|
|
method: "GET",
|
|
uri: `/iso/${file.filename}`,
|
|
downProgress(e) {
|
|
progress(Math.floor(100 * (e.progress / e.total)));
|
|
},
|
|
})
|
|
).data;
|
|
}
|
|
|
|
/**
|
|
* Delete iso file
|
|
*/
|
|
static async Delete(file: IsoFile): Promise<void> {
|
|
await APIClient.exec({
|
|
method: "DELETE",
|
|
uri: `/iso/${file.filename}`,
|
|
});
|
|
}
|
|
}
|