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 { 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 { await APIClient.exec({ method: "POST", uri: "/iso/upload_from_url", jsonData: { url: url, filename: filename }, }); } /** * Get iso files list */ static async GetList(): Promise { return ( await APIClient.exec({ method: "GET", uri: "/iso/list", }) ).data; } /** * Download an ISO file */ static async Download( file: IsoFile, progress: (p: number) => void ): Promise { 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 { await APIClient.exec({ method: "DELETE", uri: `/iso/${file.filename}`, }); } }