feat(download): torrent downloads manager

This commit is contained in:
Alexey Kasyanchuk
2018-03-06 11:17:24 +03:00
parent c40799816b
commit 1e86ba84c1
8 changed files with 119 additions and 6 deletions

View File

@ -690,8 +690,9 @@ if(dataDirectory && fs.existsSync(dataDirectory + '/peers.p2p'))
callback(true)
});
recive('download', (magnet) =>
recive('download', (torrentObject) =>
{
const magnet = `magnet:?xt=urn:btih:${torrentObject.hash}`
console.log('download', magnet)
if(torrentClient.get(magnet)) {
console.log('aready added')
@ -700,6 +701,7 @@ if(dataDirectory && fs.existsSync(dataDirectory + '/peers.p2p'))
torrentClient.add(magnet, {path: config.client.downloadPath}, (torrent) =>{
torrentClientHashMap[torrent.infoHash] = magnet
torrent.torrentObject = torrentObject
console.log('start downloading', torrent.infoHash)
send('downloading', torrent.infoHash)
@ -716,7 +718,7 @@ if(dataDirectory && fs.existsSync(dataDirectory + '/peers.p2p'))
now = Date.now()
send('downloadProgress', torrent.infoHash, {
bytes,
received: bytes,
downloaded: torrent.downloaded,
speed: torrent.downloadSpeed,
progress: torrent.progress
@ -751,6 +753,17 @@ if(dataDirectory && fs.existsSync(dataDirectory + '/peers.p2p'))
})
})
recive('downloads', (callback) =>
{
callback(torrentClient.torrents.map(torrent => ({
torrentObject: torrent.torrentObject,
received: torrent.received,
downloaded: torrent.downloaded,
progress: torrent.progress,
speed: torrent.downloadSpeed
})))
})
let socketIPV4 = () => {
let ip = socket.request.connection.remoteAddress;
if (ipaddr.IPv4.isValid(ip)) {