From c9a67c137d3266b1b4e7b29da1edb2136ce37085 Mon Sep 17 00:00:00 2001 From: OldHawk Date: Fri, 14 Jul 2017 23:37:06 +0800 Subject: [PATCH] feat(core): meanTorrent support public tracker torrents CMS --- README.md | 5 ++- config/env/torrents.js | 3 +- .../client/templates/upload-rules-en.md | 2 +- .../client/templates/upload-rules-zh.md | 2 +- .../controllers/torrents.server.controller.js | 33 ++++++------------- 5 files changed, 18 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 7d95c840..85e67b34 100644 --- a/README.md +++ b/README.md @@ -193,10 +193,13 @@ such as: announce_prefix: '[CHD.im].', admin: 'admin@chd.im', base_url: 'http://chd.im', - client_black_list_url: 'http://chd.im/client_black_list' + client_black_list_url: 'http://chd.im/client_black_list', + private_torrent_cms: true }, ``` meanTorrent tracker is private, please set the `announce.url` to your server url, then when user to upload torrent file, It will autocheck the torrent announce url whether matching as `announce.url`. +But, meanTorrent support public tracker torrents CMS mode with `private_torrent_cms` set to `false`, in `private` mode, user can upload and download public tracker torrent files, but these torrent files is can not +used by meanTorrent tracker server. ```javascript tmdbConfig: { diff --git a/config/env/torrents.js b/config/env/torrents.js index dc272bd2..c78ae45d 100644 --- a/config/env/torrents.js +++ b/config/env/torrents.js @@ -17,7 +17,8 @@ module.exports = { announce_prefix: '[CHD.im].', admin: 'admin@chd.im', base_url: 'http://chd.im:3000', - client_black_list_url: 'http://chd.im:3000/client_black_list' + client_black_list_url: 'http://chd.im:3000/client_black_list', + private_torrent_cms: true }, sign: { open_signin: true, diff --git a/modules/torrents/client/templates/upload-rules-en.md b/modules/torrents/client/templates/upload-rules-en.md index 34cd33ad..d7be19fa 100644 --- a/modules/torrents/client/templates/upload-rules-en.md +++ b/modules/torrents/client/templates/upload-rules-en.md @@ -1,4 +1,4 @@ -1. The torrent file tracker URL must be: __{{vm.announceConfig.url}}__. +1. If this is a private torrents management system, the torrent file announce URL must be: __{{vm.announceConfig.url}}__. 1. If you selected resource type with `Movie` or `TVSerial`, the torrent TMDB_ID must be `TheMovieDB` resources ID, you can [find the ID from here]({{vm.tmdbConfig.tmdb_home}}), then the resources detail info can be autoload, if everything looks good, hit submit. 1. Select one or more tags that match the resources, which will play a significant role in your search results. diff --git a/modules/torrents/client/templates/upload-rules-zh.md b/modules/torrents/client/templates/upload-rules-zh.md index 46fa5a5a..7e2f1166 100644 --- a/modules/torrents/client/templates/upload-rules-zh.md +++ b/modules/torrents/client/templates/upload-rules-zh.md @@ -1,4 +1,4 @@ -1. 种子文件的Tracker地址必须为:__{{vm.announceConfig.url}}__. +1. 如果这是私有种子管理系统,种子文件的Announce地址必须为:__{{vm.announceConfig.url}}__. 1. 如果你选择的资源类型为`电影`或`电视剧`,种子文件的 TMDB_ID 必须是 `TheMovieDB` 相对应的资源ID号, 您可以[从这里找到ID号]({{vm.tmdbConfig.tmdb_home}}). 资源的详细信息,系统会自动载入,如无误可直接提交. 1. 请为资源选择匹配的一个或多个标签,它会在您的搜索结果中发挥重大作用. diff --git a/modules/torrents/server/controllers/torrents.server.controller.js b/modules/torrents/server/controllers/torrents.server.controller.js index 0c436a31..44908bce 100644 --- a/modules/torrents/server/controllers/torrents.server.controller.js +++ b/modules/torrents/server/controllers/torrents.server.controller.js @@ -142,11 +142,13 @@ exports.upload = function (req, res) { message = 'Read torrent file faild'; reject(message); } else { - if (torrent.metadata.announce !== config.meanTorrentConfig.announce.url) { - console.log(torrent.metadata.announce); - message = 'ANNOUNCE_URL_ERROR'; + if (config.meanTorrentConfig.announce.private_torrent_cms) { + if (torrent.metadata.announce !== config.meanTorrentConfig.announce.url) { + console.log(torrent.metadata.announce); + message = 'ANNOUNCE_URL_ERROR'; - reject(message); + reject(message); + } } torrentinfo = torrent.metadata; torrentinfo.info_hash = torrent.infoHash(); @@ -305,28 +307,11 @@ exports.download = function (req, res) { if (exists) { getTorrentFileData(filePath) .then(function () { - //var options = { - // root: path.join(__dirname, '../../../../'), - // headers: { - // 'Content-Type': 'application/x-bittorrent', - // 'Content-Disposition': 'attachment; filename=' + config.meanTorrentConfig.announce.announce_prefix + req.torrent.torrent_filename, - // 'Content-Length': stat.size - // } - //}; - //res.sendFile(filePath, options); - res.set('Content-Type', 'application/x-bittorrent'); res.set('Content-Disposition', 'attachment; filename=' + config.meanTorrentConfig.announce.announce_prefix + req.torrent.torrent_filename); res.set('Content-Length', stat.size); res.send(benc.encode(torrent_data)); - - //res.writeHead(200, { - // 'Content-Type': 'application/octet-stream', - // 'Content-Disposition': 'attachment; filename=' + config.meanTorrentConfig.announce.announce_prefix + req.torrent.torrent_filename, - // 'Content-Length': stat.size - //}); - //fs.createReadStream(filePath).pipe(res); }) .catch(function (err) { res.status(422).send(err); @@ -347,8 +332,10 @@ exports.download = function (req, res) { message = 'Read torrent file faild'; reject(message); } else { - var announce = config.meanTorrentConfig.announce.url + '/' + req.user.passkey; - torrent.metadata.announce = announce; + if (config.meanTorrentConfig.announce.private_torrent_cms) { + var announce = config.meanTorrentConfig.announce.url + '/' + req.user.passkey; + torrent.metadata.announce = announce; + } torrent_data = torrent.metadata; resolve(); }