]> git.p6c8.net - jirafeau_mojo42.git/commitdiff
[BUGFIX] fix file previewing 95/head
authorJerome Jutteau <jerome@jutteau.fr>
Tue, 18 May 2021 07:15:34 +0000 (09:15 +0200)
committerJerome Jutteau <jerome@jutteau.fr>
Tue, 18 May 2021 07:58:16 +0000 (09:58 +0200)
- avoid previewing text/*
- javascript side more clear

closes #264

Signed-off-by: Jerome Jutteau <jerome@jutteau.fr>
lib/functions.js.php
lib/functions.php

index 71ce17ba0dafdc18a92ae8a022d98677f9f7d6f8..7cf1da8644261a52476a3fcfc880fc33efdac3cb 100644 (file)
@@ -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;
 
         // 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;
          {
             document.getElementById('preview_link').href = preview_link_href;
             document.getElementById('preview_link_text').innerHTML = web_root + preview_link_href;
index f564db61f494287b6901b46f85fe06d96d11c9bd..c831b73e944c29257a367757ad86a79e5a6b03cd 100644 (file)
@@ -509,10 +509,15 @@ function jirafeau_upload($file, $one_time_download, $key, $time, $ip, $crypt, $l
 function jirafeau_is_viewable($mime)
 {
     if (!empty($mime)) {
 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);
         $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;
 }
     }
     return false;
 }

patrick-canterino.de