Skip to content
This repository has been archived by the owner on Aug 13, 2019. It is now read-only.

Commit

Permalink
Made it possible to parse all links
Browse files Browse the repository at this point in the history
  • Loading branch information
amix committed Apr 21, 2014
1 parent da63cee commit 398d7de
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
29 changes: 21 additions & 8 deletions lib/media-embed-server.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
"description": "Node oEmbed proxy that supports a few other non-oEmbed services and JSONP",
"keywords": ["oembed", "media", "proxy", "thumbnails"],
"author": "amix",
"version": "1.4.2",
"version": "1.4.3",
"repository": "https://github.com/Doist/media-embed-server",
"licenses": [{
"type": "MIT",
"url": "http://opensource.org/licenses/mit-license.php"
}],

"dependencies": {
"media-parser": "1.4.0",
"media-parser": "1.4.2",
"webpage-info": "0.0.1",
"express": "4.0.0",
"commander": ">=0.6.0",
"async": ">=0.7.0",
Expand Down
19 changes: 15 additions & 4 deletions src/media-embed-server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ async = require('async')
program = require('commander')
partial = require('partial')
media_parser = require('media-parser')
webpage_info = require('webpage-info')
Memcached = require('memcached')

app = express()

app.unknown_error = {'error': 'Could not resolve resource'}


# --- Parse
app.get('/parse', (req, res) ->
Expand All @@ -18,7 +21,7 @@ app.get('/parse', (req, res) ->

# Process the requests in parallel
cb_functions = []
for _url in media_parser.extractURLs(content)
for _url in media_parser.allURLs(content)
cb = (url, async_cb) ->
cache_key = _url + ':' + min_tn_size

Expand Down Expand Up @@ -46,9 +49,17 @@ app.get('/parse', (req, res) ->
app.cache.set(cache_key, JSON.stringify(obj), 3600)
async_cb(null, obj)
else
result = {'error': 'Could not resolve resource'}
result.matched_url = url
async_cb(null, result)
webpage_info.parse(url, (page_info) ->
if page_info.error
result = app.unknown_error
result.matched_url = url
else
result = page_info
result.matched_url = url
app.cache.set(cache_key, JSON.stringify(result), 3600)

async_cb(null, result)
)
, timeout)
)

Expand Down

0 comments on commit 398d7de

Please sign in to comment.