cancel active download and reset state if downloading again, fixes #187
This commit is contained in:
parent
cef4ce23e1
commit
52bc986260
2 changed files with 16 additions and 8 deletions
|
@ -378,6 +378,10 @@ class Item(db.Model):
|
|||
u = state.user()
|
||||
if not u in self.users:
|
||||
t = Transfer.get_or_create(self.id)
|
||||
if not t.added:
|
||||
t.added = datetime.utcnow()
|
||||
t.progress = 0
|
||||
t.save()
|
||||
logger.debug('queue %s for download', self.id)
|
||||
self.add_user(u)
|
||||
|
||||
|
|
20
oml/nodes.py
20
oml/nodes.py
|
@ -332,14 +332,18 @@ class Node(Thread):
|
|||
if since_ct > 1:
|
||||
ct = datetime.utcnow()
|
||||
t = Transfer.get(item.id)
|
||||
t.progress = len(content) / item.info['size']
|
||||
t.save()
|
||||
trigger_event('transfer', {
|
||||
'id': item.id, 'progress': t.progress
|
||||
})
|
||||
if state.bandwidth:
|
||||
state.bandwidth.download(size/since_ct)
|
||||
size = 0
|
||||
if not t.added:
|
||||
# transfer was canceled
|
||||
return False
|
||||
else:
|
||||
t.progress = len(content) / item.info['size']
|
||||
t.save()
|
||||
trigger_event('transfer', {
|
||||
'id': item.id, 'progress': t.progress
|
||||
})
|
||||
if state.bandwidth:
|
||||
state.bandwidth.download(size/since_ct)
|
||||
size = 0
|
||||
'''
|
||||
content = fileobj.read()
|
||||
'''
|
||||
|
|
Loading…
Reference in a new issue