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.

stephan 2022-01-01 13:09 trunk
Commit cead9178c8c90076a0e3647d6a486d60f73c528f8c8dca4ce1d016f1a4bbd534
1 file changed +9 -6
--- src/fossil.page.chat.js
+++ src/fossil.page.chat.js
@@ -895,15 +895,15 @@
895895
896896
const canEmbedFile = function f(msg){
897897
if(!f.$rx){
898898
f.$rx = /\.((html?)|(txt))$/i;
899899
}
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);
905905
};
906906
907907
cf.prototype = {
908908
scrollIntoView: function(){
909909
this.e.content.scrollIntoView();
@@ -944,11 +944,14 @@
944944
if( m.xfrom && m.fsize>0 ){
945945
if( m.fmime
946946
&& m.fmime.startsWith("image/")
947947
&& Chat.settings.getBool('images-inline',true)
948948
){
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
+ )));
950953
ds.hasImage = 1;
951954
}else{
952955
// Add a download link.
953956
const downloadUri = window.fossil.rootPath+
954957
'chat-download/' + m.msgid+'/'+encodeURIComponent(m.fname);
955958
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button