mailtrain/server/routes/rest/editors.js
Tomas Bures 66702b5edc Fixes in reports (generating a CSV).
Added caching of generated images in mosaico handler.
Various other fixes.
2019-04-22 02:41:40 +02:00

25 lines
739 B
JavaScript

'use strict';
const passport = require('../../lib/passport');
const bluebird = require('bluebird');
const premailerApi = require('premailer-api');
const premailerPrepareAsync = bluebird.promisify(premailerApi.prepare.bind(premailerApi));
const router = require('../../lib/router-async').create();
router.postAsync('/html-to-text', passport.loggedIn, passport.csrfProtection, async (req, res) => {
if (!req.body.html) {
return res.json({text: ''}); // Premailer crashes very hard when html is empty
}
const email = await premailerPrepareAsync({
html: req.body.html,
fetchHTML: false
});
res.json({text: email.text.replace(/%5B/g, '[').replace(/%5D/g, ']')});
});
module.exports = router;