From 54b98c687815bfdd61491c36e3ffb18acff45f89 Mon Sep 17 00:00:00 2001 From: OldHawk Date: Sun, 3 Dec 2017 10:35:51 +0800 Subject: [PATCH] feat(torrents): list all files in torrent on torrent detail page #20 --- config/lib/common.js | 17 +++++++++++- modules/core/client/app/trans-string-en.js | 1 + modules/core/client/app/trans-string-zh.js | 1 + modules/core/client/less/mt.less | 26 +++++++++++++++++++ .../views/view-torrent.client.view.html | 9 +++++++ .../controllers/torrents.server.controller.js | 25 +++++++++++++++++- .../server/models/torrent.server.model.js | 2 +- 7 files changed, 78 insertions(+), 3 deletions(-) diff --git a/config/lib/common.js b/config/lib/common.js index 4fe6bea6..d47454d3 100644 --- a/config/lib/common.js +++ b/config/lib/common.js @@ -2,7 +2,7 @@ var querystring = require('querystring'); - /** +/** * binaryToHex * @param str */ @@ -32,3 +32,18 @@ module.exports.hexToBinary = function (str) { module.exports.querystringParse = function (q) { return querystring.parse(q, null, null, {decodeURIComponent: unescape}); }; + +/** + * fileSizeFormat + * @param bytes + * @param precision + * @returns {*} + */ +module.exports.fileSizeFormat = function (bytes, precision) { + if (bytes === 0 || isNaN(parseFloat(bytes)) || !isFinite(bytes)) return '-'; + if (typeof precision === 'undefined') precision = 1; + //var units = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB'], + var units = ['b', 'K', 'M', 'G', 'T', 'P'], + number = Math.floor(Math.log(bytes) / Math.log(1024)); + return (bytes / Math.pow(1024, Math.floor(number))).toFixed(precision) + units[number]; +}; diff --git a/modules/core/client/app/trans-string-en.js b/modules/core/client/app/trans-string-en.js index 65acd00c..bb617c89 100644 --- a/modules/core/client/app/trans-string-en.js +++ b/modules/core/client/app/trans-string-en.js @@ -287,6 +287,7 @@ TORRENT_FILENAME: 'Torrent Filename', ATTRIBUTE_TAGS: 'Video Attribute (tags)', VIDEO_NFO: 'Video NFO', + ALL_FILES_LIST: 'Files List', VIDEO_SIZE: 'Video Size', VIDEO_SALE_INFO: 'Video Sale Info', SALE_EXPIRES_TIME: 'expires', diff --git a/modules/core/client/app/trans-string-zh.js b/modules/core/client/app/trans-string-zh.js index 11537264..230ec73b 100644 --- a/modules/core/client/app/trans-string-zh.js +++ b/modules/core/client/app/trans-string-zh.js @@ -287,6 +287,7 @@ TORRENT_FILENAME: '种子文件名', ATTRIBUTE_TAGS: '视频属性(标签)', VIDEO_NFO: '视频 NFO', + ALL_FILES_LIST: '文件清单', VIDEO_SIZE: '视频文件大小', VIDEO_SALE_INFO: '视频促销信息', SALE_EXPIRES_TIME: '过期', diff --git a/modules/core/client/less/mt.less b/modules/core/client/less/mt.less index af15d605..f8a825d9 100644 --- a/modules/core/client/less/mt.less +++ b/modules/core/client/less/mt.less @@ -1363,6 +1363,32 @@ body { background-color: #fff !important; } +.all-files { + json-tree { + json-node.expandable { + &::before { + content: '\25b6'; + position: absolute; + left: 0; + top: -2px; + font-size: 10px; + transition: transform .1s ease; + } + } + .branch-preview { + max-width: 80%; + height: 2em; + } + .branch-value { + background-color: #fff; + max-height: 300px; + overflow: auto; + border: solid 1px #ccc; + border-radius: 4px; + padding: 2px 20px; + } + } +} .subtitle-list { padding-left: 0; .glyphicon { diff --git a/modules/torrents/client/views/view-torrent.client.view.html b/modules/torrents/client/views/view-torrent.client.view.html index 4819da84..3cc439d8 100644 --- a/modules/torrents/client/views/view-torrent.client.view.html +++ b/modules/torrents/client/views/view-torrent.client.view.html @@ -608,6 +608,15 @@ +
{{ 'ALL_FILES_LIST' | translate}}:
+
+
+
+ +
+
+
+
{{ 'VIDEO_NFO' | translate}}:
diff --git a/modules/torrents/server/controllers/torrents.server.controller.js b/modules/torrents/server/controllers/torrents.server.controller.js index ac052e6d..2898561f 100644 --- a/modules/torrents/server/controllers/torrents.server.controller.js +++ b/modules/torrents/server/controllers/torrents.server.controller.js @@ -6,6 +6,7 @@ var path = require('path'), config = require(path.resolve('./config/config')), mongoose = require('mongoose'), + common = require(path.resolve('./config/lib/common')), errorHandler = require(path.resolve('./modules/core/server/controllers/errors.server.controller')), multer = require('multer'), moment = require('moment'), @@ -1838,7 +1839,29 @@ exports.torrentByID = function (req, res, next, id) { } }; - async.waterfall([findTorrents, findOtherTorrents], function (err, torrent) { + var writeAllFiles = function (torrent, callback) { + var filePath = config.uploads.torrent.file.dest + torrent.torrent_filename; + nt.read(filePath, function (err, torrent_data) { + if (err) { + callback(err); + } else { + var mdata = torrent_data.metadata; + + if (mdata.info.files) { + mdata.info.files.forEach(function (f) { + torrent._all_files.push(f.path.join('/') + ', ' + common.fileSizeFormat(f.length, 2)); + }); + } else { + torrent._all_files.push(mdata.info.name + ', ' + common.fileSizeFormat(mdata.info.length, 2)); + } + + callback(null, torrent); + } + }); + + }; + + async.waterfall([findTorrents, findOtherTorrents, writeAllFiles], function (err, torrent) { if (err) { next(err); } else { diff --git a/modules/torrents/server/models/torrent.server.model.js b/modules/torrents/server/models/torrent.server.model.js index a017b724..1121124e 100644 --- a/modules/torrents/server/models/torrent.server.model.js +++ b/modules/torrents/server/models/torrent.server.model.js @@ -183,7 +183,7 @@ var TorrentSchema = new Schema({ _thumbs: [ThumbSchema], _ratings: [RatingSchema], _other_torrents: [], - + _all_files: [], //resource info resource_detail_info: Object,