Fixed device file tab edit save, #3451

This commit is contained in:
Ylian Saint-Hilaire 2022-01-13 18:26:47 -08:00
parent e5ab311a0f
commit a438e18e6d
2 changed files with 88 additions and 48 deletions

View File

@ -5502,6 +5502,25 @@
// Push the next part of the file into the websocket. If dataPriming is true, push more data only if it's not the last block of the file.
function p13uploadNextPart(dataPriming) {
if (uploadFile.xdata) {
var data = uploadFile.xdata, start = uploadFile.xptr;
if (start >= data.byteLength) {
files.sendText(JSON.stringify({ action: 'uploaddone', reqid: uploadFile.xfilePtr }));
} else {
var end = uploadFile.xptr + 16384;
if (end > data.byteLength) { if (dataPriming == true) { return; } end = data.byteLength; }
var dataslice = new Uint8Array(data.slice(start, end))
if ((dataslice[0] == 123) || (dataslice[0] == 0)) {
var datapart = new Uint8Array(end - start + 1);
datapart.set(dataslice, 1); // Add a zero char at the start of the send, this will indicate that it's not a JSON command.
files.send(datapart);
} else {
files.send(dataslice); // The data does not start with 0 or 123 "{" so it can't be confused for JSON.
}
uploadFile.xptr = end;
Q('d2progressBar').value = end;
}
} else if (uploadFile.xfile) {
if (uploadFile.xreader != null) return; // Data reading already in process
if (uploadFile.xptr >= uploadFile.xfile.size) return;
var end = uploadFile.xptr + 16384;
@ -5530,6 +5549,7 @@
};
uploadFile.xreader.readAsArrayBuffer(uploadFile.xfile.slice(uploadFile.xptr, end));
}
}
//
// DEVICE DETAILS

View File

@ -10337,6 +10337,25 @@
// Push the next part of the file into the websocket. If dataPriming is true, push more data only if it's not the last block of the file.
function p13uploadNextPart(dataPriming) {
if (uploadFile.xdata) {
var data = uploadFile.xdata, start = uploadFile.xptr;
if (start >= data.byteLength) {
files.sendText(JSON.stringify({ action: 'uploaddone', reqid: uploadFile.xfilePtr }));
} else {
var end = uploadFile.xptr + 16384;
if (end > data.byteLength) { if (dataPriming == true) { return; } end = data.byteLength; }
var dataslice = new Uint8Array(data.slice(start, end))
if ((dataslice[0] == 123) || (dataslice[0] == 0)) {
var datapart = new Uint8Array(end - start + 1);
datapart.set(dataslice, 1); // Add a zero char at the start of the send, this will indicate that it's not a JSON command.
files.send(datapart);
} else {
files.send(dataslice); // The data does not start with 0 or 123 "{" so it can't be confused for JSON.
}
uploadFile.xptr = end;
Q('d2progressBar').value = end;
}
} else if (uploadFile.xfile) {
if (uploadFile.xreader != null) return; // Data reading already in process
if (uploadFile.xptr >= uploadFile.xfile.size) return;
var end = uploadFile.xptr + 16384;
@ -10365,6 +10384,7 @@
};
uploadFile.xreader.readAsArrayBuffer(uploadFile.xfile.slice(uploadFile.xptr, end));
}
}
//
// DEVICE EVENTS