Fixed device file tab edit save, #3451

Ylian Saint-Hilaire committed Jan 13, 2022 at 18:26 UTC a438e18e6defdd9c7bce5bb8f378b61ea80318c1
2 files changed +89 -49
views/default-mobile.handlebars
+44 -24
@@ -5502,33 +5502,53 @@
5502
5503 // 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.
5504 function p13uploadNextPart(dataPriming) {
5505 - if (uploadFile.xreader != null) return; // Data reading already in process
5506 - if (uploadFile.xptr >= uploadFile.xfile.size) return;
5507 - var end = uploadFile.xptr + 16384;
5508 - if (end > uploadFile.xfile.size) { if (dataPriming == true) { return; } end = uploadFile.xfile.size; }
5509 - uploadFile.xreader = new FileReader();
5510 - uploadFile.xreader.onerror = function (err) { console.log(err); }
5511 - uploadFile.xreader.onload = function () {
5512 - var data = uploadFile.xreader.result;
5513 - delete uploadFile.xreader;
5514 - if (data == null) return;
5515 - var dataslice = new Uint8Array(data)
5516 - if ((dataslice[0] == 123) || (dataslice[0] == 0)) {
5517 - var datapart = new Uint8Array(data.byteLength + 1);
5518 - datapart.set(dataslice, 1); // Add a zero char at the start of the send, this will indicate that it's not a JSON command.
5519 - files.send(datapart);
5520 - } else {
5521 - files.send(dataslice); // The data does not start with 0 or 123 "{" so it can't be confused for JSON.
5522 - }
5523 - uploadFile.xptr = end;
5524 - Q('d2progressBar').value = end;
5525 - if (uploadFile.xptr >= uploadFile.xfile.size) {
5505 + if (uploadFile.xdata) {
5506 + var data = uploadFile.xdata, start = uploadFile.xptr;
5507 + if (start >= data.byteLength) {
5508 files.sendText(JSON.stringify({ action: 'uploaddone', reqid: uploadFile.xfilePtr }));
5509 } else {
5528 - if (uploadFile.xdataPriming > 0) { uploadFile.xdataPriming--; p13uploadNextPart(true); }
5510 + var end = uploadFile.xptr + 16384;
5511 + if (end > data.byteLength) { if (dataPriming == true) { return; } end = data.byteLength; }
5512 + var dataslice = new Uint8Array(data.slice(start, end))
5513 + if ((dataslice[0] == 123) || (dataslice[0] == 0)) {
5514 + var datapart = new Uint8Array(end - start + 1);
5515 + datapart.set(dataslice, 1); // Add a zero char at the start of the send, this will indicate that it's not a JSON command.
5516 + files.send(datapart);
5517 + } else {
5518 + files.send(dataslice); // The data does not start with 0 or 123 "{" so it can't be confused for JSON.
5519 + }
5520 + uploadFile.xptr = end;
5521 + Q('d2progressBar').value = end;
5522 }
5530 - };
5531 - uploadFile.xreader.readAsArrayBuffer(uploadFile.xfile.slice(uploadFile.xptr, end));
5523 + } else if (uploadFile.xfile) {
5524 + if (uploadFile.xreader != null) return; // Data reading already in process
5525 + if (uploadFile.xptr >= uploadFile.xfile.size) return;
5526 + var end = uploadFile.xptr + 16384;
5527 + if (end > uploadFile.xfile.size) { if (dataPriming == true) { return; } end = uploadFile.xfile.size; }
5528 + uploadFile.xreader = new FileReader();
5529 + uploadFile.xreader.onerror = function (err) { console.log(err); }
5530 + uploadFile.xreader.onload = function () {
5531 + var data = uploadFile.xreader.result;
5532 + delete uploadFile.xreader;
5533 + if (data == null) return;
5534 + var dataslice = new Uint8Array(data)
5535 + if ((dataslice[0] == 123) || (dataslice[0] == 0)) {
5536 + var datapart = new Uint8Array(data.byteLength + 1);
5537 + datapart.set(dataslice, 1); // Add a zero char at the start of the send, this will indicate that it's not a JSON command.
5538 + files.send(datapart);
5539 + } else {
5540 + files.send(dataslice); // The data does not start with 0 or 123 "{" so it can't be confused for JSON.
5541 + }
5542 + uploadFile.xptr = end;
5543 + Q('d2progressBar').value = end;
5544 + if (uploadFile.xptr >= uploadFile.xfile.size) {
5545 + files.sendText(JSON.stringify({ action: 'uploaddone', reqid: uploadFile.xfilePtr }));
5546 + } else {
5547 + if (uploadFile.xdataPriming > 0) { uploadFile.xdataPriming--; p13uploadNextPart(true); }
5548 + }
5549 + };
5550 + uploadFile.xreader.readAsArrayBuffer(uploadFile.xfile.slice(uploadFile.xptr, end));
5551 + }
5552 }
5553
5554 //
views/default.handlebars
+45 -25
@@ -10337,33 +10337,53 @@
10337
10338 // 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.
10339 function p13uploadNextPart(dataPriming) {
10340 - if (uploadFile.xreader != null) return; // Data reading already in process
10341 - if (uploadFile.xptr >= uploadFile.xfile.size) return;
10342 - var end = uploadFile.xptr + 16384;
10343 - if (end > uploadFile.xfile.size) { if (dataPriming == true) { return; } end = uploadFile.xfile.size; }
10344 - uploadFile.xreader = new FileReader();
10345 - uploadFile.xreader.onerror = function (err) { console.log(err); }
10346 - uploadFile.xreader.onload = function () {
10347 - var data = uploadFile.xreader.result;
10348 - delete uploadFile.xreader;
10349 - if (data == null) return;
10350 - var dataslice = new Uint8Array(data)
10351 - if ((dataslice[0] == 123) || (dataslice[0] == 0)) {
10352 - var datapart = new Uint8Array(data.byteLength + 1);
10353 - datapart.set(dataslice, 1); // Add a zero char at the start of the send, this will indicate that it's not a JSON command.
10354 - files.send(datapart);
10355 - } else {
10356 - files.send(dataslice); // The data does not start with 0 or 123 "{" so it can't be confused for JSON.
10357 - }
10358 - uploadFile.xptr = end;
10359 - Q('d2progressBar').value = end;
10360 - if (uploadFile.xptr >= uploadFile.xfile.size) {
10340 + if (uploadFile.xdata) {
10341 + var data = uploadFile.xdata, start = uploadFile.xptr;
10342 + if (start >= data.byteLength) {
10343 files.sendText(JSON.stringify({ action: 'uploaddone', reqid: uploadFile.xfilePtr }));
10344 } else {
10363 - if (uploadFile.xdataPriming > 0) { uploadFile.xdataPriming--; p13uploadNextPart(true); }
10364 - }
10365 - };
10366 - uploadFile.xreader.readAsArrayBuffer(uploadFile.xfile.slice(uploadFile.xptr, end));
10345 + var end = uploadFile.xptr + 16384;
10346 + if (end > data.byteLength) { if (dataPriming == true) { return; } end = data.byteLength; }
10347 + var dataslice = new Uint8Array(data.slice(start, end))
10348 + if ((dataslice[0] == 123) || (dataslice[0] == 0)) {
10349 + var datapart = new Uint8Array(end - start + 1);
10350 + datapart.set(dataslice, 1); // Add a zero char at the start of the send, this will indicate that it's not a JSON command.
10351 + files.send(datapart);
10352 + } else {
10353 + files.send(dataslice); // The data does not start with 0 or 123 "{" so it can't be confused for JSON.
10354 + }
10355 + uploadFile.xptr = end;
10356 + Q('d2progressBar').value = end;
10357 + }
10358 + } else if (uploadFile.xfile) {
10359 + if (uploadFile.xreader != null) return; // Data reading already in process
10360 + if (uploadFile.xptr >= uploadFile.xfile.size) return;
10361 + var end = uploadFile.xptr + 16384;
10362 + if (end > uploadFile.xfile.size) { if (dataPriming == true) { return; } end = uploadFile.xfile.size; }
10363 + uploadFile.xreader = new FileReader();
10364 + uploadFile.xreader.onerror = function (err) { console.log(err); }
10365 + uploadFile.xreader.onload = function () {
10366 + var data = uploadFile.xreader.result;
10367 + delete uploadFile.xreader;
10368 + if (data == null) return;
10369 + var dataslice = new Uint8Array(data)
10370 + if ((dataslice[0] == 123) || (dataslice[0] == 0)) {
10371 + var datapart = new Uint8Array(data.byteLength + 1);
10372 + datapart.set(dataslice, 1); // Add a zero char at the start of the send, this will indicate that it's not a JSON command.
10373 + files.send(datapart);
10374 + } else {
10375 + files.send(dataslice); // The data does not start with 0 or 123 "{" so it can't be confused for JSON.
10376 + }
10377 + uploadFile.xptr = end;
10378 + Q('d2progressBar').value = end;
10379 + if (uploadFile.xptr >= uploadFile.xfile.size) {
10380 + files.sendText(JSON.stringify({ action: 'uploaddone', reqid: uploadFile.xfilePtr }));
10381 + } else {
10382 + if (uploadFile.xdataPriming > 0) { uploadFile.xdataPriming--; p13uploadNextPart(true); }
10383 + }
10384 + };
10385 + uploadFile.xreader.readAsArrayBuffer(uploadFile.xfile.slice(uploadFile.xptr, end));
10386 + }
10387 }
10388
10389 //