mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-03-22 20:01:48 +01:00
fix(core): fixed torrent set salesType and recommend level issues
This commit is contained in:
@@ -975,42 +975,47 @@
|
||||
* setSaleType
|
||||
*/
|
||||
vm.setSaleType = function () {
|
||||
TorrentsService.setSaleType({
|
||||
_torrentId: vm.torrentLocalInfo._id,
|
||||
_saleType: vm.model_salestype
|
||||
}, function (res) {
|
||||
Notification.success({
|
||||
message: '<i class="glyphicon glyphicon-ok"></i> ' + $translate.instant('TORRENT_SETSALETYPE_SUCCESSFULLY')
|
||||
});
|
||||
if (vm.model_salestype && vm.model_salestype !== vm.torrentLocalInfo.torrent_sale_status) {
|
||||
TorrentsService.setSaleType({
|
||||
_torrentId: vm.torrentLocalInfo._id,
|
||||
_saleType: vm.model_salestype
|
||||
}, function (res) {
|
||||
Notification.success({
|
||||
message: '<i class="glyphicon glyphicon-ok"></i> ' + $translate.instant('TORRENT_SETSALETYPE_SUCCESSFULLY')
|
||||
});
|
||||
|
||||
vm.torrentLocalInfo = res;
|
||||
}, function (res) {
|
||||
Notification.error({
|
||||
message: res.data.message,
|
||||
title: '<i class="glyphicon glyphicon-remove"></i> ' + $translate.instant('TORRENT_SETSALETYPE_ERROR')
|
||||
mtDebug.info(res);
|
||||
vm.torrentLocalInfo = res;
|
||||
}, function (res) {
|
||||
Notification.error({
|
||||
message: res.data.message,
|
||||
title: '<i class="glyphicon glyphicon-remove"></i> ' + $translate.instant('TORRENT_SETSALETYPE_ERROR')
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* setRecommendLevel
|
||||
*/
|
||||
vm.setRecommendLevel = function () {
|
||||
TorrentsService.setRecommendLevel({
|
||||
_torrentId: vm.torrentLocalInfo._id,
|
||||
_rlevel: vm.model_rlevel
|
||||
}, function (res) {
|
||||
Notification.success({
|
||||
message: '<i class="glyphicon glyphicon-ok"></i> ' + $translate.instant('TORRENT_SETRLEVEL_SUCCESSFULLY')
|
||||
});
|
||||
if (vm.model_rlevel && vm.model_rlevel !== vm.torrentLocalInfo.torrent_recommended) {
|
||||
TorrentsService.setRecommendLevel({
|
||||
_torrentId: vm.torrentLocalInfo._id,
|
||||
_rlevel: vm.model_rlevel
|
||||
}, function (res) {
|
||||
Notification.success({
|
||||
message: '<i class="glyphicon glyphicon-ok"></i> ' + $translate.instant('TORRENT_SETRLEVEL_SUCCESSFULLY')
|
||||
});
|
||||
|
||||
vm.torrentLocalInfo = res;
|
||||
}, function (res) {
|
||||
Notification.error({
|
||||
message: res.data.message,
|
||||
title: '<i class="glyphicon glyphicon-remove"></i> ' + $translate.instant('TORRENT_SETRLEVEL_ERROR')
|
||||
vm.torrentLocalInfo = res;
|
||||
}, function (res) {
|
||||
Notification.error({
|
||||
message: res.data.message,
|
||||
title: '<i class="glyphicon glyphicon-remove"></i> ' + $translate.instant('TORRENT_SETRLEVEL_ERROR')
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -873,6 +873,8 @@ exports.setSaleType = function (req, res) {
|
||||
torrent.torrent_sale_status = req.params.saleType;
|
||||
torrent.torrent_sale_expires = Date.now() + gbit * config.meanTorrentConfig.torrentSalesType.expires.time;
|
||||
|
||||
mtDebug.debugGreen(torrent);
|
||||
|
||||
torrent.save(function (err) {
|
||||
if (err) {
|
||||
return res.status(422).send({
|
||||
|
||||
@@ -159,6 +159,10 @@ var TorrentSchema = new Schema({
|
||||
torrent_sale_expires: {
|
||||
type: Date
|
||||
},
|
||||
isSaling: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
torrent_recommended: {
|
||||
type: String,
|
||||
default: 'none'
|
||||
@@ -193,26 +197,41 @@ var TorrentSchema = new Schema({
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* overwrite toJSON
|
||||
* Hook a pre save method
|
||||
*/
|
||||
TorrentSchema.methods.toJSON = function (options) {
|
||||
var document = this.toObject(options);
|
||||
document.isSaling = false;
|
||||
TorrentSchema.pre('save', function (next) {
|
||||
writeIsSaling(this);
|
||||
next();
|
||||
});
|
||||
|
||||
if (this.torrent_sale_expires > Date.now()) {
|
||||
document.isSaling = true;
|
||||
/**
|
||||
* Hook a pre save method
|
||||
*/
|
||||
TorrentSchema.pre('update', function (next) {
|
||||
writeIsSaling(this);
|
||||
next();
|
||||
});
|
||||
|
||||
/**
|
||||
* countRatio
|
||||
* @param user
|
||||
*/
|
||||
function writeIsSaling(torrent) {
|
||||
torrent.isSaling = false;
|
||||
|
||||
if (torrent.torrent_sale_expires > Date.now()) {
|
||||
torrent.isSaling = true;
|
||||
}
|
||||
|
||||
if (!document.isSaling) {
|
||||
document.torrent_sale_status = 'U1/D1';
|
||||
if (!torrent.isSaling) {
|
||||
torrent.torrent_sale_status = 'U1/D1';
|
||||
}
|
||||
if (document.torrent_sale_status === 'U1/D1') {
|
||||
document.isSaling = false;
|
||||
if (torrent.torrent_sale_status === 'U1/D1') {
|
||||
torrent.isSaling = false;
|
||||
}
|
||||
|
||||
return document;
|
||||
};
|
||||
}
|
||||
|
||||
TorrentSchema.index({user: -1, createdat: -1});
|
||||
TorrentSchema.index({info_hash: -1, createdat: -1});
|
||||
|
||||
Reference in New Issue
Block a user