🐛 Fix upload modal status for pause/resume (#849)
This commit is contained in:
@@ -609,62 +609,29 @@ class FileUploadService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public pauseOrResume() {
|
public pauseOrResume() {
|
||||||
// pause or resume the curent upload task
|
const isPausing = this.uploadStatus === UploadStateEnum.Progress;
|
||||||
switch (this.uploadStatus) {
|
this.uploadStatus = isPausing ? UploadStateEnum.Paused : UploadStateEnum.Progress;
|
||||||
case UploadStateEnum.Progress:
|
|
||||||
this.uploadStatus = UploadStateEnum.Paused;
|
|
||||||
break;
|
|
||||||
case UploadStateEnum.Paused:
|
|
||||||
this.uploadStatus = UploadStateEnum.Progress;
|
|
||||||
break;
|
|
||||||
case UploadStateEnum.Cancelled:
|
|
||||||
throw new Error('Cannot toggle upload status: Upload is cancelled.');
|
|
||||||
default:
|
|
||||||
throw new Error(`Unexpected upload status: ${this.uploadStatus}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// pause or resume the resumable tasks
|
// Update root states
|
||||||
const filesToProcess = this.pendingFiles;
|
|
||||||
|
|
||||||
if (!filesToProcess || filesToProcess.length === 0) {
|
|
||||||
console.error(`No files found for id`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const file of filesToProcess) {
|
|
||||||
if (file.status === 'success') continue;
|
|
||||||
this.pauseOrResumeFile(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
// update the status of the roots
|
|
||||||
const roots = Object.keys(this.groupedPendingFiles);
|
const roots = Object.keys(this.groupedPendingFiles);
|
||||||
for (const root of roots) {
|
for (const root of roots) {
|
||||||
// check if the root has completed skip it
|
if (this.rootStates.completed[root]) continue; // Skip completed roots
|
||||||
if (this.rootStates.completed[root]) continue;
|
|
||||||
if (this.uploadStatus === UploadStateEnum.Paused) {
|
if (isPausing) {
|
||||||
this.rootStates.paused[root] = true;
|
if (!this.rootStates.paused[root]) {
|
||||||
|
this.pauseOrResumeRoot(root, true);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.rootStates.paused[root] = false;
|
if (this.rootStates.paused[root]) {
|
||||||
|
this.pauseOrResumeRoot(root, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.notify();
|
this.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
public pauseOrResumeRoot(id: string) {
|
public pauseOrResumeRoot(id: string, ignoreRootCheck?: boolean) {
|
||||||
const completedRoots = Object.keys(this.rootStates.completed);
|
|
||||||
const roots = Object.keys(this.rootSizes);
|
|
||||||
const isOnlyRootInProgress = roots.length - completedRoots.length === 1;
|
|
||||||
|
|
||||||
// Check if this is the only root in progress
|
|
||||||
if (!this.rootStates.completed[id] && isOnlyRootInProgress) {
|
|
||||||
this.uploadStatus =
|
|
||||||
this.uploadStatus === UploadStateEnum.Progress
|
|
||||||
? UploadStateEnum.Paused
|
|
||||||
: UploadStateEnum.Progress;
|
|
||||||
}
|
|
||||||
|
|
||||||
// set the pause status for the root
|
|
||||||
if (Object.keys(this.rootStates.paused).includes(id)) {
|
if (Object.keys(this.rootStates.paused).includes(id)) {
|
||||||
this.rootStates.paused[id] = !this.rootStates.paused[id];
|
this.rootStates.paused[id] = !this.rootStates.paused[id];
|
||||||
} else {
|
} else {
|
||||||
@@ -675,7 +642,7 @@ class FileUploadService {
|
|||||||
const filesToProcess = this.groupedPendingFiles[id];
|
const filesToProcess = this.groupedPendingFiles[id];
|
||||||
|
|
||||||
if (!filesToProcess || filesToProcess.length === 0) {
|
if (!filesToProcess || filesToProcess.length === 0) {
|
||||||
console.error(`No files found for id: ${id}`);
|
logger.error(`No files found for id: ${id}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -687,6 +654,18 @@ class FileUploadService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.notify();
|
this.notify();
|
||||||
|
|
||||||
|
if (!ignoreRootCheck) {
|
||||||
|
// set the root upload status
|
||||||
|
const roots = Object.keys(this.groupedPendingFiles);
|
||||||
|
const isAllPaused = roots.every(root => this.rootStates.paused[root]);
|
||||||
|
if (isAllPaused) {
|
||||||
|
this.uploadStatus = UploadStateEnum.Paused;
|
||||||
|
} else {
|
||||||
|
this.uploadStatus = UploadStateEnum.Progress;
|
||||||
|
}
|
||||||
|
this.notify();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private getResumableInstance({
|
private getResumableInstance({
|
||||||
|
|||||||
Reference in New Issue
Block a user