feat(config): set config default value on render index

This commit is contained in:
OldHawk
2017-12-29 14:30:28 +08:00
parent 11635470bc
commit a006695f14
3 changed files with 16 additions and 10 deletions

View File

@@ -16,7 +16,7 @@ module.exports = {
*/
app: {
name: 'CHD.im',
domain: 'http://chd:3000',
domain: 'http://chd.im:3000',
showDemoWarningPopup: true,
cronTimeZone: 'Asia/Shanghai',
showDebugLog: true

View File

@@ -13,12 +13,13 @@ exports.renderIndex = function (req, res) {
req.user.addSignedIp(ip);
}
setMeanTorrentConfigDefaultValue(req, res, config.meanTorrentConfig);
var cfg = setMeanTorrentConfigDefaultValue(req, res, config.meanTorrentConfig);
cfg = getSafeMeanTorrentConfig(cfg);
res.render('modules/core/server/views/index', {
user: JSON.stringify(safeUserObject),
sharedConfig: JSON.stringify(config.shared),
meanTorrentConfig: JSON.stringify(getSafeMeanTorrentConfig(config.meanTorrentConfig))
meanTorrentConfig: JSON.stringify(cfg)
});
};
@@ -28,12 +29,13 @@ exports.renderIndex = function (req, res) {
exports.renderServerError = function (req, res) {
var safeUserObject = req.user || null;
setMeanTorrentConfigDefaultValue(req, res, config.meanTorrentConfig);
var cfg = setMeanTorrentConfigDefaultValue(req, res, config.meanTorrentConfig);
cfg = getSafeMeanTorrentConfig(cfg);
res.status(500).render('modules/core/server/views/500', {
user: JSON.stringify(safeUserObject),
sharedConfig: JSON.stringify(config.shared),
meanTorrentConfig: JSON.stringify(getSafeMeanTorrentConfig(config.meanTorrentConfig)),
meanTorrentConfig: JSON.stringify(cfg),
error: 'Oops! Something went wrong...'
});
};
@@ -45,14 +47,15 @@ exports.renderServerError = function (req, res) {
exports.renderNotFound = function (req, res) {
var safeUserObject = req.user || null;
setMeanTorrentConfigDefaultValue(req, res, config.meanTorrentConfig);
var cfg = setMeanTorrentConfigDefaultValue(req, res, config.meanTorrentConfig);
cfg = getSafeMeanTorrentConfig(cfg);
res.status(404).format({
'text/html': function () {
res.render('modules/core/server/views/404', {
user: JSON.stringify(safeUserObject),
sharedConfig: JSON.stringify(config.shared),
meanTorrentConfig: JSON.stringify(getSafeMeanTorrentConfig(config.meanTorrentConfig)),
meanTorrentConfig: JSON.stringify(cfg),
url: req.originalUrl
});
},
@@ -109,7 +112,10 @@ function setMeanTorrentConfigDefaultValue(req, res, cfg) {
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;
if (!cfg.announce.abs) {
cfg.announce.abs = cfg.announce.url;
}
cfg.announce.url = baseUrl + cfg.announce.abs;
return cfg;
}

View File

@@ -57,7 +57,7 @@
vm.tFile = undefined;
var contentDisposition = res.headers('Content-Disposition');
var fileName = decodeURI(contentDisposition.substr(contentDisposition.indexOf('filename=') + 9));
var fileName = decodeURI(contentDisposition.substr(contentDisposition.indexOf('filename*=UTF-8\'\'') + 17));
FileSaver.saveAs(res.data, fileName);
}