88 lines
1.8 KiB
TypeScript
88 lines
1.8 KiB
TypeScript
import { APIClient } from "./ApiClient";
|
|
|
|
export interface OTAUpdate {
|
|
platform: string;
|
|
version: string;
|
|
file_size: number;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
/**
|
|
* 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,
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Get the link to download an OTA update
|
|
*/
|
|
static DownloadOTAUpdateURL(update: OTAUpdate): string {
|
|
return APIClient.backendURL() + `/ota/${update.platform}/${update.version}`;
|
|
}
|
|
|
|
/**
|
|
* Delete an update
|
|
*/
|
|
static async DeleteUpdate(update: OTAUpdate): Promise<void> {
|
|
await APIClient.exec({
|
|
method: "DELETE",
|
|
uri: `/ota/${update.platform}/${update.version}`,
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Get the list of OTA updates
|
|
*/
|
|
static async ListOTAUpdates(): Promise<OTAUpdate[]> {
|
|
return (
|
|
await APIClient.exec({
|
|
method: "GET",
|
|
uri: "/ota",
|
|
})
|
|
).data;
|
|
}
|
|
|
|
/**
|
|
* Set desired version for one or mor devices
|
|
*/
|
|
static async SetDesiredVersion(
|
|
update: OTAUpdate,
|
|
all_devices: boolean,
|
|
devices?: string[]
|
|
): Promise<void> {
|
|
await APIClient.exec({
|
|
method: "POST",
|
|
uri: "/ota/set_desired_version",
|
|
jsonData: {
|
|
version: update.version,
|
|
platform: update.platform,
|
|
devices: all_devices ? undefined : devices!,
|
|
},
|
|
});
|
|
}
|
|
}
|