mirror of
https://github.com/zoriya/flood.git
synced 2025-12-22 23:25:27 +00:00
Add TorrentCollection class and store torrents by hash
This commit is contained in:
50
server/util/formatUtil.js
Normal file
50
server/util/formatUtil.js
Normal file
@@ -0,0 +1,50 @@
|
||||
var util = require('util');
|
||||
|
||||
var FormatUtil = {
|
||||
percentComplete: function(numerator, denominator) {
|
||||
|
||||
},
|
||||
|
||||
eta: function(rate, completed, total) {
|
||||
|
||||
},
|
||||
|
||||
parsePeers: function(string) {
|
||||
var markerPosition = string.indexOf('@!@');
|
||||
return string.substr(0, markerPosition);
|
||||
},
|
||||
|
||||
status: function(isHashChecking, isComplete, isOpen, uploadRate, downloadRate, state, message) {
|
||||
var torrentStatus = [];
|
||||
|
||||
if (isHashChecking === '1') {
|
||||
torrentStatus.push('ch'); // checking
|
||||
} else if (isComplete === '1' && isOpen === '1' && state === '1') {
|
||||
torrentStatus.push('sd'); // seeding
|
||||
} else if (isComplete === '1' && isOpen === '1' && state === '0') {
|
||||
torrentStatus.push('p'); // paused
|
||||
} else if (isComplete === '1' && isOpen === '0') {
|
||||
torrentStatus.push('c'); // complete
|
||||
} else if (isComplete === '0' && isOpen === '1' && state === '1') {
|
||||
torrentStatus.push('d'); // downloading
|
||||
} else if (isComplete === '0' && isOpen === '1' && state === '0') {
|
||||
torrentStatus.push('p'); // paused
|
||||
} else if (isComplete === '0' && isOpen === '0') {
|
||||
torrentStatus.push('s'); // stopped
|
||||
}
|
||||
|
||||
if (message.length) {
|
||||
torrentStatus.push('e'); // error
|
||||
}
|
||||
|
||||
if (uploadRate === '0' && downloadRate === '0') {
|
||||
torrentStatus.push('i');
|
||||
} else {
|
||||
torrentStatus.push('a');
|
||||
}
|
||||
|
||||
return torrentStatus;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = FormatUtil;
|
||||
Reference in New Issue
Block a user