From f47ea914159fd3f7ec8e98859a3208b2463b8cb4 Mon Sep 17 00:00:00 2001 From: Thomas Zarebczan Date: Wed, 24 Jul 2019 01:23:35 -0400 Subject: [PATCH] fix: file size and full screen We are still using render media for images, so just adding it to the types makes the f button work. Feel free to remove if you think we aren't using render media for images (they seem to still work after adding that) --- src/ui/component/fileDetails/view.jsx | 22 +++++++++++++++++++ .../component/fileViewer/internal/player.jsx | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/ui/component/fileDetails/view.jsx b/src/ui/component/fileDetails/view.jsx index 67671195a..0e440fa4f 100644 --- a/src/ui/component/fileDetails/view.jsx +++ b/src/ui/component/fileDetails/view.jsx @@ -25,6 +25,9 @@ class FileDetails extends PureComponent { const { description, languages, license } = metadata; const mediaType = contentType || 'unknown'; + const fileSize = metadata.source.size + ? formatBytes(metadata.source.size) + : fileInfo && fileInfo.download_path && formatBytes(fileInfo.written_bytes); let downloadPath = fileInfo && fileInfo.download_path ? path.normalize(fileInfo.download_path) : null; let downloadNote; // If the path is blank, file is not avialable. Create path from name so the folder opens on click. @@ -50,6 +53,13 @@ class FileDetails extends PureComponent { {': '} {mediaType} + {fileSize && ( +
+ {__('File Size')} + {': '} + {fileSize} +
+ )}
{__('Languages')} {': '} @@ -81,5 +91,17 @@ class FileDetails extends PureComponent { ); } } +// move this with other helper functions when we re-use it +function formatBytes(bytes, decimals = 2) { + if (bytes === 0) return '0 Bytes'; + + const k = 1024; + const dm = decimals < 0 ? 0 : decimals; + const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; + + const i = Math.floor(Math.log(bytes) / Math.log(k)); + + return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; +} export default FileDetails; diff --git a/src/ui/component/fileViewer/internal/player.jsx b/src/ui/component/fileViewer/internal/player.jsx index a63a86890..42218743d 100644 --- a/src/ui/component/fileViewer/internal/player.jsx +++ b/src/ui/component/fileViewer/internal/player.jsx @@ -316,7 +316,7 @@ class MediaPlayer extends React.PureComponent { playableType(): boolean { const { mediaType } = this.props; - return ['audio', 'video'].indexOf(mediaType) !== -1; + return ['audio', 'video', 'image'].indexOf(mediaType) !== -1; } isRenderMediaSupported() {