Skip to content

Commit 442d121

Browse files
committed
Improve Announcements
1 parent 3c67966 commit 442d121

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

client.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ function Tracker (client, announceUrl, opts) {
145145
self.client = client
146146

147147
self._lastUploaded = 0
148+
self._lastDownloaded = 0
149+
self._downloadComplete = false
148150

149151
debug('new tracker %s', announceUrl)
150152

@@ -211,28 +213,28 @@ Tracker.prototype._announce = function (opts) {
211213
downloaded: 0 // default, user should provide real value
212214
}, opts)
213215

214-
if (!opts.event && self.client.torrentLength != null && self.client.torrentLength <= opts.downloaded) {
216+
if (!opts.event && self.client.torrentLength <= opts.downloaded) {
215217
if (opts.uploaded == self._lastUploaded) {
216218
return
217-
} else {
218-
// fix update event if torrentLength larger then opts.downloaded
219-
opts.left = 0
220-
opts.downloaded = self.client.torrentLength
219+
} else if (!self._downloadComplete) {
220+
opts.downloaded = self._lastDownloaded
221221
}
222222
}
223223

224-
self._lastUploaded = opts.uploaded
225-
226224
if (self.client.torrentLength != null && opts.left == null) {
227-
if (opts.event == 'completed') {
225+
if (opts.event == 'completed' || self._downloadComplete) {
228226
// if completed, fix announce to full
227+
self._downloadComplete = true
229228
opts.left = 0
230229
opts.downloaded = self.client.torrentLength
231230
} else {
232231
opts.left = self.client.torrentLength - (opts.downloaded || 0)
233232
}
234233
}
235234

235+
self._lastUploaded = opts.uploaded
236+
self._lastDownloaded = opts.downloaded
237+
236238
self._requestImpl(self._announceUrl, opts)
237239
}
238240

0 commit comments

Comments
 (0)