fallback to image preview if PDF rendition now available (#2827)

This commit is contained in:
Denys Vuika
2018-01-12 20:02:05 +00:00
committed by Eugenio Romano
parent 713e4bb33b
commit e97a6de792
3 changed files with 48 additions and 50 deletions

View File

@@ -118,6 +118,6 @@
"rimraf": "^2.6.2", "rimraf": "^2.6.2",
"ts-node": "~3.2.0", "ts-node": "~3.2.0",
"tslint": "^5.7.0", "tslint": "^5.7.0",
"typescript": "~2.4.2" "typescript": "2.6.2"
} }
} }

View File

@@ -71,7 +71,7 @@ export class RenditionsService {
} }
getRenditionUrl(nodeId: string, encoding: string): string { 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<RenditionEntry> { getRendition(nodeId: string, encoding: string): Observable<RenditionEntry> {

View File

@@ -219,7 +219,7 @@ export class ViewerComponent implements OnChanges {
} }
if (this.viewerType === 'unknown') { if (this.viewerType === 'unknown') {
this.displayNodeAsPdf(data.id); this.displayNodeRendition(data.id);
} else { } else {
this.isLoading = false; this.isLoading = false;
} }
@@ -253,7 +253,7 @@ export class ViewerComponent implements OnChanges {
} }
if (this.viewerType === 'unknown') { if (this.viewerType === 'unknown') {
this.displaySharedLinkAsPdf(this.sharedLinkId); this.displaySharedLinkRendition(this.sharedLinkId);
} else { } else {
this.isLoading = false; 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.isLoading = true;
this.renditionService.getRendition(nodeId, 'pdf').subscribe( try {
(response) => { const rendition = await this.apiService.renditionsApi.getRendition(nodeId, 'pdf');
const status = response.entry.status.toString(); const status = rendition.entry.status.toString();
if (status === 'CREATED') { if (status === 'CREATED') {
this.isLoading = false; this.viewerType = 'pdf';
this.showPdfRendition(nodeId); this.urlFileContent = this.apiService.contentApi.getRenditionUrl(nodeId, 'pdf');
} else if (status === 'NOT_CREATED') { } else if (status === 'NOT_CREATED') {
this.renditionService.convert(nodeId, 'pdf').subscribe({ try {
complete: () => { await this.renditionService.convert(nodeId, 'pdf').toPromise()
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;
this.viewerType = 'pdf'; this.viewerType = 'pdf';
this.urlFileContent = this.apiService.contentApi.getSharedLinkRenditionUrl(sharedId, 'pdf'); this.urlFileContent = this.apiService.contentApi.getRenditionUrl(nodeId, 'pdf');
} else { } catch {
this.isLoading = false;
} }
},
(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) { private async displaySharedLinkRendition(sharedId: string) {
if (nodeId) { this.isLoading = true;
this.viewerType = 'pdf';
this.urlFileContent = this.renditionService.getRenditionUrl(nodeId, 'pdf'); 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;
} }
} }