mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-03-06 04:01:04 +01:00
feat(announce): write upload & download data size and seed time to H&R torrent complete record and update user`s H&R warning numbers
This commit is contained in:
1
config/env/torrents.js
vendored
1
config/env/torrents.js
vendored
@@ -264,6 +264,7 @@ module.exports = {
|
||||
forbiddenDownloadMinWarningNumber: 5,
|
||||
scoreToRemoveWarning: 10000
|
||||
},
|
||||
|
||||
userStatus: {
|
||||
name: 'STATUS',
|
||||
value: [
|
||||
|
||||
@@ -294,6 +294,7 @@ exports.announce = function (req, res) {
|
||||
var comp = new Complete();
|
||||
comp.torrent = req.torrent._id;
|
||||
comp.user = req.passkeyuser._id;
|
||||
comp.complete = req.seeder ? true : false;
|
||||
|
||||
comp.save(function (err) {
|
||||
if (err) {
|
||||
@@ -398,6 +399,8 @@ exports.announce = function (req, res) {
|
||||
writeUpDownData
|
||||
uploaded,downloaded
|
||||
update complete data if completeTorrent is exist
|
||||
if has upload and download data size, write data size,
|
||||
write time of seed(complete) whether or not u/d is 0
|
||||
---------------------------------------------------------------*/
|
||||
function (done) {
|
||||
console.log('---------------WRITE_UP_DOWN_DATA----------------');
|
||||
@@ -407,36 +410,43 @@ exports.announce = function (req, res) {
|
||||
if (req.currentPeer !== undefined) {
|
||||
var curru = query.uploaded - req.currentPeer.peer_uploaded;
|
||||
var currd = query.downloaded - req.currentPeer.peer_downloaded;
|
||||
|
||||
var u = Math.round(curru * udr.ur);
|
||||
var d = Math.round(currd * udr.dr);
|
||||
|
||||
if (req.passkeyuser.isVip) {
|
||||
u = u * config.meanTorrentConfig.torrentSalesValue.vip.Ur;
|
||||
d = d * config.meanTorrentConfig.torrentSalesValue.vip.Dr;
|
||||
}
|
||||
req.passkeyuser.update({
|
||||
$inc: {uploaded: u, downloaded: d}
|
||||
}).exec();
|
||||
|
||||
//write complete data to completeTorrent
|
||||
if (req.completeTorrent) {
|
||||
req.completeTorrent.update({
|
||||
$inc: {
|
||||
total_uploaded: curru,
|
||||
total_downloaded: currd
|
||||
}
|
||||
if (curru > 0 || currd > 0) {
|
||||
if (req.passkeyuser.isVip) {
|
||||
u = u * config.meanTorrentConfig.torrentSalesValue.vip.Ur;
|
||||
d = d * config.meanTorrentConfig.torrentSalesValue.vip.Dr;
|
||||
}
|
||||
req.passkeyuser.update({
|
||||
$inc: {uploaded: u, downloaded: d}
|
||||
}).exec();
|
||||
|
||||
//only add seed time for completed torrent
|
||||
if (req.completeTorrent.complete) {
|
||||
//write complete data to completeTorrent
|
||||
if (req.completeTorrent) {
|
||||
req.completeTorrent.update({
|
||||
$inc: {
|
||||
total_seed_time: config.meanTorrentConfig.announce.announceInterval
|
||||
total_uploaded: curru,
|
||||
total_downloaded: currd
|
||||
}
|
||||
}).exec();
|
||||
}
|
||||
}
|
||||
|
||||
//only add seed time for completed torrent
|
||||
if (req.completeTorrent && req.completeTorrent.complete) {
|
||||
req.completeTorrent.update({
|
||||
$inc: {
|
||||
total_seed_time: config.meanTorrentConfig.announce.announceInterval
|
||||
}
|
||||
}).exec();
|
||||
}
|
||||
//update warning status
|
||||
if (req.completeTorrent) {
|
||||
req.completeTorrent.countHnRWarning(req.passkeyuser);
|
||||
}
|
||||
|
||||
//create trace log
|
||||
if (curru > 0 || currd > 0) {
|
||||
traceLogCreate(req, traceConfig.action.userAnnounceData, {
|
||||
|
||||
@@ -505,6 +505,9 @@ exports.toggleHnRStatus = function (req, res) {
|
||||
res.json(torrent);
|
||||
}
|
||||
});
|
||||
|
||||
//TODO: remove the complete data and update user`s warning number when the H&R prop to false
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -728,6 +731,8 @@ exports.delete = function (req, res) {
|
||||
torrent: torrent._id
|
||||
});
|
||||
|
||||
//TODO: remove the complete data and update user`s warning number if the torrent has H&R prop
|
||||
|
||||
torrent.remove(function (err) {
|
||||
if (err) {
|
||||
return res.status(422).send({
|
||||
|
||||
@@ -109,7 +109,7 @@ function countSeedDay(t) {
|
||||
*/
|
||||
CompleteSchema.methods.countHnRWarning = function (u) {
|
||||
if (this.complete) {
|
||||
if (this.total_seed_day >= hnrConfig.condition.seedTime || this.total_ratio >= hnrConfig.condition.ratio) {
|
||||
if (this.total_seed_day >= hnrConfig.condition.seedTime || this.total_ratio === -1 || this.total_ratio >= hnrConfig.condition.ratio) {
|
||||
if (this.hnr_warning) {
|
||||
this.update({
|
||||
$set: {hnr_warning: false}
|
||||
|
||||
Reference in New Issue
Block a user