From 5b603ee0180716c9f3884d04565147cc95332647 Mon Sep 17 00:00:00 2001 From: Vito Date: Fri, 4 Dec 2020 17:29:16 +0000 Subject: [PATCH] [ACA-4202] - caching with version number for the url (#6422) * [ACA-4202] - caching with version number for the url * [ACA-4202] - fixed image caching when file with the same name is versioned Co-authored-by: Vito Albano --- .../components/viewer.component.spec.ts | 20 +++++++++++++++++++ .../viewer/components/viewer.component.ts | 6 +++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/core/viewer/components/viewer.component.spec.ts b/lib/core/viewer/components/viewer.component.spec.ts index f53c582cd6..d1805a0716 100644 --- a/lib/core/viewer/components/viewer.component.spec.ts +++ b/lib/core/viewer/components/viewer.component.spec.ts @@ -376,6 +376,26 @@ describe('ViewerComponent', () => { expect(component.fileTitle).toBe('file2'); })); + it('should append version of the file to the file content URL', fakeAsync(() => { + spyOn(alfrescoApiService.nodesApi, 'getNode').and.returnValue( + Promise.resolve(new NodeEntry({ entry: { name: 'file1', content: {}, properties: { 'cm:versionLabel' : '10'} } })) + ); + spyOn(alfrescoApiService.versionsApi, 'getVersion').and.returnValue(Promise.resolve(undefined)); + + component.nodeId = 'id1'; + component.urlFile = null; + component.displayName = null; + component.blobFile = null; + component.showViewer = true; + + component.versionId = null; + component.ngOnChanges(); + tick(); + + expect(component.fileTitle).toBe('file1'); + expect(component.urlFileContent).toContain('/public/alfresco/versions/1/nodes/id1/content?attachment=false&10'); + })); + it('should change display name every time node\`s version changes', fakeAsync(() => { spyOn(alfrescoApiService.nodesApi, 'getNode').and.returnValue( Promise.resolve(new NodeEntry({ entry: { name: 'node1', content: {} } })) diff --git a/lib/core/viewer/components/viewer.component.ts b/lib/core/viewer/components/viewer.component.ts index d98e600daf..cc7d0721d7 100644 --- a/lib/core/viewer/components/viewer.component.ts +++ b/lib/core/viewer/components/viewer.component.ts @@ -391,9 +391,13 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy { this.fileTitle = this.getDisplayName(versionData ? versionData.name : nodeData.name); + const currentFileVersion = this.nodeEntry?.entry?.properties && this.nodeEntry.entry.properties['cm:versionLabel'] ? + encodeURI(this.nodeEntry?.entry?.properties['cm:versionLabel']) : encodeURI('1.0'); + this.urlFileContent = versionData ? this.apiService.contentApi.getVersionContentUrl(this.nodeId, versionData.id) : this.apiService.contentApi.getContentUrl(this.nodeId); - this.urlFileContent = this.cacheBusterNumber ? this.urlFileContent + '&' + this.cacheBusterNumber : this.urlFileContent; + this.urlFileContent = this.cacheBusterNumber ? this.urlFileContent + '&' + currentFileVersion + '&' + this.cacheBusterNumber : + this.urlFileContent + '&' + currentFileVersion; this.extension = this.getFileExtension(versionData ? versionData.name : nodeData.name);