From 03f216f58de659215008347947a754096902771e Mon Sep 17 00:00:00 2001 From: Jerome Jutteau Date: Tue, 18 May 2021 09:15:34 +0200 Subject: [PATCH 1/1] [BUGFIX] fix file previewing - avoid previewing text/* - javascript side more clear closes #264 Signed-off-by: Jerome Jutteau --- lib/functions.js.php | 8 ++++---- lib/functions.php | 11 ++++++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/functions.js.php b/lib/functions.js.php index 71ce17b..7cf1da8 100644 --- a/lib/functions.js.php +++ b/lib/functions.js.php @@ -183,10 +183,10 @@ function show_link (reference, delete_code, crypt_key, date) // Test if content can be previewed type = document.getElementById('file_select').files[0].type; - if (type.indexOf("image") > -1 || - type.indexOf("audio") > -1 || - type.indexOf("text") > -1 || - type.indexOf("video") > -1) + if (type.startsWith('image/') || + type.startsWith('audio') || + type.startsWith('text/plain') || + type.startsWith('video/')) { document.getElementById('preview_link').href = preview_link_href; document.getElementById('preview_link_text').innerHTML = web_root + preview_link_href; diff --git a/lib/functions.php b/lib/functions.php index f564db6..c831b73 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -509,10 +509,15 @@ function jirafeau_upload($file, $one_time_download, $key, $time, $ip, $crypt, $l function jirafeau_is_viewable($mime) { if (!empty($mime)) { - /* Actually, verify if mime-type is an image or a text. */ - $viewable = array('image', 'text', 'video', 'audio'); + $viewable = array('image', 'video', 'audio'); $decomposed = explode('/', $mime); - return in_array($decomposed[0], $viewable); + if (in_array($decomposed[0], $viewable)) { + return true; + } + $viewable = array('text/plain'); + if (in_array($mime, $viewable)) { + return true; + } } return false; } -- 2.34.1