Support scrape without info_hash specified (Fix #28)

This commit is contained in:
Feross Aboukhadijeh 2014-07-10 21:30:10 -07:00
parent 5bc1b50ff5
commit 23d2c02fe6

View File

@ -220,7 +220,13 @@ Server.prototype._onHttpRequest = function (req, res) {
} else if (s[0] === '/scrape') { // unofficial scrape message
if (typeof params.info_hash === 'string') {
params.info_hash = [ params.info_hash ]
} else if (params.info_hash == null) {
// if info_hash param is omitted, stats for all torrents are returned
params.info_hash = Object.keys(self.torrents).map(function (infoHashHex) {
return common.bytewiseEncodeURIComponent(new Buffer(infoHashHex, 'hex'))
})
}
if (!Array.isArray(params.info_hash)) return error('invalid info_hash')
var response = {