From 1df12fb5e9d8065d7c8a31a7ae4a584b5e6314fd Mon Sep 17 00:00:00 2001 From: OldHawk Date: Tue, 2 May 2017 15:50:52 +0800 Subject: [PATCH] add torrent sale expires time, and show in video info view --- config/env/torrents.js | 3 +- modules/core/client/app/trans-string-cn.js | 2 ++ modules/core/client/app/trans-string-en.js | 2 ++ .../core/client/filter/life.client.filter.js | 34 +++++++++++++++++++ modules/core/client/less/mt.less | 15 ++++++++ .../views/view-torrent.client.view.html | 11 ++++++ .../controllers/torrents.server.controller.js | 2 ++ .../server/models/torrent.server.model.js | 24 +++++++++++++ 8 files changed, 92 insertions(+), 1 deletion(-) diff --git a/config/env/torrents.js b/config/env/torrents.js index c4410f7b..8b0f458f 100644 --- a/config/env/torrents.js +++ b/config/env/torrents.js @@ -61,7 +61,8 @@ module.exports = { {name: 'U3/D.5', desc: 'Upload * 3, Download * 0.5'}, {name: 'U3/D.8', desc: 'Upload * 3, Download * 0.8'}, {name: 'U3/D1', desc: 'Upload * 3, Download * 1'} - ] + ], + expires: {size: 1024 * 1024 * 1024, time: 60 * 60 * 1000} }, torrentSalesValue: { global: undefined, diff --git a/modules/core/client/app/trans-string-cn.js b/modules/core/client/app/trans-string-cn.js index cd3b9f99..6bd75c0b 100644 --- a/modules/core/client/app/trans-string-cn.js +++ b/modules/core/client/app/trans-string-cn.js @@ -128,6 +128,8 @@ ATTRIBUTE_TAGS: '视频属性(标签)', VIDEO_NFO: '视频 NFO', VIDEO_SIZE: '视频文件大小', + VIDEO_SALE_INFO: '视频促销信息', + SALE_EXPIRES_TIME: '过期', UPLOAD_SUBTITLE: '上传字幕文件', SUBTITLE_LIST: '字幕列表', SUBTITLE_RULES: { diff --git a/modules/core/client/app/trans-string-en.js b/modules/core/client/app/trans-string-en.js index 9aca76c4..7f031013 100644 --- a/modules/core/client/app/trans-string-en.js +++ b/modules/core/client/app/trans-string-en.js @@ -128,6 +128,8 @@ ATTRIBUTE_TAGS: 'Video Attribute (tags)', VIDEO_NFO: 'Video NFO', VIDEO_SIZE: 'Video Size', + VIDEO_SALE_INFO: 'Video Sale Info', + SALE_EXPIRES_TIME: 'expires', UPLOAD_SUBTITLE: 'Upload Subtitle file', SUBTITLE_LIST: 'Subtitle list', SUBTITLE_RULES: { diff --git a/modules/core/client/filter/life.client.filter.js b/modules/core/client/filter/life.client.filter.js index 580d938a..cb152f8c 100644 --- a/modules/core/client/filter/life.client.filter.js +++ b/modules/core/client/filter/life.client.filter.js @@ -37,4 +37,38 @@ } }; } + + angular.module('core') + .filter('unlife', unlife); + + unlife.$inject = ['moment']; + + function unlife(moment) { + return function (expires) { + var d = moment(expires).diff(moment(), 'days'); + var h = moment(expires).diff(moment(), 'hours'); + var m = moment(expires).diff(moment(), 'minutes'); + var s = moment(expires).diff(moment(), 'seconds'); + + if (!expires) { + d = 0; + h = 0; + m = 0; + s = 0; + } + + if (d > 0) { + h = h - d * 24; + return d + 'd' + h + 'h'; + } else if (h > 0) { + m = m - h * 60; + return h + 'h' + m + 'm'; + } else if (m > 0) { + s = s - m * 60; + return m + 'm' + s + 's'; + } else { + return s + 's'; + } + }; + } }()); diff --git a/modules/core/client/less/mt.less b/modules/core/client/less/mt.less index d243932c..ea4bfaa6 100644 --- a/modules/core/client/less/mt.less +++ b/modules/core/client/less/mt.less @@ -315,6 +315,21 @@ } } +.label-sale { + color: #0366d6; + background-color: #f1f8ff; + &:hover { + cursor: pointer; + color: #f00; + } + &:active { + color: #0366d6; + } + &.used { + background-color: #c9e4ff !important; + } +} + .inline-block { display: inline-block; } diff --git a/modules/torrents/client/views/view-torrent.client.view.html b/modules/torrents/client/views/view-torrent.client.view.html index ea721314..aece5ed2 100644 --- a/modules/torrents/client/views/view-torrent.client.view.html +++ b/modules/torrents/client/views/view-torrent.client.view.html @@ -291,6 +291,17 @@
{{ 'VIDEO_SIZE' | translate}}:
{{vm.torrentLocalInfo.torrent_size | bytes:2}}
+
{{ 'VIDEO_SALE_INFO' | translate}}:
+
+ + {{vm.torrentLocalInfo.torrent_sale_status}} + + + [{{ 'SALE_EXPIRES_TIME' | translate}}: {{vm.torrentLocalInfo.torrent_sale_expires | unlife}}] + +
+
{{ 'ATTRIBUTE_TAGS' | translate}}:
diff --git a/modules/torrents/server/controllers/torrents.server.controller.js b/modules/torrents/server/controllers/torrents.server.controller.js index 423ddbf6..a3129b01 100644 --- a/modules/torrents/server/controllers/torrents.server.controller.js +++ b/modules/torrents/server/controllers/torrents.server.controller.js @@ -307,7 +307,9 @@ exports.setSaleType = function (req, res) { var torrent = req.torrent; if (req.params.saleType) { + var gbit = Math.ceil(torrent.torrent_size / config.meanTorrentConfig.torrentSalesType.expires.size); torrent.torrent_sale_status = req.params.saleType; + torrent.torrent_sale_expires = Date.now() + gbit * config.meanTorrentConfig.torrentSalesType.expires.time; torrent.save(function (err) { if (err) { diff --git a/modules/torrents/server/models/torrent.server.model.js b/modules/torrents/server/models/torrent.server.model.js index e6038d02..4f54e86e 100644 --- a/modules/torrents/server/models/torrent.server.model.js +++ b/modules/torrents/server/models/torrent.server.model.js @@ -146,6 +146,9 @@ var TorrentSchema = new Schema({ default: 'U1/D1', trim: true }, + torrent_sale_expires: { + type: Date + }, torrent_recommended: { type: Number, default: 0 @@ -170,6 +173,27 @@ var TorrentSchema = new Schema({ } }); +/** + * overwrite toJSON + */ +TorrentSchema.methods.toJSON = function (options) { + var document = this.toObject(options); + document.isSaling = false; + + if (this.torrent_sale_expires > Date.now()) { + document.isSaling = true; + } + + if (!document.isSaling) { + document.torrent_sale_status = 'U1/D1'; + } + if(document.torrent_sale_status === 'U1/D1'){ + document.isSaling=false; + } + + return document; +}; + TorrentSchema.index({user: -1, createdat: -1}); TorrentSchema.index({info_hash: -1, createdat: -1}); TorrentSchema.index({torrent_tmdb_id: -1, createdat: -1});