46 lines
923 B
TypeScript
46 lines
923 B
TypeScript
import { APIClient } from "./ApiClient";
|
|
|
|
export type DiskImage = {
|
|
file_size: number;
|
|
file_name: string;
|
|
name: string;
|
|
created: number;
|
|
} & (
|
|
| { format: "Raw"; is_sparse: boolean }
|
|
| { format: "QCow2"; virtual_size: number }
|
|
| { format: "CompressedQCow2" }
|
|
| { format: "CompressedRaw" }
|
|
);
|
|
|
|
export class DiskImageApi {
|
|
/**
|
|
* Upload a new disk image 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: "/disk_images/upload",
|
|
formData: fd,
|
|
upProgress: progress,
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Get the list of disk images
|
|
*/
|
|
static async GetList(): Promise<DiskImage[]> {
|
|
return (
|
|
await APIClient.exec({
|
|
method: "GET",
|
|
uri: "/disk_images/list",
|
|
})
|
|
).data;
|
|
}
|
|
}
|