Skip to content

Commit

Permalink
Merge pull request #1938 from julien-louis/fix-download-root-folder
Browse files Browse the repository at this point in the history
Fix download zip empty files + error message
  • Loading branch information
julien-louis authored Nov 2, 2023
2 parents 9b25ad3 + bbbaa9a commit 2692013
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<li>
<label>Status</label>
<span class="right-col">
<progress-bar [progress]="task?.progress" [warning]="task.status == 5"></progress-bar>
<progress-bar [progress]="task?.progress" [warning]="task.status == 5 || task.status == 3"></progress-bar>
<button [disabled]="loading" *ngIf="task.eventType == 'downloadDataset.event' && task?.progress == -1 && browserCompatible" class="alt left-icon normal" (click)="retry()">
<i class="fas fa-download"></i>
Retry
Expand Down
1 change: 1 addition & 0 deletions shanoir-ng-front/src/app/async-tasks/task.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export enum TaskStatus {
ERROR = -1,
DONE = 1,
IN_PROGRESS = 2,
DONE_BUT_WARNING = 3,
QUEUED = 4,
IN_PROGRESS_BUT_WARNING = 5
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@

<!-- display a progress bar -->
<ng-container *ngIf="col.type == 'progress'">
<progress-bar [progress]="vars.render?.progress != undefined ? vars.render?.progress : vars.render" width="100" [warning]="vars.render?.status == 5"></progress-bar>
<progress-bar [progress]="vars.render?.progress != undefined ? vars.render?.progress : vars.render" width="100" [warning]="vars.render?.status == 5 || vars.render?.status == 3"></progress-bar>
</ng-container>
<div *ngIf="colIndex < columnDefs.length - 1" class="resizer" (mousedown)="startDrag(colIndex, refTd, $event, columnDefs)" (mouseup)="stopDrag()"></div>
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@

.body { width: 100%; text-align: left; margin-top: 20px; }
.footer { margin-top: 20px; }
input[type="number"] { width: 52px; }
input[type="number"] { width: 52px; }
.warning { margin-left: 10px; color: var(--color-error); vertical-align: inherit; }
.warning i { margin-right: 2px; }
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ <h2 class="header">Download Datasets</h2>
</span>
</li>
<li>
<label>Unzip datasets</label>
<label>Unzip datasets (slower)</label>
<span class="right-col">
<checkbox formControlName="unzip"></checkbox>
<span class="warning" *ngIf="form.get('unzip').value">
<i class="fas fa-exclamation-triangle"></i>
The unzipping will run on your computer
</span>
</span>
</li>
</ol>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@
* along with this program. If not, see https://www.gnu.org/licenses/gpl-3.0.html
*/

import { formatDate } from '@angular/common';
import { HttpResponse } from '@angular/common/http';
import { ComponentRef, Injectable } from '@angular/core';
import { Observable, Subject, Subscription } from 'rxjs-compat';
import { Task, TaskState, TaskStatus } from 'src/app/async-tasks/task.model';
import { Observable, Subscription } from 'rxjs-compat';
import { take } from 'rxjs/operators';
import { Task, TaskState } from 'src/app/async-tasks/task.model';
import { Dataset } from 'src/app/datasets/shared/dataset.model';
import { DatasetService, Format } from 'src/app/datasets/shared/dataset.service';
import { ServiceLocator } from 'src/app/utils/locator.service';
import { SuperPromise } from 'src/app/utils/super-promise';
import { ConfirmDialogService } from '../components/confirm-dialog/confirm-dialog.service';
import { ConsoleService } from '../console/console.service';
import { NotificationsService } from '../notifications/notifications.service';
import { DownloadSetupAltComponent } from './download-setup-alt/download-setup-alt.component';
import { DownloadSetupComponent, DownloadSetupOptions } from './download-setup/download-setup.component';
import { ConfirmDialogService } from '../components/confirm-dialog/confirm-dialog.service';
import { Queue } from './queue.model';
import { take } from 'rxjs/operators';
import { SuperPromise } from 'src/app/utils/super-promise';
import { DownloadSetupAltComponent } from './download-setup-alt/download-setup-alt.component';
import { ConsoleService } from '../console/console.service';
import { formatDate } from '@angular/common';

declare var JSZip: any;

Expand Down Expand Up @@ -322,15 +322,15 @@ export class MassDownloadService {
report.duration = Date.now() - start;
task.report = JSON.stringify(report, null, 4);
if (report.nbError > 0) {
task.status = -1;
task.status = 3;
const tab: string = '- ';
task.message = 'download failed in ' + report.duration + 'ms.\n'
task.message = (report.nbSuccess > 0 ? 'download partially succeed in ' : 'download failed in ') + report.duration + 'ms.\n'
+ tab + report.nbSuccess + ' datasets were successfully downloaded\n'
+ tab + report.nbError + ' datasets are (at least partially) in error and files could be missing.\n';
JSON.stringify(report);
} else {
task.status = task.status == -1 ? -1 : 1;
task.message = 'download completed in ' + report.duration + 'ms, ' + report.nbSuccess + ' files saved in the selected directory';
task.message = 'download completed in ' + report.duration + 'ms, ' + report.nbSuccess + ' datasets saved in the selected directory';
}

this.notificationService.pushLocalTask(task);
Expand All @@ -355,7 +355,7 @@ export class MassDownloadService {
const filename: string = this.getFilename(httpResponse) || 'dataset_' + id;

// Check ERRORS file in zip
var zip = new JSZip();
var zip: any = new JSZip();
const unzipPromise: Promise<any> = zip.loadAsync(httpResponse.body).then(dataFiles => {
if (dataFiles.files['ERRORS.json']) {
return dataFiles.files['ERRORS.json'].async('string').then(content => {
Expand All @@ -364,28 +364,40 @@ export class MassDownloadService {
report.list[id].error = errorsJson;
report.list[id].errorTime = Date.now();
task.lastUpdate = new Date();
task.message = 'saving dataset n°' + id + ' failed';
task.status = 5;
});
} else {
report.list[id].status = 'SUCCESS';
delete report.list[id].error;
delete report.list[id].errorTime;
task.lastUpdate = new Date();
task.message = '(' + report.nbSuccess + '/' + report.requestedDatasetIds.length + ') dataset n°' + id + ' successfully saved';
}
return dataFiles;
});

if (unzip) {
return unzipPromise.then(data => {
for(let [name, file] of Object.entries(data.files)) {
const path: string = this.buildAcquisitionPath(dataset) + filename.replace('.zip', '') + '/' + name;
this.writeMyFile(path, file, userFolderHandle);
if (data) {
return Promise.all(
Object.entries(data.files)?.map(([name, file]) => {
task.message = 'unzipping file ' + name + ' from dataset n°' + id;
this.notificationService.pushLocalTask(task);
const path: string = this.buildAcquisitionPath(dataset) + filename.replace('.zip', '') + '/' + name;
let type: string;
if (name.endsWith('.json') || name.endsWith('.txt')) type = 'string';
else type = 'blob';
return (file as {async: (string) => Promise<Blob>}).async(type).then(blob => {
task.message = 'saving file ' + name + ' from dataset n°' + id;
this.notificationService.pushLocalTask(task);
return this.writeMyFile(path, blob, userFolderHandle);
});
})
);
}
});
} else {
const path: string = this.buildAcquisitionPath(dataset) + filename;
task.message = 'saving dataset n°' + id;
this.notificationService.pushLocalTask(task);
return Promise.all([unzipPromise, this.writeMyFile(path, blob, userFolderHandle)]).then(() => null);
}
}).catch(reason => {
Expand All @@ -397,8 +409,11 @@ export class MassDownloadService {
task.status = 5;
}).finally(() => {
if (report.list[id].status == 'SUCCESS') {
task.lastUpdate = new Date();
task.message = '(' + report.nbSuccess + '/' + report.requestedDatasetIds.length + ') dataset n°' + id + ' successfully saved';
report.nbSuccess++;
} else if (report.list[id].status == 'ERROR') {
task.message = 'saving dataset n°' + id + ' failed';
report.nbError++;
}
task.report = JSON.stringify(report, null, 4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<div class="sub-menu jobs" [@slideDown]="state.jobsOpened" [@disapearUp]>
<li *ngFor="let task of notificationsService.freshCompletedTasks.concat(notificationsService.tasksInProgress).concat(notificationsService.tasksInWait)" [ngSwitch]="task.eventType" [@.disabled]="task.status == 2 || task.status == 5">
<a routerLink="/task" routerLinkActive="active">
<progress-bar [progress]="task.progress" [width]="50" [warning]="task.status == 5"></progress-bar>
<progress-bar [progress]="task.progress" [width]="50" [warning]="task.status == 5 || task.status == 3"></progress-bar>
<i *ngIf="task.status == 4" class="fa-solid fa-hourglass-half status-icon"></i>
<i *ngIf="task.status == 2" class="fa-solid fa-play status-icon"></i>
<i *ngIf="task.status == 1" class="fa-solid fa-check status-icon"></i>
Expand Down

0 comments on commit 2692013

Please sign in to comment.