dld stream

This commit is contained in:
Timo 2021-02-16 17:50:44 +02:00
parent 0f86fd5874
commit dadcc4668d
3 changed files with 7 additions and 23 deletions

View File

@ -4,7 +4,6 @@ import { interval, Observable } from 'rxjs';
import { AppConfigService } from '../app-config/app-config.service'; import { AppConfigService } from '../app-config/app-config.service';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { DialogService } from '../dialogs/dialog.service'; import { DialogService } from '../dialogs/dialog.service';
import { download } from '../utils/file-download-utils';
import { ProjectWrapper } from '../state/model/project.wrapper'; import { ProjectWrapper } from '../state/model/project.wrapper';
import { FileStatusWrapper } from '../screens/file/model/file-status.wrapper'; import { FileStatusWrapper } from '../screens/file/model/file-status.wrapper';
import { mergeMap, tap } from 'rxjs/operators'; import { mergeMap, tap } from 'rxjs/operators';
@ -58,31 +57,12 @@ export class FileDownloadService {
return this._downloadControllerService.getDownloadStatus().pipe( return this._downloadControllerService.getDownloadStatus().pipe(
tap((statusResponse) => { tap((statusResponse) => {
this.downloads = statusResponse.downloadStatus.map((d) => new DownloadStatusWrapper(d)); this.downloads = statusResponse.downloadStatus.map((d) => new DownloadStatusWrapper(d));
this.hasPendingDownloads = !!this.downloads.find((f) => !f.lastDownload); this.hasPendingDownloads = !!this.downloads.find((f) => !f.lastDownload && f.isReady);
}) })
); );
} }
public performDownload(status: DownloadStatusWrapper) { public performDownload(status: DownloadStatusWrapper) {
status.inProgress = true;
this._streamDownloadService.performDownload(status); this._streamDownloadService.performDownload(status);
status.inProgress = false;
this._downloadControllerService
.downloadFile(
{
storageId: status.storageId
},
false,
'response'
)
.subscribe(
(response) => {
download(response, status.filename);
status.inProgress = false;
},
() => {
status.inProgress = false;
}
);
} }
} }

View File

@ -6,7 +6,7 @@ export class DownloadStatusWrapper {
constructor(private _downloadStatus: DownloadStatus) {} constructor(private _downloadStatus: DownloadStatus) {}
get size() { get size() {
let i = this._downloadStatus.fileSize === 0 ? 0 : Math.floor(Math.log(this._downloadStatus.fileSize) / Math.log(1024)); const i = this._downloadStatus.fileSize === 0 ? 0 : Math.floor(Math.log(this._downloadStatus.fileSize) / Math.log(1024));
return (this._downloadStatus.fileSize / Math.pow(1024, i)).toFixed(2) + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i]; return (this._downloadStatus.fileSize / Math.pow(1024, i)).toFixed(2) + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];
} }
@ -34,6 +34,10 @@ export class DownloadStatusWrapper {
return this._downloadStatus.projectId; return this._downloadStatus.projectId;
} }
get isReady() {
return this._downloadStatus.status === 'READY';
}
get status() { get status() {
return this._downloadStatus.status; return this._downloadStatus.status;
} }

View File

@ -93,7 +93,7 @@ export class StreamDownloadService {
window.onbeforeunload = (evt) => { window.onbeforeunload = (evt) => {
if (this._activeDownloadCount > 0) { if (this._activeDownloadCount > 0) {
evt.returnValue = this._translateService.instant('stream-download.abort'); return this._translateService.instant('stream-download.abort');
} }
}; };
} }