добавил обновление прошивки из веб морды
This commit is contained in:
@@ -617,10 +617,10 @@
|
||||
|
||||
<h3>Обновление ПО</h3>
|
||||
<label>
|
||||
<span>Порт для CinC</span>
|
||||
<input type="file" accept="application/zip">
|
||||
<span>Файл {{ this.uploadFw.progress !== null ? `(${this.uploadFw.progress}%)` : '' }}</span>
|
||||
<input type="file" accept="application/zip" @change="(e) => { this.uploadFw.filename = e.target.files[0] }">
|
||||
</label>
|
||||
<button class="dangerous-button" @click="settingsUploadUpdate()">Обновить встроенное ПО</button>
|
||||
<button class="dangerous-button" @click="settingsUploadUpdate()">Обновить встроенное ПО <span class="submit-spinner" v-show="submitStatus.firmwareUpload"></span></button>
|
||||
</div>
|
||||
|
||||
<div hidden>
|
||||
@@ -798,6 +798,7 @@
|
||||
network: false,
|
||||
debugSend: false,
|
||||
tcpAccel: false,
|
||||
firmwareUpload: false,
|
||||
},
|
||||
|
||||
stat_rx: {
|
||||
@@ -951,6 +952,11 @@
|
||||
},
|
||||
},
|
||||
|
||||
uploadFw: {
|
||||
progress: null,
|
||||
filename: null
|
||||
},
|
||||
|
||||
testState: false,
|
||||
initState: '',
|
||||
lastUpdateTime: new Date(),
|
||||
@@ -1277,6 +1283,59 @@
|
||||
})
|
||||
},
|
||||
|
||||
async settingsUploadUpdate() {
|
||||
if (!this.uploadFw.filename) {
|
||||
alert('Выберите файл для загрузки');
|
||||
return;
|
||||
}
|
||||
|
||||
async function readFileAsArrayBuffer(fileName) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!fileName) { reject(`Файл не выбран`); return }
|
||||
const reader = new FileReader();
|
||||
reader.onload = (e) => { resolve(reader.result) }
|
||||
reader.onerror = (e) => { reject(e) }
|
||||
reader.readAsArrayBuffer(fileName)
|
||||
})
|
||||
}
|
||||
|
||||
try {
|
||||
this.submitStatus.firmwareUpload = true
|
||||
const blob = await readFileAsArrayBuffer(this.uploadFw.filename)
|
||||
|
||||
const xhr = new XMLHttpRequest();
|
||||
const success = await new Promise((resolve) => {
|
||||
xhr.upload.addEventListener("progress", (event) => {
|
||||
if (event.lengthComputable) {
|
||||
this.uploadFw.progress = Math.round((event.loaded / event.total) * 1000) / 10;
|
||||
console.log("upload progress:", this.uploadFw.progress);
|
||||
}
|
||||
});
|
||||
xhr.addEventListener("loadend", () => {
|
||||
this.uploadFw.progress = 100
|
||||
resolve(xhr.readyState === 4 && xhr.status === 200);
|
||||
});
|
||||
xhr.open("PUT", "/api/firmwareUpdate", true);
|
||||
xhr.setRequestHeader("Content-Type", "application/octet-stream");
|
||||
xhr.send(blob);
|
||||
});
|
||||
console.log("success:", success);
|
||||
// const result = await fetch('', {
|
||||
// method: 'POST',
|
||||
// body: await readFileAsArrayBuffer(this.uploadFw.filename),
|
||||
// headers: {
|
||||
// 'Content-Type': 'application/zip',
|
||||
// },
|
||||
// onuploadprogress: (progressEvent) => {
|
||||
// this.uploadFw.progress = Math.round((progressEvent.loaded / progressEvent.total) * 100);
|
||||
// },
|
||||
// })
|
||||
} catch (e) {
|
||||
alert(`Ошибка загрузки файла: ${e}`);
|
||||
}
|
||||
this.submitStatus.firmwareUpload = false
|
||||
},
|
||||
|
||||
performUpdateSettings(reloadParts) {
|
||||
const doFetchSettings = async () => {
|
||||
let d = await fetch("/api/get/settings")
|
||||
|
Reference in New Issue
Block a user