Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.downloadHttpRequestSubscribtion = request.subscribe(event => {
// progress
if (event.type === HttpEventType.DownloadProgress) {
this.downloadedMBs = event.loaded / 1024 / 1014
}
// finished
if (event.type === HttpEventType.Response) {
this.createFile(event.body, this.downloadFormat, this.data.index, startDate, endDate);
this.downloadFinish = true
}
});
}
switch (event.type) {
case HttpEventType.Sent:
return `Uploading Files`;
case HttpEventType.UploadProgress:
status = Math.round((100 * event.loaded) / event.total);
this.uploadProgress.next(status);
return `Files are ${status}% uploaded`;
case HttpEventType.DownloadProgress:
status = Math.round((100 * event.loaded) / event.total);
this.downloadProgress.next(status); // NOTE: The Content-Length header must be set on the server to calculate this
return `Files are ${status}% downloaded`;
case HttpEventType.Response:
return (event as HttpResponse).body; // `Done`;
default:
return `Something went wrong`;
}
}
}
private showProgress(evt: HttpEvent) {
switch (evt.type) {
case HttpEventType.Sent:
this.percent.next(5);
break;
case HttpEventType.ResponseHeader:
this.percent.next(10);
break;
case HttpEventType.DownloadProgress:
const kbLoaded = Math.round(evt.loaded / 1024);
console.log(`Download in progress! ${kbLoaded}Kb loaded`);
this.percent.next(15 + 80 * evt.loaded / evt.total);
break;
case HttpEventType.Response: {
this.percent.next(95);
}
}
}
map(event => {
if (event.type === HttpEventType.UploadProgress && progress && event.total) {
const percentDone = Math.round(100 * event.loaded / event.total);
progress.next(percentDone);
} else if (event.type === HttpEventType.Response) {
if (progress) {
progress.next(100);
progress.complete();
}
return event;
}
}),
last()
switchMap(httpEvent => {
if (httpEvent.type === HttpEventType.DownloadProgress) {
this.progress.percentage = Math.round(
50 + 25 * (httpEvent.loaded / httpEvent.total)
);
return empty();
}
if (httpEvent.type === HttpEventType.UploadProgress) {
this.progress.percentage = Math.round(
50 * (httpEvent.loaded / httpEvent.total)
);
return empty();
}
if (httpEvent.type === HttpEventType.Response) {
this.progress.percentage = 75;
this.progress.success = true;
return this.http
.get('/api/item/' + this.item.id + '/logo')
.pipe(
tap(subresponse => {
this.progress.percentage = 100;
this.item.logo = subresponse;
}),
catchError((response, caught) => {
Notify.response(response);
return empty();
})
);
this.imageService.uploadFile(formData).subscribe((res: HttpEvent) => {
if (res.type === HttpEventType.UploadProgress) {
this.uploadProgressValue = res;
} else if (res.type === HttpEventType.Response) {
(event.target as HTMLInputElement).value = '';
this.uploadTarPackageName = file.name;
this.isUploadFileWIP = false;
this.updateFileListAndPreviewInfo();
this.messageService.showAlert('IMAGE.CREATE_IMAGE_UPLOAD_SUCCESS', {view: this.alertView});
}
}, (error: HttpErrorResponse) => {
this.isUploadFileWIP = false;
event => {
if (event.type === HttpEventType.UploadProgress) {
this.collectorApp.tgzLink = Math.round(100 * event.loaded / event.total).toString();
} else if (event.type === HttpEventType.Response) {
this.collectorApp.tgzLink = event.body.toString();
}
});
}
filter(event =>
event.type === HttpEventType.UploadProgress ||
event.type === HttpEventType.Response),
map(event => {
(event: HttpEvent) => {
switch (event.type) {
case HttpEventType.Response:
this.uploadProgress$.next(null);
this.onSuccess(fileAttachment);
return;
case HttpEventType.UploadProgress:
this.uploadProgress$.next(Math.round((event.loaded / event.total) * 100));
return;
}
},
() => this.onUploadFailure(fileAttachment.id)
.subscribe(event => {
expect(event.type).toBe(HttpEventType.Response);
const response = event as HttpResponse;
expect(response.headers.get('authentication-token')).toBeTruthy();
done();
});
});