2017-03-10 08:59:25 +00:00
|
|
|
|
'use strict';
|
|
|
|
|
|
2018-02-25 19:54:15 +00:00
|
|
|
|
const config = require('config');
|
|
|
|
|
const router = require('../lib/router-async').create();
|
|
|
|
|
const passport = require('../lib/passport');
|
|
|
|
|
const clientHelpers = require('../lib/client-helpers');
|
2017-03-10 08:59:25 +00:00
|
|
|
|
|
2018-02-25 19:54:15 +00:00
|
|
|
|
const bluebird = require('bluebird');
|
|
|
|
|
const fsReadFile = bluebird.promisify(require('fs').readFile);
|
|
|
|
|
|
|
|
|
|
const path = require('path');
|
|
|
|
|
|
|
|
|
|
// FIXME - add authentication by sandboxToken
|
2017-03-10 08:59:25 +00:00
|
|
|
|
|
2018-02-25 19:54:15 +00:00
|
|
|
|
|
|
|
|
|
router.getAsync('/editor', passport.csrfProtection, async (req, res) => {
|
|
|
|
|
const resourceType = req.query.type;
|
|
|
|
|
const resourceId = req.query.id;
|
|
|
|
|
|
|
|
|
|
const mailtrainConfig = await clientHelpers.getAnonymousConfig(req.context);
|
|
|
|
|
|
|
|
|
|
let languageStrings = null;
|
|
|
|
|
if (config.language && config.language !== 'en') {
|
|
|
|
|
const lang = config.language.split('_')[0];
|
|
|
|
|
try {
|
|
|
|
|
const file = path.join(__dirname, '..', 'client', 'public', 'mosaico', 'lang', 'mosaico-' + lang + '.json');
|
|
|
|
|
languageStrings = await fsReadFile(file, 'utf8');
|
|
|
|
|
} catch (err) {
|
2017-03-10 08:59:25 +00:00
|
|
|
|
}
|
2018-02-25 19:54:15 +00:00
|
|
|
|
}
|
2017-03-10 08:59:25 +00:00
|
|
|
|
|
2018-02-25 19:54:15 +00:00
|
|
|
|
/* ????
|
2017-03-10 12:14:38 +00:00
|
|
|
|
resource.editorName = resource.editorName || 'mosaico';
|
|
|
|
|
resource.editorData = !resource.editorData ?
|
|
|
|
|
{
|
|
|
|
|
template: req.query.template || 'versafix-1'
|
|
|
|
|
} :
|
|
|
|
|
JSON.parse(resource.editorData);
|
2018-02-25 19:54:15 +00:00
|
|
|
|
*/
|
2017-03-10 08:59:25 +00:00
|
|
|
|
|
2018-02-25 19:54:15 +00:00
|
|
|
|
res.render('mosaico/root', {
|
|
|
|
|
layout: 'mosaico/layout',
|
|
|
|
|
editorConfig: config.mosaico,
|
|
|
|
|
languageStrings: languageStrings,
|
|
|
|
|
reactCsrfToken: req.csrfToken(),
|
|
|
|
|
mailtrainConfig: JSON.stringify(mailtrainConfig)
|
2017-03-10 08:59:25 +00:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
module.exports = router;
|