Refactor main.js: torrent list controller
This commit is contained in:
@@ -14,6 +14,7 @@ var path = require('path')
|
||||
var crashReporter = require('../crash-reporter')
|
||||
var config = require('../config')
|
||||
var torrentPoster = require('./lib/torrent-poster')
|
||||
var TorrentSummary = require('./lib/torrent-summary')
|
||||
|
||||
// Report when the process crashes
|
||||
crashReporter.init()
|
||||
@@ -42,8 +43,8 @@ function init () {
|
||||
client.on('warning', (err) => ipc.send('wt-warning', null, err.message))
|
||||
client.on('error', (err) => ipc.send('wt-error', null, err.message))
|
||||
|
||||
ipc.on('wt-start-torrenting', (e, torrentKey, torrentID, path, fileModtimes, selections) =>
|
||||
startTorrenting(torrentKey, torrentID, path, fileModtimes, selections))
|
||||
ipc.on('wt-start-torrenting', (e, torrentSummary) =>
|
||||
startTorrenting(torrentSummary))
|
||||
ipc.on('wt-stop-torrenting', (e, infoHash) =>
|
||||
stopTorrenting(infoHash))
|
||||
ipc.on('wt-create-torrent', (e, torrentKey, options) =>
|
||||
@@ -72,12 +73,15 @@ function init () {
|
||||
|
||||
// Starts a given TorrentID, which can be an infohash, magnet URI, etc. Returns WebTorrent object
|
||||
// See https://github.com/feross/webtorrent/blob/master/docs/api.md#clientaddtorrentid-opts-function-ontorrent-torrent-
|
||||
function startTorrenting (torrentKey, torrentID, path, fileModtimes, selections) {
|
||||
function startTorrenting (torrentSummary) {
|
||||
var s = torrentSummary
|
||||
var torrentKey = s.torrentKey
|
||||
var torrentID = TorrentSummary.getTorrentID(s)
|
||||
console.log('starting torrent %s: %s', torrentKey, torrentID)
|
||||
|
||||
var torrent = client.add(torrentID, {
|
||||
path: path,
|
||||
fileModtimes: fileModtimes
|
||||
path: s.path,
|
||||
fileModtimes: s.fileModtimes
|
||||
})
|
||||
torrent.key = torrentKey
|
||||
|
||||
@@ -85,7 +89,7 @@ function startTorrenting (torrentKey, torrentID, path, fileModtimes, selections)
|
||||
addTorrentEvents(torrent)
|
||||
|
||||
// Only download the files the user wants, not necessarily all files
|
||||
torrent.once('ready', () => selectFiles(torrent, selections))
|
||||
torrent.once('ready', () => selectFiles(torrent, s.selections))
|
||||
|
||||
return torrent
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user