106 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			106 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
import { APIClient } from "./ApiClient";
 | 
						|
 | 
						|
export interface IsoFile {
 | 
						|
  filename: string;
 | 
						|
  size: number;
 | 
						|
}
 | 
						|
 | 
						|
/**
 | 
						|
 * ISO catalog entries
 | 
						|
 */
 | 
						|
export interface ISOCatalogEntry {
 | 
						|
  name: string;
 | 
						|
  url: string;
 | 
						|
  image: string;
 | 
						|
}
 | 
						|
 | 
						|
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}`,
 | 
						|
    });
 | 
						|
  }
 | 
						|
 | 
						|
  /**
 | 
						|
   * Get iso catalog
 | 
						|
   */
 | 
						|
  static async Catalog(): Promise<ISOCatalogEntry[]> {
 | 
						|
    return (
 | 
						|
      await APIClient.exec({
 | 
						|
        method: "GET",
 | 
						|
        uri: "/assets/iso_catalog.json",
 | 
						|
      })
 | 
						|
    ).data;
 | 
						|
  }
 | 
						|
 | 
						|
  /**
 | 
						|
   * Get catalog image URL
 | 
						|
   */
 | 
						|
  static CatalogImageURL(entry: ISOCatalogEntry): string {
 | 
						|
    return APIClient.backendURL() + entry.image;
 | 
						|
  }
 | 
						|
}
 |