From 7595e04dc95abaf4af60ee684e6f563ff7afd1a1 Mon Sep 17 00:00:00 2001 From: Roland Date: Wed, 15 Feb 2023 21:20:23 -0700 Subject: [PATCH] Adding many more FileIcon types. --- app/src/components/Common.js | 18 +++++++++++++++++- app/src/components/FilePreview.js | 4 +++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/src/components/Common.js b/app/src/components/Common.js index 552eaeb9..befaf844 100644 --- a/app/src/components/Common.js +++ b/app/src/components/Common.js @@ -606,6 +606,16 @@ export function mimetypeColor(mimetype) { return 'grey' } +export function isZipMimetype(mimetype) { + return mimetype.startsWith('application/zip') + || mimetype.startsWith('application/zlib') + || mimetype.startsWith('application/x-7z-compressed') + || mimetype.startsWith('application/x-bzip2') + || mimetype.startsWith('application/x-xz') + || mimetype.startsWith('application/gzip') + || mimetype.startsWith('application/x-rar'); +} + export function FileIcon({file, disabled = true, size = 'huge', ...props}) { // Default to a grey file icon. const {mimetype, path} = file; @@ -623,7 +633,9 @@ export function FileIcon({file, disabled = true, size = 'huge', ...props}) { props['name'] = 'image'; } else if (mimetype.startsWith('video/')) { props['name'] = 'film'; - } else if (mimetype.startsWith('application/zip') || mimetype.startsWith('application/zlib') || mimetype.startsWith('application/x-7z-compressed') || mimetype.startsWith('application/x-bzip2') || mimetype.startsWith('application/x-xz')) { + } else if (mimetype.startsWith('message/rfc822')) { + props['name'] = 'mail'; + } else if (isZipMimetype(mimetype)) { props['name'] = 'file archive'; } else if (mimetype.startsWith('application/x-iso9660-image')) { props['name'] = 'dot circle'; @@ -631,8 +643,12 @@ export function FileIcon({file, disabled = true, size = 'huge', ...props}) { props['name'] = 'book'; } else if (mimetype.startsWith('text/vtt') || mimetype.startsWith('text/srt')) { props['name'] = 'closed captioning'; + } else if (mimetype.startsWith('application/octet-stream') && lowerPath.endsWith('.dmg')) { + props['name'] = 'apple'; } else if (mimetype.startsWith('application/octet-stream') && (lowerPath.endsWith('.stl') || lowerPath.endsWith('.blend'))) { props['name'] = 'cube'; + } else if (mimetype.startsWith('application/x-dosexec') || mimetype.startsWith('application/x-msi')) { + props['name'] = 'microsoft'; } } return diff --git a/app/src/components/FilePreview.js b/app/src/components/FilePreview.js index 33a53b34..8224d54f 100644 --- a/app/src/components/FilePreview.js +++ b/app/src/components/FilePreview.js @@ -66,6 +66,8 @@ export const FilePreviewContext = React.createContext({ previewFile: null, setPreviewFile: null, previewModal: null, setPreviewModal: null, }); +const MAXIMUM_TEXT_SIZE = 5_000_000; + export function FilePreviewWrapper({children}) { const [previewFile, setPreviewFile] = React.useState(null); const [previewModal, setPreviewModal] = React.useState(null); @@ -102,7 +104,7 @@ export function FilePreviewWrapper({children}) { console.debug(`useFilePreview path=${previewFile['path']} mimetype=${mimetype}`); const url = getMediaPathURL(previewFile); const downloadURL = getDownloadPathURL(previewFile); - if (mimetype.startsWith('text/') && size >= 10000) { + if (mimetype.startsWith('text/') && size > MAXIMUM_TEXT_SIZE) { // Large text files should be downloaded. window.open(downloadURL); } else if (mimetype.startsWith('text/') || mimetype.startsWith('application/json')) {