support for explicit viewer type for URL (#2688)

This commit is contained in:
Denys Vuika
2017-12-04 09:49:03 +00:00
committed by Eugenio Romano
parent dc213adf55
commit 6c8ed9eae0
2 changed files with 14 additions and 3 deletions

View File

@@ -54,6 +54,9 @@ export class ViewerComponent implements OnChanges {
@Input()
urlFile = '';
@Input()
urlFileViewer: string = null;
@Input()
blobFile: Blob;
@@ -176,7 +179,7 @@ export class ViewerComponent implements OnChanges {
this.downloadUrl = this.urlFile;
this.fileName = this.displayName;
this.viewerType = this.getViewerTypeByExtension(this.extension);
this.viewerType = this.urlFileViewer || this.getViewerTypeByExtension(this.extension);
if (this.viewerType === 'unknown') {
this.viewerType = this.getViewerTypeByMimeType(this.mimeType);
}
@@ -328,13 +331,20 @@ export class ViewerComponent implements OnChanges {
}
/**
* Get the token from the local storage
* Get file extension from the string.
* Supports the URL formats like:
* http://localhost/test.jpg?cache=1000
* http://localhost/test.jpg#cache=1000
*
* @param {string} fileName - file name
* @returns {string} file name extension
*/
getFileExtension(fileName: string): string {
return fileName.split('.').pop().toLowerCase();
if (fileName) {
const match = fileName.match(/\.([^\./\?\#]+)($|\?|\#)/);
return match ? match[1] : null;
}
return null;
}
isCustomViewerExtension(extension: string): boolean {