Only attempt loading img URL with filename and appropriate extension
updates #1228
This commit is contained in:
parent
e425f25753
commit
2426f9b7c8
41
dist/converse.js
vendored
41
dist/converse.js
vendored
@ -82094,21 +82094,36 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
|
|||||||
*/
|
*/
|
||||||
const __ = _converse.__;
|
const __ = _converse.__;
|
||||||
const list = obj.textContent.match(URL_REGEX) || [];
|
const list = obj.textContent.match(URL_REGEX) || [];
|
||||||
return Promise.all(_.map(list, url => new Promise((resolve, reject) => isImage(url).then(function (img) {
|
return Promise.all(_.map(list, url => new Promise((resolve, reject) => {
|
||||||
const i = new Image();
|
const uri = new URI(url),
|
||||||
i.src = img.src;
|
filename = uri.filename(),
|
||||||
i.addEventListener('load', resolve); // We also resolve for non-images, otherwise the
|
lower_filename = filename.toLowerCase();
|
||||||
// Promise.all resolves prematurely.
|
|
||||||
|
|
||||||
i.addEventListener('error', resolve);
|
if (!_.includes(["https", "http"], uri.protocol().toLowerCase())) {
|
||||||
|
return resolve();
|
||||||
|
}
|
||||||
|
|
||||||
_.each(sizzle(`a[href="${url}"]`, obj), a => {
|
if (lower_filename.endsWith('jpg') || lower_filename.endsWith('jpeg') || lower_filename.endsWith('png') || lower_filename.endsWith('gif') || lower_filename.endsWith('svg')) {
|
||||||
a.outerHTML = tpl_image({
|
return isImage(url).then(img => {
|
||||||
'url': url,
|
const i = new Image();
|
||||||
'label_download': __('Download')
|
i.src = img.src;
|
||||||
});
|
i.addEventListener('load', resolve); // We also resolve for non-images, otherwise the
|
||||||
});
|
// Promise.all resolves prematurely.
|
||||||
}).catch(resolve))));
|
|
||||||
|
i.addEventListener('error', resolve);
|
||||||
|
const __ = _converse.__;
|
||||||
|
|
||||||
|
_.each(sizzle(`a[href="${url}"]`, obj), a => {
|
||||||
|
a.outerHTML = tpl_image({
|
||||||
|
'url': url,
|
||||||
|
'label_download': __('Download')
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}).catch(resolve);
|
||||||
|
} else {
|
||||||
|
return resolve();
|
||||||
|
}
|
||||||
|
})));
|
||||||
};
|
};
|
||||||
|
|
||||||
u.renderFileURL = function (_converse, url) {
|
u.renderFileURL = function (_converse, url) {
|
||||||
|
@ -288,23 +288,37 @@
|
|||||||
const list = obj.textContent.match(URL_REGEX) || [];
|
const list = obj.textContent.match(URL_REGEX) || [];
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
_.map(list, (url) =>
|
_.map(list, (url) =>
|
||||||
new Promise((resolve, reject) =>
|
new Promise((resolve, reject) => {
|
||||||
isImage(url).then(function (img) {
|
const uri = new URI(url),
|
||||||
const i = new Image();
|
filename = uri.filename(),
|
||||||
i.src = img.src;
|
lower_filename = filename.toLowerCase();
|
||||||
i.addEventListener('load', resolve);
|
if (!_.includes(["https", "http"], uri.protocol().toLowerCase())) {
|
||||||
// We also resolve for non-images, otherwise the
|
return resolve();
|
||||||
// Promise.all resolves prematurely.
|
}
|
||||||
i.addEventListener('error', resolve);
|
if (lower_filename.endsWith('jpg') || lower_filename.endsWith('jpeg') ||
|
||||||
|
lower_filename.endsWith('png') || lower_filename.endsWith('gif') ||
|
||||||
|
lower_filename.endsWith('svg')) {
|
||||||
|
|
||||||
_.each(sizzle(`a[href="${url}"]`, obj), (a) => {
|
return isImage(url).then(img => {
|
||||||
a.outerHTML= tpl_image({
|
const i = new Image();
|
||||||
'url': url,
|
i.src = img.src;
|
||||||
'label_download': __('Download')
|
i.addEventListener('load', resolve);
|
||||||
})
|
// We also resolve for non-images, otherwise the
|
||||||
});
|
// Promise.all resolves prematurely.
|
||||||
}).catch(resolve)
|
i.addEventListener('error', resolve);
|
||||||
)
|
|
||||||
|
const { __ } = _converse;
|
||||||
|
_.each(sizzle(`a[href="${url}"]`, obj), (a) => {
|
||||||
|
a.outerHTML= tpl_image({
|
||||||
|
'url': url,
|
||||||
|
'label_download': __('Download')
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}).catch(resolve)
|
||||||
|
} else {
|
||||||
|
return resolve();
|
||||||
|
}
|
||||||
|
})
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user