Fossil SCM
/chat: when creating download links, append file's extension to the /chat-download/MSGID so that the browser's mime-type guessing can work better (seems to fix inline SVG attachments). Prefer to use an attachment's mimetype, instead of filename, for guessing whether it can be embedded, and enable embedding for all text/ and image/ mimetypes.
Commit
cead9178c8c90076a0e3647d6a486d60f73c528f8c8dca4ce1d016f1a4bbd534
Parent
2bb3c76ad9e78e4…
1 file changed
+9
-6
+9
-6
| --- src/fossil.page.chat.js | ||
| +++ src/fossil.page.chat.js | ||
| @@ -895,15 +895,15 @@ | ||
| 895 | 895 | |
| 896 | 896 | const canEmbedFile = function f(msg){ |
| 897 | 897 | if(!f.$rx){ |
| 898 | 898 | f.$rx = /\.((html?)|(txt))$/i; |
| 899 | 899 | } |
| 900 | - return msg.fname && ( | |
| 901 | - f.$rx.test(msg.fname) | |
| 902 | - || (msg.fmime | |
| 903 | - && msg.fmime.startsWith("image/")) | |
| 904 | - ); | |
| 900 | + if(msg.fmime){ | |
| 901 | + return (msg.fmime.startsWith("text/") | |
| 902 | + || msg.fmime.startsWith("image/")); | |
| 903 | + } | |
| 904 | + return msg.fname && f.$rx.test(msg.fname); | |
| 905 | 905 | }; |
| 906 | 906 | |
| 907 | 907 | cf.prototype = { |
| 908 | 908 | scrollIntoView: function(){ |
| 909 | 909 | this.e.content.scrollIntoView(); |
| @@ -944,11 +944,14 @@ | ||
| 944 | 944 | if( m.xfrom && m.fsize>0 ){ |
| 945 | 945 | if( m.fmime |
| 946 | 946 | && m.fmime.startsWith("image/") |
| 947 | 947 | && Chat.settings.getBool('images-inline',true) |
| 948 | 948 | ){ |
| 949 | - contentTarget.appendChild(D.img("chat-download/" + m.msgid)); | |
| 949 | + const extension = m.fname.split('.').pop(); | |
| 950 | + contentTarget.appendChild(D.img("chat-download/" + m.msgid +( | |
| 951 | + extension ? ('.'+extension) : ''/*So that IMG tag mimetype guessing works*/ | |
| 952 | + ))); | |
| 950 | 953 | ds.hasImage = 1; |
| 951 | 954 | }else{ |
| 952 | 955 | // Add a download link. |
| 953 | 956 | const downloadUri = window.fossil.rootPath+ |
| 954 | 957 | 'chat-download/' + m.msgid+'/'+encodeURIComponent(m.fname); |
| 955 | 958 |
| --- src/fossil.page.chat.js | |
| +++ src/fossil.page.chat.js | |
| @@ -895,15 +895,15 @@ | |
| 895 | |
| 896 | const canEmbedFile = function f(msg){ |
| 897 | if(!f.$rx){ |
| 898 | f.$rx = /\.((html?)|(txt))$/i; |
| 899 | } |
| 900 | return msg.fname && ( |
| 901 | f.$rx.test(msg.fname) |
| 902 | || (msg.fmime |
| 903 | && msg.fmime.startsWith("image/")) |
| 904 | ); |
| 905 | }; |
| 906 | |
| 907 | cf.prototype = { |
| 908 | scrollIntoView: function(){ |
| 909 | this.e.content.scrollIntoView(); |
| @@ -944,11 +944,14 @@ | |
| 944 | if( m.xfrom && m.fsize>0 ){ |
| 945 | if( m.fmime |
| 946 | && m.fmime.startsWith("image/") |
| 947 | && Chat.settings.getBool('images-inline',true) |
| 948 | ){ |
| 949 | contentTarget.appendChild(D.img("chat-download/" + m.msgid)); |
| 950 | ds.hasImage = 1; |
| 951 | }else{ |
| 952 | // Add a download link. |
| 953 | const downloadUri = window.fossil.rootPath+ |
| 954 | 'chat-download/' + m.msgid+'/'+encodeURIComponent(m.fname); |
| 955 |
| --- src/fossil.page.chat.js | |
| +++ src/fossil.page.chat.js | |
| @@ -895,15 +895,15 @@ | |
| 895 | |
| 896 | const canEmbedFile = function f(msg){ |
| 897 | if(!f.$rx){ |
| 898 | f.$rx = /\.((html?)|(txt))$/i; |
| 899 | } |
| 900 | if(msg.fmime){ |
| 901 | return (msg.fmime.startsWith("text/") |
| 902 | || msg.fmime.startsWith("image/")); |
| 903 | } |
| 904 | return msg.fname && f.$rx.test(msg.fname); |
| 905 | }; |
| 906 | |
| 907 | cf.prototype = { |
| 908 | scrollIntoView: function(){ |
| 909 | this.e.content.scrollIntoView(); |
| @@ -944,11 +944,14 @@ | |
| 944 | if( m.xfrom && m.fsize>0 ){ |
| 945 | if( m.fmime |
| 946 | && m.fmime.startsWith("image/") |
| 947 | && Chat.settings.getBool('images-inline',true) |
| 948 | ){ |
| 949 | const extension = m.fname.split('.').pop(); |
| 950 | contentTarget.appendChild(D.img("chat-download/" + m.msgid +( |
| 951 | extension ? ('.'+extension) : ''/*So that IMG tag mimetype guessing works*/ |
| 952 | ))); |
| 953 | ds.hasImage = 1; |
| 954 | }else{ |
| 955 | // Add a download link. |
| 956 | const downloadUri = window.fossil.rootPath+ |
| 957 | 'chat-download/' + m.msgid+'/'+encodeURIComponent(m.fname); |
| 958 |