RED-3845: fix file caching
This commit is contained in:
parent
a34fb20caf
commit
df29bd91d7
@ -1,5 +1,5 @@
|
|||||||
import { Injectable, Injector } from '@angular/core';
|
import { Injectable, Injector } from '@angular/core';
|
||||||
import { combineLatest, firstValueFrom, from, Observable, pairwise, switchMap } from 'rxjs';
|
import { combineLatest, firstValueFrom, from, Observable, of, pairwise, switchMap } from 'rxjs';
|
||||||
import { Dossier, File } from '@red/domain';
|
import { Dossier, File } from '@red/domain';
|
||||||
import { ActivatedRoute } from '@angular/router';
|
import { ActivatedRoute } from '@angular/router';
|
||||||
import { FilesMapService } from '@services/entity-services/files-map.service';
|
import { FilesMapService } from '@services/entity-services/files-map.service';
|
||||||
@ -69,7 +69,7 @@ export class FilePreviewStateService {
|
|||||||
startWith(undefined),
|
startWith(undefined),
|
||||||
pairwise(),
|
pairwise(),
|
||||||
filter(([oldFile, newFile]) => oldFile?.cacheIdentifier !== newFile.cacheIdentifier),
|
filter(([oldFile, newFile]) => oldFile?.cacheIdentifier !== newFile.cacheIdentifier),
|
||||||
switchMap(([, newFile]) => this.#downloadOriginalFile(newFile.cacheIdentifier)),
|
switchMap(([oldFile, newFile]) => this.#downloadOriginalFile(newFile.cacheIdentifier, !!oldFile?.cacheIdentifier)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,8 +80,9 @@ export class FilePreviewStateService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#downloadOriginalFile(cacheIdentifier?: string): Observable<Blob> {
|
#downloadOriginalFile(cacheIdentifier: string, wipeCaches = true): Observable<Blob> {
|
||||||
const downloadFile = this._fileManagementService.downloadOriginalFile(this.dossierId, this.fileId, 'body', cacheIdentifier);
|
const downloadFile = this._fileManagementService.downloadOriginalFile(this.dossierId, this.fileId, 'body', cacheIdentifier);
|
||||||
return from(wipeFilesCache()).pipe(switchMap(() => downloadFile));
|
const obs = wipeCaches ? from(wipeFilesCache()) : of({});
|
||||||
|
return obs.pipe(switchMap(() => downloadFile));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user