mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-03-02 02:00:58 +01:00
feat(config): set config default value on render index
This commit is contained in:
2
config/env/torrents.js
vendored
2
config/env/torrents.js
vendored
@@ -16,7 +16,7 @@ module.exports = {
|
||||
*/
|
||||
app: {
|
||||
name: 'CHD.im',
|
||||
domain: 'http://chd.im:3000',
|
||||
domain: 'http://chd:3000',
|
||||
showDemoWarningPopup: true,
|
||||
cronTimeZone: 'Asia/Shanghai',
|
||||
showDebugLog: true
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
var validator = require('validator'),
|
||||
path = require('path'),
|
||||
moment = require('moment'),
|
||||
var path = require('path'),
|
||||
config = require(path.resolve('./config/config'));
|
||||
|
||||
/**
|
||||
@@ -15,6 +13,8 @@ exports.renderIndex = function (req, res) {
|
||||
req.user.addSignedIp(ip);
|
||||
}
|
||||
|
||||
setMeanTorrentConfigDefaultValue(req, res, config.meanTorrentConfig);
|
||||
|
||||
res.render('modules/core/server/views/index', {
|
||||
user: JSON.stringify(safeUserObject),
|
||||
sharedConfig: JSON.stringify(config.shared),
|
||||
@@ -28,6 +28,8 @@ exports.renderIndex = function (req, res) {
|
||||
exports.renderServerError = function (req, res) {
|
||||
var safeUserObject = req.user || null;
|
||||
|
||||
setMeanTorrentConfigDefaultValue(req, res, config.meanTorrentConfig);
|
||||
|
||||
res.status(500).render('modules/core/server/views/500', {
|
||||
user: JSON.stringify(safeUserObject),
|
||||
sharedConfig: JSON.stringify(config.shared),
|
||||
@@ -43,6 +45,8 @@ exports.renderServerError = function (req, res) {
|
||||
exports.renderNotFound = function (req, res) {
|
||||
var safeUserObject = req.user || null;
|
||||
|
||||
setMeanTorrentConfigDefaultValue(req, res, config.meanTorrentConfig);
|
||||
|
||||
res.status(404).format({
|
||||
'text/html': function () {
|
||||
res.render('modules/core/server/views/404', {
|
||||
@@ -92,3 +96,20 @@ function getSafeMeanTorrentConfig(cfg) {
|
||||
|
||||
return cfg;
|
||||
}
|
||||
|
||||
/**
|
||||
* setMeanTorrentConfigDefaultValue
|
||||
* @param cfg
|
||||
*/
|
||||
function setMeanTorrentConfigDefaultValue(req, res, cfg) {
|
||||
var httpTransport = 'http://';
|
||||
if (config.secure && config.secure.ssl === true) {
|
||||
httpTransport = 'https://';
|
||||
}
|
||||
var baseUrl = req.app.get('domain') || httpTransport + req.headers.host;
|
||||
|
||||
cfg.app.domain = baseUrl;
|
||||
if (!cfg.announce.url.startsWith('http')) {
|
||||
cfg.announce.url = baseUrl + cfg.announce.url;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ exports.upload = function (req, res) {
|
||||
} else {
|
||||
if (config.meanTorrentConfig.announce.privateTorrentCmsMode) {
|
||||
//force change announce url to config value
|
||||
var announce = appConfig.domain + config.meanTorrentConfig.announce.url;
|
||||
var announce = config.meanTorrentConfig.announce.url;
|
||||
torrent.metadata.announce = announce;
|
||||
|
||||
var cws = fs.createWriteStream(newfile);
|
||||
@@ -477,7 +477,7 @@ exports.announceEdit = function (req, res) {
|
||||
message = 'Read torrent file faild';
|
||||
reject(message);
|
||||
} else {
|
||||
var announce = appConfig.domain + config.meanTorrentConfig.announce.url;
|
||||
var announce = config.meanTorrentConfig.announce.url;
|
||||
torrent.metadata.announce = announce;
|
||||
torrent.metadata.comment = req.query.comment;
|
||||
torrent_data = torrent.metadata;
|
||||
@@ -551,7 +551,7 @@ exports.download = function (req, res) {
|
||||
reject(message);
|
||||
} else {
|
||||
if (config.meanTorrentConfig.announce.privateTorrentCmsMode) {
|
||||
var announce = appConfig.domain + config.meanTorrentConfig.announce.url + '/' + user.passkey;
|
||||
var announce = config.meanTorrentConfig.announce.url + '/' + user.passkey;
|
||||
torrent.metadata.announce = announce;
|
||||
}
|
||||
torrent_data = torrent.metadata;
|
||||
|
||||
Reference in New Issue
Block a user