feat: enabling web-based OTA updates and deployment for frontend

This commit is contained in:
2026-03-03 16:33:01 -05:00
parent 7c537ed4db
commit eafb705eda
7 changed files with 439 additions and 2 deletions

View File

@@ -37,3 +37,39 @@ export async function reboot() {
}
return res.json();
}
/**
* Fetch OTA status from the ESP32.
* @returns {Promise<{active_slot: number, active_partition: string, target_partition: string}>}
*/
export async function getOTAStatus() {
const res = await fetch(`${API_BASE}/api/ota/status`);
if (!res.ok) {
throw new Error(`HTTP ${res.status}: ${res.statusText}`);
}
return res.json();
}
/**
* Upload a new frontend binary image.
* @param {File} file The binary file to upload.
* @returns {Promise<{status: string, message: string}>}
*/
export async function uploadOTAFrontend(file) {
const res = await fetch(`${API_BASE}/api/ota/frontend`, {
method: 'POST',
body: file, // Send the raw file Blob/Buffer
headers: {
// Let the browser set Content-Type for the binary payload,
// or we could force application/octet-stream.
'Content-Type': 'application/octet-stream'
}
});
if (!res.ok) {
const errorText = await res.text();
throw new Error(`Upload failed (${res.status}): ${errorText || res.statusText}`);
}
return res.json();
}