attachment-detection
Advanced tools
Comparing version 0.2.0-0 to 0.2.1-0
@@ -0,1 +1,5 @@ | ||
var _ = require('underscore'), | ||
Helper = require('./detectors/helper'), | ||
request = require('request'); | ||
var _detect = function(link, handlers, callback) { | ||
@@ -29,4 +33,7 @@ var handler, index = 0, result = { | ||
module.exports = (function() { | ||
var Detector = function(handlers) { | ||
this.handlers = handlers || []; | ||
var Detector = function(options) { | ||
this.handlers = []; | ||
this.options = _.defaults(options || {}, { | ||
follow: true | ||
}); | ||
}; | ||
@@ -40,3 +47,5 @@ | ||
detect: function(links, callback) { | ||
var attachments = [], self = this, count; | ||
var attachments = [], | ||
self = this, | ||
count; | ||
@@ -58,5 +67,15 @@ if (Object.prototype.toString.call(links) != "[object Array]") { | ||
var detectClosure = (function (index) { | ||
_detect(links[index], self.handlers, function (result) { | ||
attachments[index] = result; | ||
done(); | ||
var resolveLink = function(url, callback) { | ||
if (!self.options.follow) return callback(url); | ||
request(url, function (err, response, body) { | ||
callback(response.request.uri.href); | ||
}); | ||
}; | ||
resolveLink(Helper.fullUrl(links[index]), function (link) { | ||
_detect(link, self.handlers, function (result) { | ||
attachments[index] = result; | ||
done(); | ||
}); | ||
}); | ||
@@ -63,0 +82,0 @@ }); |
@@ -8,6 +8,7 @@ var detector = require('./detector'); | ||
wrapper.Detector = detector; | ||
wrapper.YouTube = require('./youtube'); | ||
wrapper.Image = require('./image'); | ||
wrapper.Link = require('./link'); | ||
wrapper.YouTube = require('./detectors/youtube'); | ||
wrapper.SoundCloud = require('./detectors/soundcloud'); | ||
wrapper.Image = require('./detectors/image'); | ||
wrapper.Link = require('./detectors/link'); | ||
module.exports = wrapper; |
{ | ||
"name": "attachment-detection", | ||
"version": "0.2.0-0", | ||
"version": "0.2.1-0", | ||
"dependencies": { | ||
"request": "2.10.0", | ||
"cheerio": "0.9.2" | ||
"cheerio": "0.9.2", | ||
"underscore": "*" | ||
}, | ||
@@ -8,0 +9,0 @@ "devDependencies": { |
@@ -39,3 +39,2 @@ var buster = require('buster'), | ||
detector.detect(['http://www.paintballarena.dk/'], function(result) { | ||
console.log(result[0].description); | ||
expect(!!~result[0].description.indexOf('Europas største indendørs Paintball- og eventcenter, høvdingebold, skydebane, Laserskydning, Sumo brydning, human football, gladiator kamp og rodeo tyr, Bungee tag, Multisport index')).toBeTrue(); | ||
@@ -42,0 +41,0 @@ done(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12552
14
321
3
2
1
+ Addedunderscore@*