Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
2426f9b7
Commit
2426f9b7
authored
Oct 13, 2018
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only attempt loading img URL with filename and appropriate extension
updates #1228
parent
e425f257
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
32 deletions
+61
-32
dist/converse.js
dist/converse.js
+30
-15
src/utils/core.js
src/utils/core.js
+31
-17
No files found.
dist/converse.js
View file @
2426f9b7
...
...
@@ -82094,21 +82094,36 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
*/
const __ = _converse.__;
const list = obj.textContent.match(URL_REGEX) || [];
return Promise.all(_.map(list, url => new Promise((resolve, reject) => isImage(url).then(function (img) {
const i = new Image();
i.src = img.src;
i.addEventListener('load', resolve); // We also resolve for non-images, otherwise the
// Promise.all resolves prematurely.
i.addEventListener('error', resolve);
_.each(sizzle(`a[href="${url}"]`, obj), a => {
a.outerHTML = tpl_image({
'url': url,
'label_download': __('Download')
});
});
}).catch(resolve))));
return Promise.all(_.map(list, url => new Promise((resolve, reject) => {
const uri = new URI(url),
filename = uri.filename(),
lower_filename = filename.toLowerCase();
if (!_.includes(["https", "http"], uri.protocol().toLowerCase())) {
return resolve();
}
if (lower_filename.endsWith('jpg') || lower_filename.endsWith('jpeg') || lower_filename.endsWith('png') || lower_filename.endsWith('gif') || lower_filename.endsWith('svg')) {
return isImage(url).then(img => {
const i = new Image();
i.src = img.src;
i.addEventListener('load', resolve); // We also resolve for non-images, otherwise the
// Promise.all resolves prematurely.
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) {
src/utils/core.js
View file @
2426f9b7
...
...
@@ -288,23 +288,37 @@
const
list
=
obj
.
textContent
.
match
(
URL_REGEX
)
||
[];
return
Promise
.
all
(
_
.
map
(
list
,
(
url
)
=>
new
Promise
((
resolve
,
reject
)
=>
isImage
(
url
).
then
(
function
(
img
)
{
const
i
=
new
Image
();
i
.
src
=
img
.
src
;
i
.
addEventListener
(
'
load
'
,
resolve
);
// We also resolve for non-images, otherwise the
// Promise.all resolves prematurely.
i
.
addEventListener
(
'
error
'
,
resolve
);
_
.
each
(
sizzle
(
`a[href="
${
url
}
"]`
,
obj
),
(
a
)
=>
{
a
.
outerHTML
=
tpl_image
({
'
url
'
:
url
,
'
label_download
'
:
__
(
'
Download
'
)
})
});
}).
catch
(
resolve
)
)
new
Promise
((
resolve
,
reject
)
=>
{
const
uri
=
new
URI
(
url
),
filename
=
uri
.
filename
(),
lower_filename
=
filename
.
toLowerCase
();
if
(
!
_
.
includes
([
"
https
"
,
"
http
"
],
uri
.
protocol
().
toLowerCase
()))
{
return
resolve
();
}
if
(
lower_filename
.
endsWith
(
'
jpg
'
)
||
lower_filename
.
endsWith
(
'
jpeg
'
)
||
lower_filename
.
endsWith
(
'
png
'
)
||
lower_filename
.
endsWith
(
'
gif
'
)
||
lower_filename
.
endsWith
(
'
svg
'
))
{
return
isImage
(
url
).
then
(
img
=>
{
const
i
=
new
Image
();
i
.
src
=
img
.
src
;
i
.
addEventListener
(
'
load
'
,
resolve
);
// We also resolve for non-images, otherwise the
// Promise.all resolves prematurely.
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
();
}
})
)
)
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment