feat(download): cancel downloading

This commit is contained in:
Alexey Kasyanchuk 2018-02-08 22:48:49 +03:00
parent d320448903
commit 76651b6e02
2 changed files with 21 additions and 4 deletions

View File

@ -18,6 +18,7 @@ var moment = require('moment');
import RefreshIndicator from 'material-ui/RefreshIndicator';
let rating = require('./rating');
import LinearProgress from 'material-ui/LinearProgress';
import FlatButton from 'material-ui/FlatButton';
import {fileTypeDetect} from './content'
import {contentIcon} from './torrent'
@ -247,11 +248,14 @@ export default class TorrentPage extends Page {
}
window.torrentSocket.on('downloading', this.downloading);
this.downloadDone = (hash) => {
this.downloadDone = (hash, canceled) => {
if(this.props.hash != hash)
return;
this.setState({downloading: false})
this.setState({
downloading: false,
askDownloading: !canceled
})
}
window.torrentSocket.on('downloadDone', this.downloadDone);
@ -402,6 +406,14 @@ export default class TorrentPage extends Page {
mode="determinate"
value={this.state.downloadProgress && this.state.downloadProgress.progress * 100}
/>
<FlatButton
onClick={() => {
window.torrentSocket.emit('downloadCancel', this.torrent.hash)
}}
label="Cancel download"
secondary={true}
icon={<svg fill='rgb(255, 64, 129)' viewBox="0 0 18 18"><path d="M9 1C4.58 1 1 4.58 1 9s3.58 8 8 8 8-3.58 8-8-3.58-8-8-8zm4 10.87L11.87 13 9 10.13 6.13 13 5 11.87 7.87 9 5 6.13 6.13 5 9 7.87 11.87 5 13 6.13 10.13 9 13 11.87z"/></svg>}
/>
</div>
}
<div className='fs0-75 pad0-75 center column' style={{color: 'rgba(0, 0, 0, 0.541176)'}}><div>BTIH:</div><div>{this.torrent.hash}</div></div>

View File

@ -584,11 +584,14 @@ setInterval(() => {
recive('download', (magnet) =>
{
console.log('download', magnet)
if(torrentClient.get(magnet))
if(torrentClient.get(magnet)) {
console.log('aready added')
return
}
torrentClient.add(magnet, {path: config.client.downloadPath}, (torrent) =>{
torrentClientHashMap[torrent.infoHash] = magnet
console.log('start downloading', torrent.infoHash)
send('downloading', torrent.infoHash)
torrent.on('done', () => {
@ -622,7 +625,7 @@ setInterval(() => {
return
}
client.remove(id, (err) => {
torrentClient.remove(id, (err) => {
if(err)
{
callback(false)
@ -630,6 +633,8 @@ setInterval(() => {
}
delete torrentClientHashMap[hash]
send('downloadDone', hash, true)
if(callback)
callback(true)
})