Refactor file-extension checking into utility functions
This commit is contained in:
parent
0c58cb7c48
commit
82239d281f
@ -5,6 +5,7 @@
|
|||||||
- Bugfix. Handler not triggered when submitting MUC password form 2nd time
|
- Bugfix. Handler not triggered when submitting MUC password form 2nd time
|
||||||
- Bugfix. MUC features weren't being refreshed when saving the config form
|
- Bugfix. MUC features weren't being refreshed when saving the config form
|
||||||
- Don't show duplicate notification messages
|
- Don't show duplicate notification messages
|
||||||
|
- New config setting [show_images_inline](https://conversejs.org/docs/html/configuration.html#show-images-inline)
|
||||||
- #537 Render `xmpp:` URI as link
|
- #537 Render `xmpp:` URI as link
|
||||||
- #1062 Collapse multiple join/leave messages into one
|
- #1062 Collapse multiple join/leave messages into one
|
||||||
- #1063 URLs in the topic / subject are not clickable
|
- #1063 URLs in the topic / subject are not clickable
|
||||||
@ -17,6 +18,7 @@
|
|||||||
- #1214 Setting `allow_contact_requests` to `false` has no effect
|
- #1214 Setting `allow_contact_requests` to `false` has no effect
|
||||||
- #1221 Avoid creating a headlines box if we don't have anything to show inside it
|
- #1221 Avoid creating a headlines box if we don't have anything to show inside it
|
||||||
- #1222 Adding a bookmark should prefill the room name
|
- #1222 Adding a bookmark should prefill the room name
|
||||||
|
- #1228 Converse automatically visits links (to try and determine whether they're images to show inline)
|
||||||
|
|
||||||
## 4.0.2 (2018-10-02)
|
## 4.0.2 (2018-10-02)
|
||||||
|
|
||||||
|
71
dist/converse.js
vendored
71
dist/converse.js
vendored
@ -81839,30 +81839,60 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
|
|||||||
};
|
};
|
||||||
|
|
||||||
u.renderFileURL = function (_converse, url) {
|
u.renderFileURL = function (_converse, url) {
|
||||||
const uri = new URI(url),
|
const uri = new URI(url);
|
||||||
filename = uri.filename(),
|
|
||||||
lower_filename = filename.toLowerCase();
|
|
||||||
|
|
||||||
if (!_.includes(["https", "http"], uri.protocol().toLowerCase()) || lower_filename.endsWith('mp3') || lower_filename.endsWith('mp4') || lower_filename.endsWith('ogg') || lower_filename.endsWith('jpg') || lower_filename.endsWith('jpeg') || lower_filename.endsWith('png') || lower_filename.endsWith('gif') || lower_filename.endsWith('m4a') || lower_filename.endsWith('webm') || lower_filename.endsWith('svg')) {
|
if (u.isImageURL(uri) || u.isVideoURL(uri) || u.isAudioURL(uri)) {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
const __ = _converse.__;
|
const __ = _converse.__,
|
||||||
|
filename = uri.filename();
|
||||||
return tpl_file({
|
return tpl_file({
|
||||||
'url': url,
|
'url': url,
|
||||||
'label_download': __('Download file "%1$s"', decodeURI(filename))
|
'label_download': __('Download file "%1$s"', decodeURI(filename))
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
u.isImageURL = function (url) {
|
u.isAudioURL = function (url) {
|
||||||
const uri = new URI(url),
|
if (!(url instanceof URI)) {
|
||||||
filename = uri.filename().toLowerCase();
|
url = new URI(url);
|
||||||
|
}
|
||||||
|
|
||||||
if (!_.includes(["https", "http"], uri.protocol().toLowerCase())) {
|
const filename = url.filename().toLowerCase();
|
||||||
|
|
||||||
|
if (!_.includes(["https", "http"], url.protocol().toLowerCase())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return filename.endsWith('jpg') || filename.endsWith('jpeg') || filename.endsWith('png') || filename.endsWith('gif') || filename.endsWith('svg');
|
return filename.endsWith('.ogg') || filename.endsWith('.mp3') || filename.endsWith('.m4a');
|
||||||
|
};
|
||||||
|
|
||||||
|
u.isVideoURL = function (url) {
|
||||||
|
if (!(url instanceof URI)) {
|
||||||
|
url = new URI(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
const filename = url.filename().toLowerCase();
|
||||||
|
|
||||||
|
if (!_.includes(["https", "http"], url.protocol().toLowerCase())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return filename.endsWith('.mp4') || filename.endsWith('.webm');
|
||||||
|
};
|
||||||
|
|
||||||
|
u.isImageURL = function (url) {
|
||||||
|
if (!(url instanceof URI)) {
|
||||||
|
url = new URI(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
const filename = url.filename().toLowerCase();
|
||||||
|
|
||||||
|
if (!_.includes(["https", "http"], url.protocol().toLowerCase())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return filename.endsWith('.jpg') || filename.endsWith('.jpeg') || filename.endsWith('.png') || filename.endsWith('.gif') || filename.endsWith('.bmp') || filename.endsWith('.tiff') || filename.endsWith('.svg');
|
||||||
};
|
};
|
||||||
|
|
||||||
u.renderImageURL = function (_converse, url) {
|
u.renderImageURL = function (_converse, url) {
|
||||||
@ -81870,9 +81900,10 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
|
|||||||
return u.addHyperlinks(url);
|
return u.addHyperlinks(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (u.isImageURL(url)) {
|
const uri = new URI(url);
|
||||||
const __ = _converse.__,
|
|
||||||
uri = new URI(url);
|
if (u.isImageURL(uri)) {
|
||||||
|
const __ = _converse.__;
|
||||||
return tpl_image({
|
return tpl_image({
|
||||||
'url': url,
|
'url': url,
|
||||||
'label_download': __('Download image "%1$s"', decodeURI(uri.filename()))
|
'label_download': __('Download image "%1$s"', decodeURI(uri.filename()))
|
||||||
@ -81883,9 +81914,10 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
|
|||||||
};
|
};
|
||||||
|
|
||||||
u.renderMovieURL = function (_converse, url) {
|
u.renderMovieURL = function (_converse, url) {
|
||||||
if (url.endsWith('mp4') || url.endsWith('webm')) {
|
const uri = new URI(url);
|
||||||
const __ = _converse.__,
|
|
||||||
uri = new URI(url);
|
if (u.isVideoURL(uri)) {
|
||||||
|
const __ = _converse.__;
|
||||||
return tpl_video({
|
return tpl_video({
|
||||||
'url': url,
|
'url': url,
|
||||||
'label_download': __('Download video file "%1$s"', decodeURI(uri.filename()))
|
'label_download': __('Download video file "%1$s"', decodeURI(uri.filename()))
|
||||||
@ -81896,9 +81928,10 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
|
|||||||
};
|
};
|
||||||
|
|
||||||
u.renderAudioURL = function (_converse, url) {
|
u.renderAudioURL = function (_converse, url) {
|
||||||
if (url.endsWith('mp3') || url.endsWith('m4a') || url.endsWith('ogg')) {
|
const uri = new URI(url);
|
||||||
const __ = _converse.__,
|
|
||||||
uri = new URI(url);
|
if (u.isAudioURL(uri)) {
|
||||||
|
const __ = _converse.__;
|
||||||
return tpl_audio({
|
return tpl_audio({
|
||||||
'url': url,
|
'url': url,
|
||||||
'label_download': __('Download audio file "%1$s"', decodeURI(uri.filename()))
|
'label_download': __('Download audio file "%1$s"', decodeURI(uri.filename()))
|
||||||
|
2
package-lock.json
generated
2
package-lock.json
generated
@ -2252,7 +2252,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"backbone.browserStorage": {
|
"backbone.browserStorage": {
|
||||||
"version": "github:jcbrand/Backbone.browserStorage#7079bf7bf9a43474da1d48e31e3cda6c4a716382",
|
"version": "github:jcbrand/Backbone.browserStorage#78e4a58f7cee10cad6af4fd5f3213331a396aa5a",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"backbone": "1.3.3",
|
"backbone": "1.3.3",
|
||||||
|
@ -318,43 +318,61 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
u.renderFileURL = function (_converse, url) {
|
u.renderFileURL = function (_converse, url) {
|
||||||
const uri = new URI(url),
|
const uri = new URI(url);
|
||||||
filename = uri.filename(),
|
if (u.isImageURL(uri) || u.isVideoURL(uri) || u.isAudioURL(uri)) {
|
||||||
lower_filename = filename.toLowerCase();
|
|
||||||
if (!_.includes(["https", "http"], uri.protocol().toLowerCase()) ||
|
|
||||||
lower_filename.endsWith('mp3') || lower_filename.endsWith('mp4') || lower_filename.endsWith('ogg') ||
|
|
||||||
lower_filename.endsWith('jpg') || lower_filename.endsWith('jpeg') ||
|
|
||||||
lower_filename.endsWith('png') || lower_filename.endsWith('gif') ||
|
|
||||||
lower_filename.endsWith('m4a') || lower_filename.endsWith('webm') ||
|
|
||||||
lower_filename.endsWith('svg')) {
|
|
||||||
|
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
const { __ } = _converse;
|
const { __ } = _converse,
|
||||||
|
filename = uri.filename();
|
||||||
return tpl_file({
|
return tpl_file({
|
||||||
'url': url,
|
'url': url,
|
||||||
'label_download': __('Download file "%1$s"', decodeURI(filename))
|
'label_download': __('Download file "%1$s"', decodeURI(filename))
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
u.isImageURL = function (url) {
|
u.isAudioURL = function (url) {
|
||||||
const uri = new URI(url),
|
if (!(url instanceof URI)) {
|
||||||
filename = uri.filename().toLowerCase();
|
url = new URI(url);
|
||||||
if (!_.includes(["https", "http"], uri.protocol().toLowerCase())) {
|
}
|
||||||
|
const filename = url.filename().toLowerCase();
|
||||||
|
if (!_.includes(["https", "http"], url.protocol().toLowerCase())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return filename.endsWith('jpg') || filename.endsWith('jpeg') ||
|
return filename.endsWith('.ogg') || filename.endsWith('.mp3') || filename.endsWith('.m4a');
|
||||||
filename.endsWith('png') || filename.endsWith('gif') ||
|
}
|
||||||
filename.endsWith('svg');
|
|
||||||
|
u.isVideoURL = function (url) {
|
||||||
|
if (!(url instanceof URI)) {
|
||||||
|
url = new URI(url);
|
||||||
|
}
|
||||||
|
const filename = url.filename().toLowerCase();
|
||||||
|
if (!_.includes(["https", "http"], url.protocol().toLowerCase())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return filename.endsWith('.mp4') || filename.endsWith('.webm');
|
||||||
|
}
|
||||||
|
|
||||||
|
u.isImageURL = function (url) {
|
||||||
|
if (!(url instanceof URI)) {
|
||||||
|
url = new URI(url);
|
||||||
|
}
|
||||||
|
const filename = url.filename().toLowerCase();
|
||||||
|
if (!_.includes(["https", "http"], url.protocol().toLowerCase())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return filename.endsWith('.jpg') || filename.endsWith('.jpeg') ||
|
||||||
|
filename.endsWith('.png') || filename.endsWith('.gif') ||
|
||||||
|
filename.endsWith('.bmp') || filename.endsWith('.tiff') ||
|
||||||
|
filename.endsWith('.svg');
|
||||||
};
|
};
|
||||||
|
|
||||||
u.renderImageURL = function (_converse, url) {
|
u.renderImageURL = function (_converse, url) {
|
||||||
if (!_converse.show_images_inline) {
|
if (!_converse.show_images_inline) {
|
||||||
return u.addHyperlinks(url);
|
return u.addHyperlinks(url);
|
||||||
}
|
}
|
||||||
if (u.isImageURL(url)) {
|
const uri = new URI(url);
|
||||||
const { __ } = _converse,
|
if (u.isImageURL(uri)) {
|
||||||
uri = new URI(url);
|
const { __ } = _converse;
|
||||||
return tpl_image({
|
return tpl_image({
|
||||||
'url': url,
|
'url': url,
|
||||||
'label_download': __('Download image "%1$s"', decodeURI(uri.filename()))
|
'label_download': __('Download image "%1$s"', decodeURI(uri.filename()))
|
||||||
@ -364,9 +382,9 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
u.renderMovieURL = function (_converse, url) {
|
u.renderMovieURL = function (_converse, url) {
|
||||||
if (url.endsWith('mp4') || url.endsWith('webm')) {
|
const uri = new URI(url);
|
||||||
const { __ } = _converse,
|
if (u.isVideoURL(uri)) {
|
||||||
uri = new URI(url);
|
const { __ } = _converse;
|
||||||
return tpl_video({
|
return tpl_video({
|
||||||
'url': url,
|
'url': url,
|
||||||
'label_download': __('Download video file "%1$s"', decodeURI(uri.filename()))
|
'label_download': __('Download video file "%1$s"', decodeURI(uri.filename()))
|
||||||
@ -376,9 +394,9 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
u.renderAudioURL = function (_converse, url) {
|
u.renderAudioURL = function (_converse, url) {
|
||||||
if (url.endsWith('mp3') || url.endsWith('m4a') || url.endsWith('ogg')) {
|
const uri = new URI(url);
|
||||||
const { __ } = _converse,
|
if (u.isAudioURL(uri)) {
|
||||||
uri = new URI(url);
|
const { __ } = _converse;
|
||||||
return tpl_audio({
|
return tpl_audio({
|
||||||
'url': url,
|
'url': url,
|
||||||
'label_download': __('Download audio file "%1$s"', decodeURI(uri.filename()))
|
'label_download': __('Download audio file "%1$s"', decodeURI(uri.filename()))
|
||||||
|
Loading…
Reference in New Issue
Block a user