Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-client-qt
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-client-qt
Commits
d490e840
Commit
d490e840
authored
2 years ago
by
Sébastien Blin
Browse files
Options
Downloads
Patches
Plain Diff
preview: avoid to parse too big pages and non text files
Change-Id: Ie2550f6ede051b7b7a937cc3230aacdea4fa01db
parent
300ac17d
No related branches found
Branches containing commit
Tags
beta/202310101006
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
resources/misc/previewInterop.js
+44
-11
44 additions, 11 deletions
resources/misc/previewInterop.js
with
44 additions
and
11 deletions
resources/misc/previewInterop.js
+
44
−
11
View file @
d490e840
...
...
@@ -13,12 +13,46 @@ function getPreviewInfo(messageId, url) {
if
(
!
url
.
includes
(
"
http://
"
)
&&
!
url
.
includes
(
"
https://
"
))
{
url
=
"
http://
"
.
concat
(
url
)
}
var
domain
=
(
new
URL
(
url
))
fetch
(
url
,
{
mode
:
'
no-cors
'
,
headers
:
{
'
Set-Cookie
'
:
'
SameSite=None; Secure
'
}
}).
then
(
function
(
response
)
{
return
response
.
text
()
}).
then
(
function
(
html
)
{
const
contentType
=
response
.
headers
.
get
(
'
content-type
'
);
if
(
!
contentType
||
!
contentType
.
includes
(
'
text/html
'
))
{
return
}
return
response
.
body
}).
then
(
body
=>
{
const
reader
=
body
.
getReader
();
return
new
ReadableStream
({
start
(
controller
)
{
return
pump
();
function
pump
()
{
return
reader
.
read
().
then
(({
done
,
value
})
=>
{
// When no more data needs to be consumed, close the stream
if
(
done
)
{
controller
.
close
();
return
;
}
if
(
value
.
byteLength
>
2
*
1024
*
1024
)
{
controller
.
close
();
return
;
}
// Enqueue the next data chunk into our target stream
controller
.
enqueue
(
value
);
return
pump
();
});
}
}
})
},
e
=>
Promise
.
reject
(
e
))
.
then
(
stream
=>
new
Response
(
stream
))
.
then
(
response
=>
response
.
text
())
.
then
(
function
(
html
)
{
// create DOM from html string
var
parser
=
new
DOMParser
()
var
doc
=
parser
.
parseFromString
(
html
,
"
text/html
"
)
...
...
@@ -29,18 +63,17 @@ function getPreviewInfo(messageId, url) {
}
image
=
getImage
(
doc
,
url
)
description
=
getDescription
(
doc
)
var
domain
=
(
new
URL
(
url
))
domain
=
(
domain
.
hostname
).
replace
(
"
www.
"
,
""
)
window
.
jsbridge
.
emitInfoReady
(
messageId
,
{
'
title
'
:
title
,
'
image
'
:
image
,
'
description
'
:
description
,
'
url
'
:
url
,
'
domain
'
:
domain
,
})
}).
catch
(
function
(
err
)
{
log
(
"
Error occured while fetching document:
"
+
err
)
}).
finally
(()
=>
{
window
.
jsbridge
.
emitInfoReady
(
messageId
,
{
'
title
'
:
title
,
'
image
'
:
image
,
'
description
'
:
description
,
'
url
'
:
url
,
'
domain
'
:
domain
,
})
})
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment