function TorrentStart(){ var id, fn, btname; if (typeof arguments[0] === 'number' && typeof arguments[1] === 'function'){ id = arguments[0]; fn = arguments[1]; } else { info("Parameter type error!"); return false; } function onResult(err, res, body) { if (err) { fn(false); } else { fn(true); insertLogBT(btname, 'INFO', 'BT START'); } } btname = getNameById(id); if (!btname) { fn(false); } else { bt.query( 'torrent-start', { ids: [id], }, onResult ); } }
Nasd.Webd.addUploadHandler('torrent-file', function (tmp, name) { var fs = require('fs'); function onResult(err, res, body) { if (err) { } else { list(); if (body.arguments['torrent-added']){ insertLogBT(body.arguments['torrent-added'].name, 'INFO', 'BT ADD'); } else { insertLogBT(body.result, 'WARNING', 'BT ADD'); } } fs.unlinkSync(tmp); list(); } bt.query( 'torrent-add', { filename: tmp }, onResult ); });
function TorrentRemove(){ var id, fn, btname; if (typeof arguments[0] === 'number' && typeof arguments[1] === 'function'){ id = arguments[0]; fn = arguments[1]; } else { info("Parameter type error!"); return false; } function onResult(err, res, body) { if (err) { fn(false); } else { fn(true); list(); insertLogBT(btname, 'INFO', 'BT REMOVE'); } } btname = getNameById(id); if (!btname) { fn(false); } else { bt.query( 'torrent-remove', { ids: [id], 'delete-local-data': false }, onResult ); } }
function list() { bt.query( 'torrent-get', { fields: [ 'id', 'name', 'status', 'percentDone', 'rateDownload', 'downloadDir', 'peers' ] }, function(err, res, body) { if (err) { info(err); } else { btList = countAvailability(body.arguments.torrents); self.emit('update', btList); } }); }