diff --git a/demo-shell/package.json b/demo-shell/package.json index 5339ea939e..bd6dafc637 100644 --- a/demo-shell/package.json +++ b/demo-shell/package.json @@ -118,6 +118,6 @@ "rimraf": "^2.6.2", "ts-node": "~3.2.0", "tslint": "^5.7.0", - "typescript": "~2.4.2" + "typescript": "2.6.2" } } diff --git a/lib/core/services/renditions.service.ts b/lib/core/services/renditions.service.ts index 21718b1cb4..3ccc69af02 100644 --- a/lib/core/services/renditions.service.ts +++ b/lib/core/services/renditions.service.ts @@ -71,7 +71,7 @@ export class RenditionsService { } getRenditionUrl(nodeId: string, encoding: string): string { - return this.apiService.contentApi.getRenditionUrl(nodeId, 'pdf'); + return this.apiService.contentApi.getRenditionUrl(nodeId, encoding); } getRendition(nodeId: string, encoding: string): Observable { diff --git a/lib/core/viewer/components/viewer.component.ts b/lib/core/viewer/components/viewer.component.ts index c7c1bdc03c..3273aa619c 100644 --- a/lib/core/viewer/components/viewer.component.ts +++ b/lib/core/viewer/components/viewer.component.ts @@ -219,7 +219,7 @@ export class ViewerComponent implements OnChanges { } if (this.viewerType === 'unknown') { - this.displayNodeAsPdf(data.id); + this.displayNodeRendition(data.id); } else { this.isLoading = false; } @@ -253,7 +253,7 @@ export class ViewerComponent implements OnChanges { } if (this.viewerType === 'unknown') { - this.displaySharedLinkAsPdf(this.sharedLinkId); + this.displaySharedLinkRendition(this.sharedLinkId); } else { this.isLoading = false; } @@ -443,60 +443,58 @@ export class ViewerComponent implements OnChanges { } } - private displayNodeAsPdf(nodeId: string) { + private async displayNodeRendition(nodeId: string) { this.isLoading = true; - this.renditionService.getRendition(nodeId, 'pdf').subscribe( - (response) => { - const status = response.entry.status.toString(); + try { + const rendition = await this.apiService.renditionsApi.getRendition(nodeId, 'pdf'); + const status = rendition.entry.status.toString(); - if (status === 'CREATED') { - this.isLoading = false; - this.showPdfRendition(nodeId); - } else if (status === 'NOT_CREATED') { - this.renditionService.convert(nodeId, 'pdf').subscribe({ - complete: () => { - this.isLoading = false; - this.showPdfRendition(nodeId); - }, - error: (error) => { - this.isLoading = false; - } - }); - } else { - this.isLoading = false; - } - }, - (err) => { - this.isLoading = false; - } - ); - } - - private displaySharedLinkAsPdf(sharedId: string) { - this.isLoading = true; - - this.apiService.renditionsApi.getSharedLinkRendition(sharedId, 'pdf').then( - (response) => { - const status = response.entry.status.toString(); - if (status === 'CREATED') { - this.isLoading = false; + if (status === 'CREATED') { + this.viewerType = 'pdf'; + this.urlFileContent = this.apiService.contentApi.getRenditionUrl(nodeId, 'pdf'); + } else if (status === 'NOT_CREATED') { + try { + await this.renditionService.convert(nodeId, 'pdf').toPromise() this.viewerType = 'pdf'; - this.urlFileContent = this.apiService.contentApi.getSharedLinkRenditionUrl(sharedId, 'pdf'); - } else { - this.isLoading = false; + this.urlFileContent = this.apiService.contentApi.getRenditionUrl(nodeId, 'pdf'); + } catch { } - }, - (err) => { - this.isLoading = false; } - ); + } catch { + try { + const imagePreview = await this.apiService.renditionsApi.getRendition(nodeId, 'imgpreview'); + if (imagePreview.entry.status.toString() === 'CREATED') { + this.viewerType = 'image'; + this.urlFileContent = this.apiService.contentApi.getRenditionUrl(nodeId, 'imgpreview'); + } + } catch { + } + } + + this.isLoading = false; } - private showPdfRendition(nodeId: string) { - if (nodeId) { - this.viewerType = 'pdf'; - this.urlFileContent = this.renditionService.getRenditionUrl(nodeId, 'pdf'); + private async displaySharedLinkRendition(sharedId: string) { + this.isLoading = true; + + try { + const rendition = await this.apiService.renditionsApi.getSharedLinkRendition(sharedId, 'pdf'); + if (rendition.entry.status.toString() === 'CREATED') { + this.viewerType = 'pdf'; + this.urlFileContent = this.apiService.contentApi.getSharedLinkRenditionUrl(sharedId, 'pdf'); + } + } catch { + try { + const rendition = await this.apiService.renditionsApi.getSharedLinkRendition(sharedId, 'imgpreview'); + if (rendition.entry.status.toString() === 'CREATED') { + this.viewerType = 'image'; + this.urlFileContent = this.apiService.contentApi.getSharedLinkRenditionUrl(sharedId, 'imgpreview'); + } + } catch { + } } + + this.isLoading = false; } }