fix file upload progress bar

master
Niko PLP 4 months ago
parent 44fd445f4d
commit dc4cf5ae13
  1. 2
      ng-app/src/apps/automerge/ADate.svelte
  2. 78
      ng-app/src/lib/panes/Files.svelte

@ -36,7 +36,7 @@
const change = (event) => { const change = (event) => {
let newval = new Date(date.split('/').reverse().join('/')+" "+time); let newval = new Date(date.split('/').reverse().join('/')+" "+time);
console.log(time, date, newval) //console.log(time, date, newval)
dispatch('updateScalar', { dispatch('updateScalar', {
v: newval, v: newval,

@ -65,7 +65,7 @@
} }
function uploadFile(upload_id, nuri, file, success) { function uploadFile(upload_id, nuri, file, success) {
console.log(nuri); //console.log(nuri);
let chunkSize = 1_048_564; let chunkSize = 1_048_564;
let fileSize = file.size; let fileSize = file.size;
let offset = 0; let offset = 0;
@ -76,50 +76,48 @@
let result = event.target.result; let result = event.target.result;
if (event.target.error == null) { if (event.target.error == null) {
offset += result.byteLength; offset += result.byteLength;
upload_progress = { total: fileSize, current: offset }; upload_progress = { total: fileSize, current: offset };
// console.log("chunk", result); // console.log("chunk", result);
let res = await ng.upload_chunk( let res = await ng.upload_chunk(
$active_session.session_id, $active_session.session_id,
upload_id, upload_id,
result, result,
nuri nuri
); );
//console.log("chunk upload res", res); //console.log("chunk upload res", res);
// if (onChunkRead) { // if (onChunkRead) {
// onChunkRead(result); // onChunkRead(result);
// } // }
} else { } else {
// if (onChunkError) { // if (onChunkError) {
// onChunkError(event.target.error); // onChunkError(event.target.error);
// } // }
return; upload_progress = { total: fileSize, current: fileSize, error: true };
return;
} }
// If finished: // If finished:
if (offset >= fileSize) { if (offset >= fileSize) {
//console.log("file uploaded"); //console.log("file uploaded");
let res = await ng.upload_chunk( let res = await ng.upload_chunk(
$active_session.session_id, $active_session.session_id,
upload_id, upload_id,
[], [],
nuri nuri
); );
//console.log("end upload res", res); //console.log("end upload res", res);
if (success) { if (success) {
upload_progress = { total: fileSize, current: fileSize }; upload_progress = { total: fileSize, current: fileSize };
success(res); await success(res);
} else { // Make progress bar disappear
upload_progress = { total: fileSize, current: fileSize, error: true }; setTimeout(() => {
} upload_progress = null;
}, 1_000);
// Make progress bar disappear }
setTimeout(() => { return;
upload_progress = null;
}, 1_000);
return;
} }
readBlock(offset, chunkSize, file); readBlock(offset, chunkSize, file);

Loading…
Cancel
Save