Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
Rocket.Chat
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
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
RocketChat
Rocket.Chat
Commits
c811244c
Commit
c811244c
authored
9 years ago
by
Rodrigo Nascimento
Browse files
Options
Downloads
Patches
Plain Diff
Create method to load url and extract headers and meta tags
parent
b54775e3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
packages/rocketchat-oembed/package.js
+1
-0
1 addition, 0 deletions
packages/rocketchat-oembed/package.js
packages/rocketchat-oembed/server.coffee
+82
-0
82 additions, 0 deletions
packages/rocketchat-oembed/server.coffee
with
83 additions
and
0 deletions
packages/rocketchat-oembed/package.js
+
1
−
0
View file @
c811244c
...
...
@@ -15,6 +15,7 @@ Package.onUse(function(api) {
]);
api
.
addFiles
(
'
oembed.coffee
'
,
[
'
server
'
,
'
client
'
]);
api
.
addFiles
(
'
server.coffee
'
,
[
'
server
'
]);
});
Package
.
onTest
(
function
(
api
)
{
...
...
This diff is collapsed.
Click to expand it.
packages/rocketchat-oembed/server.coffee
0 → 100644
+
82
−
0
View file @
c811244c
URL
=
Npm
.
require
(
'url'
)
http
=
Npm
.
require
(
'http'
)
https
=
Npm
.
require
(
'https'
)
querystring
=
Npm
.
require
(
'querystring'
)
getUrlContent
=
(
urlObj
,
redirectCount
=
5
,
callback
)
->
opts
=
method
:
'GET'
port
:
urlObj
.
port
hostname
:
urlObj
.
hostname
path
:
urlObj
.
path
httpOrHttps
=
if
urlObj
.
protocol
is
'https:'
then
https
else
http
request
=
httpOrHttps
.
request
opts
,
(
response
)
->
if
response
.
statusCode
is
301
and
response
.
headers
.
location
?
request
.
abort
()
console
.
log
response
.
headers
.
location
if
redirectCount
<=
0
return
callback
null
,
null
getUrlContent
response
.
headers
.
location
,
--
redirectCount
,
callback
return
if
response
.
statusCode
isnt
200
return
callback
null
,
null
str
=
''
response
.
on
'data'
,
(
chunk
)
->
str
+=
chunk
if
str
.
length
>
250000
request
.
abort
()
response
.
on
'end'
,
->
callback
null
,
{
headers
:
response
.
headers
body
:
str
}
request
.
end
()
getUrlMeta
=
(
url
,
withFragment
)
->
getUrlContentSync
=
Meteor
.
wrapAsync
getUrlContent
urlObj
=
URL
.
parse
url
if
withFragment
?
queryStringObj
=
querystring
.
parse
urlObj
.
query
queryStringObj
.
_escaped_fragment_
=
''
urlObj
.
query
=
querystring
.
stringify
queryStringObj
path
=
urlObj
.
pathname
if
urlObj
.
query
?
path
+=
'?'
+
urlObj
.
query
urlObj
.
path
=
path
content
=
getUrlContentSync
urlObj
,
5
metas
=
{}
content
?
.
body
.
replace
/<meta.*(?:name|property)=['"]([^'"]*)['"].*content=['"]([^'"]*)['"].*>/gmi
,
(
meta
,
name
,
value
)
->
metas
[
name
]
=
value
return
{
meta
:
metas
headers
:
content
?
.
headers
}
Meteor
.
methods
getUrlMeta
:
(
url
)
->
data
=
getUrlMeta
url
if
data
.
meta
.
fragment
is
'!'
data
=
getUrlMeta
url
,
true
console
.
log
data
.
meta
console
.
log
data
.
headers
return
data
\ No newline at end of file
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