Update API call to remove premailer
This commit is contained in:
parent
1b8eb33979
commit
d47159d47b
1 changed files with 3 additions and 12 deletions
|
@ -3,23 +3,14 @@
|
||||||
const passport = require('../../lib/passport');
|
const passport = require('../../lib/passport');
|
||||||
|
|
||||||
const bluebird = require('bluebird');
|
const bluebird = require('bluebird');
|
||||||
const premailerApi = require('premailer-api');
|
const htmlToText = require('html-to-text');
|
||||||
const premailerPrepareAsync = bluebird.promisify(premailerApi.prepare.bind(premailerApi));
|
|
||||||
|
|
||||||
const router = require('../../lib/router-async').create();
|
const router = require('../../lib/router-async').create();
|
||||||
|
|
||||||
router.postAsync('/html-to-text', passport.loggedIn, passport.csrfProtection, async (req, res) => {
|
router.postAsync('/html-to-text', passport.loggedIn, passport.csrfProtection, async (req, res) => {
|
||||||
if (!req.body.html) {
|
const email = htmlToText.fromString(req.body.html, {wordwrap: 130});
|
||||||
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, ']')});
|
|
||||||
|
|
||||||
|
res.json({text: email});
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|
Loading…
Reference in a new issue