Files
NodeBB/src/controllers/admin/settings.js

66 lines
1.5 KiB
JavaScript
Raw Normal View History

2015-09-17 16:25:15 -04:00
'use strict';
2016-10-31 13:52:26 +03:00
var async = require('async');
var nconf = require('nconf');
2016-10-31 13:52:26 +03:00
var meta = require('../../meta');
var settingsController = module.exports;
2015-09-17 16:25:15 -04:00
settingsController.get = function (req, res, next) {
2015-09-17 16:25:15 -04:00
var term = req.params.term ? req.params.term : 'general';
switch (req.params.term) {
2017-02-18 02:38:03 -07:00
case 'email':
renderEmail(req, res, next);
break;
2017-02-18 02:38:03 -07:00
default:
res.render('admin/settings/' + term);
}
2015-09-17 16:25:15 -04:00
};
function renderEmail(req, res, next) {
var fs = require('fs');
var path = require('path');
var file = require('../../file');
var emailsPath = path.join(nconf.get('views_dir'), 'emails');
2016-08-16 19:46:59 +02:00
2016-10-31 13:52:26 +03:00
async.waterfall([
function (next) {
file.walk(emailsPath, next);
2016-10-31 13:52:26 +03:00
},
function (emails, next) {
async.map(emails, function (email, next) {
var path = email.replace(emailsPath, '').substr(1).replace('.tpl', '');
2017-06-22 19:03:49 -04:00
async.waterfall([
function (next) {
fs.readFile(email, next);
},
function (original, next) {
var text = meta.config['email:custom:' + path] ? meta.config['email:custom:' + path] : original.toString();
2016-08-16 19:46:59 +02:00
2017-06-22 19:03:49 -04:00
next(null, {
path: path,
fullpath: email,
text: text,
original: original.toString(),
});
},
], next);
2016-10-31 13:52:26 +03:00
}, next);
2017-02-17 19:31:21 -07:00
},
2017-06-22 19:03:49 -04:00
function (emails) {
res.render('admin/settings/email', {
emails: emails,
sendable: emails.filter(function (email) {
return email.path.indexOf('_plaintext') === -1 && email.path.indexOf('partials') === -1;
}),
});
},
], next);
}