[ACS-9406] Add getContentRenditionTypePreview to process-content service (#10743)

* [ACS-9406] Add getContentRenditionTypePreview to process-content service

* [ACS-9406] remove extra space

* [ACS-9406] fix unit tests

* [ACS-9406] fix unit tests

* [ACS-9406] cr fixes
This commit is contained in:
Mykyta Maliarchuk
2025-04-02 14:07:20 +02:00
committed by GitHub
parent c85245b241
commit 8e0ea373f0
14 changed files with 119 additions and 10 deletions

View File

@@ -16,7 +16,6 @@
*/
import { TestBed } from '@angular/core/testing';
import { of } from 'rxjs';
import { ProcessContentService } from './process-content.service';
import { CoreTestingModule } from '@alfresco/adf-core';
import { AlfrescoApiService, AlfrescoApiServiceMock } from '@alfresco/adf-content-services';
@@ -176,10 +175,24 @@ describe('ProcessContentService', () => {
});
it('should return a Blob as thumbnail', (done) => {
const contentId: number = 999;
const blob = createFakeBlob();
spyOn(service, 'getContentThumbnail').and.returnValue(of(blob));
const contentId = 999;
spyOn(service.contentApi, 'getRawContent').and.returnValue(Promise.resolve(createFakeBlob()));
service.getContentThumbnail(contentId).subscribe((result) => {
expect(service.contentApi.getRawContent).toHaveBeenCalledWith(contentId, 'thumbnail');
expect(result).toEqual(jasmine.any(Blob));
expect(result.size).toEqual(48);
expect(result.type).toEqual('image/png');
done();
});
});
it('should return a Blob as preview', (done) => {
const contentId = 999;
spyOn(service.contentApi, 'getRawContent').and.returnValue(Promise.resolve(createFakeBlob()));
service.getContentRenditionTypePreview(contentId).subscribe((result) => {
expect(service.contentApi.getRawContent).toHaveBeenCalledWith(contentId, 'preview');
expect(result).toEqual(jasmine.any(Blob));
expect(result.size).toEqual(48);
expect(result.type).toEqual('image/png');

View File

@@ -120,6 +120,16 @@ export class ProcessContentService {
return from(this.contentApi.getRawContent(contentId, 'thumbnail')).pipe(catchError((err) => this.handleError(err)));
}
/**
* Gets the preview rendition for a related content file.
*
* @param contentId ID of the related content
* @returns Binary data of the related content
*/
getContentRenditionTypePreview(contentId: number): Observable<Blob> {
return from(this.contentApi.getRawContent(contentId, 'preview')).pipe(catchError((err) => this.handleError(err)));
}
/**
* Gets related content items for a task instance.
*

View File

@@ -112,7 +112,7 @@ export class ContentWidgetComponent implements OnChanges {
}
openViewer(content: ContentLinkModel): void {
let fetch = this.processContentService.getContentPreview(content.id);
let fetch = this.processContentService.getContentRenditionTypePreview(content.id);
if (content.isTypeImage() || content.isTypePdf()) {
fetch = this.processContentService.getFileRawContent(content.id);
}