Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function loadReleases (cb) {
const opts = {
url: 'https://api.github.com/repos/webtorrent/webtorrent-desktop/releases',
json: true,
timeout: 30 * 1000,
headers: {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36'
}
}
console.log('Fetching ' + opts.url)
get.concat(opts, function (err, res, data) {
if (err) return cb(err)
console.log('Got ' + data.length + ' WebTorrent Desktop releases')
const releases = data.map(function (d) {
// Count total downloads
let win32 = 0
let darwin = 0
let linux = 0
d.assets.map(function (a) {
if (a.name.endsWith('.dmg')) {
darwin += a.download_count
} else if (a.name.endsWith('.exe')) {
win32 += a.download_count
} else if (a.name.endsWith('.deb') ||
a.name.endsWith('linux-ia32.zip') ||
a.name.endsWith('linux-x64.zip')) {
linux += a.download_count
login (cb) {
// Check that required params exist
if (typeof cb !== 'function') {
throw new Error('Invalid or missing `cb` parameter for login method')
}
const requestData = {
url: TW_REQ_TOKEN_URL,
method: 'POST',
data: {
oauth_callback: this.callbackUrl
}
}
// Get a "request token"
get.concat({
url: requestData.url,
method: requestData.method,
form: requestData.data,
headers: this._oauth.toHeader(this._oauth.authorize(requestData))
}, (err, res, data) => {
if (err) return cb(err)
const {
oauth_token: token,
oauth_token_secret: tokenSecret,
oauth_callback_confirmed: callbackConfirmed
} = querystring.parse(data.toString())
// Must validate that this param exists, according to Twitter docs
if (callbackConfirmed !== 'true') {
return cb(new Error('Missing `oauth_callback_confirmed` parameter in response'))
commonTest.createServer(t, 'http', function (server, announceUrl) {
var url = announceUrl.replace('/announce', '/stats')
get.concat(url, function (err, res, data) {
t.error(err)
var stats = parseHtml(data.toString())
t.equal(res.statusCode, 200)
t.equal(stats.torrents, 0)
t.equal(stats.activeTorrents, 0)
t.equal(stats.peersAll, 0)
t.equal(stats.peersSeederOnly, 0)
t.equal(stats.peersLeecherOnly, 0)
t.equal(stats.peersSeederAndLeecher, 0)
t.equal(stats.peersIPv4, 0)
t.equal(stats.peersIPv6, 0)
server.close(function () { t.pass('server closed') })
})
})
return done(err);
}
if (!shows.length) {
return done();
}
getLatest(shows[0].id, distance, done);
});
} else {
id = series;
}
url = exports.host + '/watch-' + id + '-X-online-free';
get.concat(url, function (err, res, body) {
var $, episode, match;
if (err) {
return done(err);
}
try {
$ = cheerio.load(body);
} catch (e) {
return done(e);
}
episode = $('.tv_episode_item a').get();
episode = episode[episode.length - distance];
if (!episode || !episode.attribs || !episode.attribs.href) {
function search(terms, done) {
get.concat(exports.host + '?' + qs.encode({
'search_keywords': terms.title,
'search_section': terms.section === 'tv' ? 2 : 1,
key: '',
year: terms.year,
page: 1
}), function (err, res, body) {
var $, shows;
if (err) {
return done(err);
}
try {
$ = cheerio.load(body);
} catch (e) {
return done(e);
return new Promise(function (resolve, reject) {
log('getting from url', url);
simpleGet.concat(url, function (err, data, res) {
if (err) {
log('simple get error from url', url, err);
return reject(err);
}
if (res.statusCode !== 200) {
log('while fetching from', url, 'got', res.statusCode);
log(res);
return reject(new Error('GET from ' + url + ' status ' + res.statusCode));
}
return resolve(data);
});
});
}
api_key: this._key,
format: 'json'
})
const urlBase = 'https://ws.audioscrobbler.com/2.0/'
const opts = {
url: urlBase + '?' + querystring.stringify(params),
headers: {
'User-Agent': this._userAgent
},
timeout: 30 * 1000,
json: true
}
get.concat(opts, onResponse)
function onResponse (err, res, data) {
if (err) return cb(err)
if (data.error) return cb(new Error(data.message))
cb(null, data[name])
}
}