2024-10-07 22:04:57 +02:00
|
|
|
import { APIClient } from "./ApiClient";
|
|
|
|
|
2024-10-08 21:53:21 +02:00
|
|
|
export interface OTAUpdate {
|
|
|
|
platform: string;
|
|
|
|
version: string;
|
|
|
|
file_size: number;
|
|
|
|
}
|
|
|
|
|
2024-10-07 22:04:57 +02:00
|
|
|
export class OTAAPI {
|
|
|
|
/**
|
|
|
|
* Get the list of supported OTA platforms
|
|
|
|
*/
|
|
|
|
static async SupportedPlatforms(): Promise<Array<string>> {
|
|
|
|
return (
|
|
|
|
await APIClient.exec({
|
|
|
|
method: "GET",
|
|
|
|
uri: "/ota/supported_platforms",
|
|
|
|
})
|
|
|
|
).data;
|
|
|
|
}
|
2024-10-07 22:13:47 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Upload new OTA firwmare
|
|
|
|
*/
|
|
|
|
static async UploadFirmware(
|
|
|
|
platform: string,
|
|
|
|
version: string,
|
|
|
|
firmware: File
|
|
|
|
): Promise<void> {
|
|
|
|
const fd = new FormData();
|
|
|
|
fd.append("firmware", firmware);
|
|
|
|
|
|
|
|
await APIClient.exec({
|
|
|
|
method: "POST",
|
|
|
|
uri: `/ota/${platform}/${version}`,
|
|
|
|
formData: fd,
|
|
|
|
});
|
|
|
|
}
|
2024-10-08 21:53:21 +02:00
|
|
|
|
2024-10-08 22:13:36 +02:00
|
|
|
/**
|
|
|
|
* Get the link to download an OTA update
|
|
|
|
*/
|
|
|
|
static DownloadOTAUpdateURL(platform: string, version: string): string {
|
|
|
|
return APIClient.backendURL() + `/ota/${platform}/${version}`;
|
|
|
|
}
|
|
|
|
|
2024-10-08 21:53:21 +02:00
|
|
|
/**
|
|
|
|
* Get the list of OTA updates
|
|
|
|
*/
|
|
|
|
static async ListOTAUpdates(): Promise<OTAUpdate[]> {
|
|
|
|
return (
|
|
|
|
await APIClient.exec({
|
|
|
|
method: "GET",
|
|
|
|
uri: "/ota",
|
|
|
|
})
|
|
|
|
).data;
|
|
|
|
}
|
2024-10-07 22:04:57 +02:00
|
|
|
}
|