From 0d16867d13c788803aaf0aee1460da8df6198300 Mon Sep 17 00:00:00 2001 From: minottic Date: Thu, 1 Feb 2024 13:18:33 +0100 Subject: [PATCH] Get thumbnail using thumbnailHash when avaialable --- scilog/src/app/core/model/logbooks.ts | 1 + scilog/src/app/core/remote-data.service.ts | 4 ++-- .../logbook-cover/logbook-cover.component.spec.ts | 14 ++++++++++++-- .../logbook-cover/logbook-cover.component.ts | 5 ++++- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/scilog/src/app/core/model/logbooks.ts b/scilog/src/app/core/model/logbooks.ts index 3069344c..f5489478 100644 --- a/scilog/src/app/core/model/logbooks.ts +++ b/scilog/src/app/core/model/logbooks.ts @@ -4,6 +4,7 @@ export interface Logbooks extends Basesnippets { name?: string; description?: string; thumbnail?: string; + thumbnailHash?: string; location?: string; readACL?: string[]; updateACL?: string[]; diff --git a/scilog/src/app/core/remote-data.service.ts b/scilog/src/app/core/remote-data.service.ts index 3fdcf1e9..137e4ea1 100644 --- a/scilog/src/app/core/remote-data.service.ts +++ b/scilog/src/app/core/remote-data.service.ts @@ -159,13 +159,13 @@ export class LogbookItemDataService extends RemoteDataService { return this.getSnippets(imageSnippetUrl, { responseType: 'blob' }).toPromise(); } - async getImage(id: string) { + getImage(id: string) { // first retrieve image snippet, then filesnippet and then file // let fileSnippet = await this.getFilesnippet(id); // console.log(fileSnippet) // let headers = new HttpHeaders(); // headers = headers.set('Accept', 'application/json'); - return this.getSnippets("filesnippet/" + id + "/files", { responseType: 'blob' }).toPromise(); + return this.getSnippets("images/" + id, { responseType: 'blob' }).toPromise(); } getFilesnippet(id: string) { diff --git a/scilog/src/app/overview/logbook-cover/logbook-cover.component.spec.ts b/scilog/src/app/overview/logbook-cover/logbook-cover.component.spec.ts index 966eafbc..5bd5bc2a 100644 --- a/scilog/src/app/overview/logbook-cover/logbook-cover.component.spec.ts +++ b/scilog/src/app/overview/logbook-cover/logbook-cover.component.spec.ts @@ -44,7 +44,7 @@ describe('LogbookWidgetComponent', () => { logbookSpy = jasmine.createSpyObj("LogbookInfoService", ["logbookInfo"]); logbookSpy.logbookInfo.and.returnValue([]); - logbookItemDataSpy = jasmine.createSpyObj("LogbookItemDataService", ["getFile"]); + logbookItemDataSpy = jasmine.createSpyObj("LogbookItemDataService", ["getFile", "getImage"]); logbookItemDataSpy.getFile.and.returnValue(of({})); beforeEach(waitForAsync(() => { @@ -72,11 +72,21 @@ describe('LogbookWidgetComponent', () => { expect(component).toBeTruthy(); }); - it('should test enableActions', () => { const isAnyEditAllowedSpy = spyOn(component['isActionAllowed'], 'isAnyEditAllowed'); component['enableActions'](); expect(isAnyEditAllowedSpy).toHaveBeenCalledTimes(1); }); + [undefined, 'hash'].forEach((t, i) => { + it(`should getImageFromService ${i}`, async () => { + logbookItemDataSpy.getImage.calls.reset(); + component.logbook.thumbnail = 'abc' + component.logbook.thumbnailHash = t + spyOn(component, 'createImageFromBlob'); + await component.getImageFromService(); + expect(logbookItemDataSpy.getImage).toHaveBeenCalledOnceWith(t ?? 'abc'); + }); + }); + }); diff --git a/scilog/src/app/overview/logbook-cover/logbook-cover.component.ts b/scilog/src/app/overview/logbook-cover/logbook-cover.component.ts index 8cbd5037..121ab2a9 100644 --- a/scilog/src/app/overview/logbook-cover/logbook-cover.component.ts +++ b/scilog/src/app/overview/logbook-cover/logbook-cover.component.ts @@ -58,7 +58,10 @@ export class LogbookWidgetComponent implements OnInit { async getImageFromService() { this.isImageLoading = true; - let data = await this.logbookItemDataService.getImage(this.logbook.thumbnail); + let data = await this.logbookItemDataService.getImage( + this.logbook.thumbnailHash ?? + this.logbook.thumbnail + ); this.createImageFromBlob(data); this.isImageLoading = false; }