file download updates

This commit is contained in:
Timo 2021-02-01 23:20:54 +02:00
parent 92d07a5633
commit af9926adce
3 changed files with 60 additions and 20 deletions

View File

@ -8,17 +8,20 @@ import { download } from '../utils/file-download-utils';
import { ProjectWrapper } from '../state/model/project.wrapper';
import { FileStatusWrapper } from '../screens/file/model/file-status.wrapper';
import { mergeMap, tap } from 'rxjs/operators';
import { DownloadStatusWrapper } from './model/download-status.wrapper';
import { AppStateService } from '../state/app-state.service';
@Injectable({
providedIn: 'root'
})
export class FileDownloadService {
public downloads: DownloadStatus[] = [];
public pendingDownloads: DownloadStatus[] = [];
public downloads: DownloadStatusWrapper[] = [];
public pendingDownloads: DownloadStatusWrapper[] = [];
private inProgressDownloads = new Set<string>();
constructor(
private readonly _applicationRef: ApplicationRef,
private readonly _appStateService: AppStateService,
private readonly _downloadControllerService: DownloadControllerService,
private readonly _translateService: TranslateService,
private readonly _appConfigService: AppConfigService,
@ -48,10 +51,9 @@ export class FileDownloadService {
private _getDownloadStatus() {
return this._downloadControllerService.getDownloadStatus().pipe(
tap((statusResponse) => {
this.downloads = statusResponse.downloadStatus;
this.downloads = statusResponse.downloadStatus.map((d) => new DownloadStatusWrapper(d));
this.downloads.forEach((d) => {
if (!d.lastDownload && d.status === 'READY') {
this.inProgressDownloads.add(d.storageId);
this.performDownload(d);
}
});
@ -61,7 +63,9 @@ export class FileDownloadService {
);
}
public performDownload(status: DownloadStatus) {
public performDownload(status: DownloadStatusWrapper) {
this.inProgressDownloads.add(status.storageId);
status.inProgress = true;
this._downloadControllerService
.downloadFile(
{
@ -70,12 +74,17 @@ export class FileDownloadService {
false,
'response'
)
.subscribe((response) => {
download(response, status.filename);
console.log('done');
setTimeout(() => {
.subscribe(
(response) => {
download(response, status.filename);
setTimeout(() => {
this.inProgressDownloads.delete(status.storageId);
}, 1000);
},
() => {
this.inProgressDownloads.delete(status.storageId);
}, 1000);
});
status.inProgress = false;
}
);
}
}

View File

@ -0,0 +1,40 @@
import { DownloadDetails, DownloadStatus } from '@redaction/red-ui-http';
export class DownloadStatusWrapper {
inProgress: boolean;
displayName: string;
constructor(private _downloadStatus: DownloadStatus) {}
get creationDate() {
return this._downloadStatus.creationDate;
}
get downloadDetails(): DownloadDetails {
return this._downloadStatus.downloadDetails;
}
get filename() {
return this._downloadStatus.filename;
}
get lastDownload() {
return this._downloadStatus.lastDownload;
}
get mimeType() {
return this._downloadStatus.mimeType;
}
get projectId() {
return this._downloadStatus.projectId;
}
get status() {
return this._downloadStatus.status;
}
get storageId() {
return this._downloadStatus.storageId;
}
}

View File

@ -1,9 +0,0 @@
import { ProjectWrapper } from '../../state/model/project.wrapper';
export interface ProjectDownloadModel {
fileIds: string[];
project: ProjectWrapper;
completed: boolean;
error: any;
type: 'REDACTED' | 'PREVIEW';
}