From abca324a67cbd01195a56f8717a350c34c620258 Mon Sep 17 00:00:00 2001 From: Empire Phoenix Date: Wed, 18 Mar 2026 01:42:37 +0100 Subject: [PATCH] fix website --- .../MainBoard/rust/src_webpack/src/main.ts | 98 ++++++------------- 1 file changed, 31 insertions(+), 67 deletions(-) diff --git a/Software/MainBoard/rust/src_webpack/src/main.ts b/Software/MainBoard/rust/src_webpack/src/main.ts index e296b17..eb90312 100644 --- a/Software/MainBoard/rust/src_webpack/src/main.ts +++ b/Software/MainBoard/rust/src_webpack/src/main.ts @@ -191,72 +191,36 @@ export class Controller { } uploadNewFirmware(file: File) { - const reader = new FileReader(); - reader.onload = () => { - const arrayBuffer = reader.result as ArrayBuffer; - const data = new Uint8Array(arrayBuffer); - const crc = this.crc32(data); - const size = data.length; - - console.log("Uploading new firmware with size " + size + " and crc " + crc + "") - - const payload = new Uint8Array(size + 8); - const view = new DataView(payload.buffer); - view.setUint32(0, size, true); - view.setUint32(4, crc, true); - payload.set(data, 8); - - let current = 0; - let max = 100; + let current = 0; + let max = 100; + controller.progressview.addProgress("ota_upload", (current / max) * 100, "Uploading firmeware (" + current + "/" + max + ")") + const ajax = new XMLHttpRequest(); + ajax.upload.addEventListener("progress", event => { + current = event.loaded / 1000; + max = event.total / 1000; controller.progressview.addProgress("ota_upload", (current / max) * 100, "Uploading firmeware (" + current + "/" + max + ")") - const ajax = new XMLHttpRequest(); - ajax.upload.addEventListener("progress", event => { - current = event.loaded / 1000; - max = event.total / 1000; - controller.progressview.addProgress("ota_upload", (current / max) * 100, "Uploading firmeware (" + current + "/" + max + ")") - }, false); - ajax.addEventListener("load", () => { - controller.progressview.removeProgress("ota_upload") - const status = ajax.status; - if (status >= 200 && status < 300) { - controller.reboot(); - } else { - const statusText = ajax.statusText || ""; - const body = ajax.responseText || ""; - toast.error(`OTA update error (${status}${statusText ? ' ' + statusText : ''}): ${body}`); - } - }, false); - ajax.addEventListener("error", () => { - controller.progressview.removeProgress("ota_upload") - toast.error("OTA upload failed due to a network error."); - }, false); - ajax.addEventListener("abort", () => { - controller.progressview.removeProgress("ota_upload") - toast.error("OTA upload was aborted."); - }, false); - ajax.open("POST", PUBLIC_URL + "/ota"); - ajax.send(payload); - }; - reader.onerror = () => { - toast.error("Error reading firmware file."); - }; - reader.readAsArrayBuffer(file); - } - - private crc32(data: Uint8Array): number { - let crc = 0xFFFFFFFF; - for (let i = 0; i < data.length; i++) { - let byte = data[i]; - crc ^= byte; - for (let j = 0; j < 8; j++) { - if (crc & 1) { - crc = (crc >>> 1) ^ 0xEDB88320; - } else { - crc = crc >>> 1; - } + }, false); + ajax.addEventListener("load", () => { + controller.progressview.removeProgress("ota_upload") + const status = ajax.status; + if (status >= 200 && status < 300) { + controller.reboot(); + } else { + const statusText = ajax.statusText || ""; + const body = ajax.responseText || ""; + toast.error(`OTA update error (${status}${statusText ? ' ' + statusText : ''}): ${body}`); } - } - return (crc ^ 0xFFFFFFFF) >>> 0; + }, false); + ajax.addEventListener("error", () => { + controller.progressview.removeProgress("ota_upload") + toast.error("OTA upload failed due to a network error."); + }, false); + ajax.addEventListener("abort", () => { + controller.progressview.removeProgress("ota_upload") + toast.error("OTA upload was aborted."); + }, false); + ajax.open("POST", PUBLIC_URL + "/ota"); + ajax.send(file); } async version(): Promise { @@ -415,9 +379,9 @@ export class Controller { var pretty = JSON.stringify(detection, undefined, 1); - fetch(PUBLIC_URL + "/detect_sensors", { method: "POST", body: pretty }) + fetch(PUBLIC_URL + "/detect_sensors", {method: "POST", body: pretty}) .then(response => response.json()) - .then (json => json as Detection) + .then(json => json as Detection) .then(json => { clearTimeout(timerId); controller.progressview.removeProgress("detect_sensors"); @@ -568,7 +532,7 @@ export class Controller { private setCanPower(checked: boolean) { var body: CanPower = { - state : checked + state: checked } var pretty = JSON.stringify(body, undefined, 1);