applied some code style changes

This commit is contained in:
Andris Reinman 2017-03-10 14:14:38 +02:00
parent e34e07f61e
commit 020a77c78f
7 changed files with 196 additions and 126 deletions

View file

@ -8,7 +8,7 @@ msgstr ""
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n" "Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2017-03-10 08:57+0000\n" "POT-Creation-Date: 2017-03-10 12:12+0000\n"
#: views/archive/layout.hbs:1 #: views/archive/layout.hbs:1
#: views/layout.hbs:1 #: views/layout.hbs:1
@ -1773,7 +1773,7 @@ msgstr ""
#: views/lists/subscription/edit.hbs:6 #: views/lists/subscription/edit.hbs:6
#: views/lists/subscription/import-preview.hbs:6 #: views/lists/subscription/import-preview.hbs:6
#: views/subscription/unsubscribe.hbs:3 #: views/subscription/unsubscribe.hbs:3
#: lib/helpers.js:26 #: lib/helpers.js:25
#: lib/models/segments.js:11 #: lib/models/segments.js:11
msgid "Email address" msgid "Email address"
msgstr "" msgstr ""
@ -2969,7 +2969,7 @@ msgid "Could not find template with specified ID"
msgstr "" msgstr ""
#: lib/editor-helpers.js:32 #: lib/editor-helpers.js:32
#: routes/archive.js:140 #: routes/archive.js:142
#: routes/campaigns.js:131 #: routes/campaigns.js:131
#: routes/campaigns.js:295 #: routes/campaigns.js:295
#: routes/campaigns.js:390 #: routes/campaigns.js:390
@ -2984,7 +2984,7 @@ msgid "Could not find campaign with specified ID"
msgstr "" msgstr ""
#: lib/editor-helpers.js:46 #: lib/editor-helpers.js:46
#: routes/editorapi.js:276 #: routes/editorapi.js:308
msgid "Invalid resource type" msgid "Invalid resource type"
msgstr "" msgstr ""
@ -2992,41 +2992,41 @@ msgstr ""
msgid "Bad status code %s" msgid "Bad status code %s"
msgstr "" msgstr ""
#: lib/helpers.js:17 #: lib/helpers.js:16
msgid "URL that points to the unsubscribe page" msgid "URL that points to the unsubscribe page"
msgstr "" msgstr ""
#: lib/helpers.js:20 #: lib/helpers.js:19
msgid "URL that points to the preferences page of the subscriber" msgid "URL that points to the preferences page of the subscriber"
msgstr "" msgstr ""
#: lib/helpers.js:23 #: lib/helpers.js:22
msgid "URL to preview the message in a browser" msgid "URL to preview the message in a browser"
msgstr "" msgstr ""
#: lib/helpers.js:29 #: lib/helpers.js:28
#: lib/models/segments.js:31 #: lib/models/segments.js:31
msgid "First name" msgid "First name"
msgstr "" msgstr ""
#: lib/helpers.js:32 #: lib/helpers.js:31
#: lib/models/segments.js:35 #: lib/models/segments.js:35
msgid "Last name" msgid "Last name"
msgstr "" msgstr ""
#: lib/helpers.js:35 #: lib/helpers.js:34
msgid "Full name (first and last name combined)" msgid "Full name (first and last name combined)"
msgstr "" msgstr ""
#: lib/helpers.js:38 #: lib/helpers.js:37
msgid "Unique ID that identifies the recipient" msgid "Unique ID that identifies the recipient"
msgstr "" msgstr ""
#: lib/helpers.js:41 #: lib/helpers.js:40
msgid "Unique ID that identifies the list used for this campaign" msgid "Unique ID that identifies the list used for this campaign"
msgstr "" msgstr ""
#: lib/helpers.js:44 #: lib/helpers.js:43
msgid "Unique ID that identifies current campaign" msgid "Unique ID that identifies current campaign"
msgstr "" msgstr ""
@ -3465,18 +3465,18 @@ msgstr ""
msgid "Not Found" msgid "Not Found"
msgstr "" msgstr ""
#: routes/archive.js:116 #: routes/archive.js:118
#: services/sender.js:451 #: services/sender.js:451
msgid "Received status code %s from %s" msgid "Received status code %s from %s"
msgstr "" msgstr ""
#: routes/archive.js:148 #: routes/archive.js:150
#: routes/campaigns.js:789 #: routes/campaigns.js:789
msgid "Attachment not found" msgid "Attachment not found"
msgstr "" msgstr ""
#: routes/campaigns.js:26 #: routes/campaigns.js:26
#: routes/editorapi.js:33 #: routes/editorapi.js:35
#: routes/fields.js:13 #: routes/fields.js:13
#: routes/grapejs.js:13 #: routes/grapejs.js:13
#: routes/lists.js:49 #: routes/lists.js:49
@ -3606,16 +3606,16 @@ msgstr ""
msgid "Could not delete attachment" msgid "Could not delete attachment"
msgstr "" msgstr ""
#: routes/editorapi.js:39 #: routes/editorapi.js:41
msgid "Invalid editor name" msgid "Invalid editor name"
msgstr "" msgstr ""
#: routes/editorapi.js:220 #: routes/editorapi.js:237
#: routes/editorapi.js:246 #: routes/editorapi.js:275
msgid "Method not supported" msgid "Method not supported"
msgstr "" msgstr ""
#: routes/editorapi.js:316 #: routes/editorapi.js:352
msgid "Invalid resource type or ID" msgid "Invalid resource type or ID"
msgstr "" msgstr ""

View file

@ -11,39 +11,37 @@ module.exports = {
function getDefaultMergeTags(callback) { function getDefaultMergeTags(callback) {
// Using a callback for the sake of future-proofness // Using a callback for the sake of future-proofness
callback(null, [ callback(null, [{
{ key: 'LINK_UNSUBSCRIBE',
key: 'LINK_UNSUBSCRIBE', value: _('URL that points to the unsubscribe page')
value: _('URL that points to the unsubscribe page') }, {
}, { key: 'LINK_PREFERENCES',
key: 'LINK_PREFERENCES', value: _('URL that points to the preferences page of the subscriber')
value: _('URL that points to the preferences page of the subscriber') }, {
}, { key: 'LINK_BROWSER',
key: 'LINK_BROWSER', value: _('URL to preview the message in a browser')
value: _('URL to preview the message in a browser') }, {
}, { key: 'EMAIL',
key: 'EMAIL', value: _('Email address')
value: _('Email address') }, {
}, { key: 'FIRST_NAME',
key: 'FIRST_NAME', value: _('First name')
value: _('First name') }, {
}, { key: 'LAST_NAME',
key: 'LAST_NAME', value: _('Last name')
value: _('Last name') }, {
}, { key: 'FULL_NAME',
key: 'FULL_NAME', value: _('Full name (first and last name combined)')
value: _('Full name (first and last name combined)') }, {
}, { key: 'SUBSCRIPTION_ID',
key: 'SUBSCRIPTION_ID', value: _('Unique ID that identifies the recipient')
value: _('Unique ID that identifies the recipient') }, {
}, { key: 'LIST_ID',
key: 'LIST_ID', value: _('Unique ID that identifies the list used for this campaign')
value: _('Unique ID that identifies the list used for this campaign') }, {
}, { key: 'CAMPAIGN_ID',
key: 'CAMPAIGN_ID', value: _('Unique ID that identifies current campaign')
value: _('Unique ID that identifies current campaign') }]);
}
]);
} }
function getListMergeTags(listId, callback) { function getListMergeTags(listId, callback) {

View file

@ -230,7 +230,7 @@ module.exports.addConfirmation = (list, email, optInIp, data, callback) => {
name: [].concat(data.firstName || []).concat(data.lastName || []).join(' '), name: [].concat(data.firstName || []).concat(data.lastName || []).join(' '),
address: email address: email
}, },
subject: util.format(_('%s: Please Confirm Subscription'),list.name), subject: util.format(_('%s: Please Confirm Subscription'), list.name),
encryptionKeys encryptionKeys
}, { }, {
html: 'emails/confirm-html.hbs', html: 'emails/confirm-html.hbs',

View file

@ -77,7 +77,9 @@ router.get('/:campaign/:list/:subscription', passport.csrfProtection, (req, res,
}; };
if (campaign.editorName && campaign.editorName !== 'summernote' && campaign.editorName !== 'codeeditor') { if (campaign.editorName && campaign.editorName !== 'summernote' && campaign.editorName !== 'codeeditor') {
res.render('partials/tracking-scripts', { layout: 'archive/layout-raw' }, (err, scripts) => { res.render('partials/tracking-scripts', {
layout: 'archive/layout-raw'
}, (err, scripts) => {
html = scripts ? html.replace(/<\/body\b/i, match => scripts + match) : html; html = scripts ? html.replace(/<\/body\b/i, match => scripts + match) : html;
render('archive/view-raw', 'archive/layout-raw'); render('archive/view-raw', 'archive/layout-raw');
}); });

View file

@ -17,7 +17,9 @@ let multiparty = require('multiparty');
let fileType = require('file-type'); let fileType = require('file-type');
let escapeStringRegexp = require('escape-string-regexp'); let escapeStringRegexp = require('escape-string-regexp');
let jqueryFileUpload = require('jquery-file-upload-middleware'); let jqueryFileUpload = require('jquery-file-upload-middleware');
let gm = require('gm').subClass({ imageMagick: true }); let gm = require('gm').subClass({
imageMagick: true
});
let url = require('url'); let url = require('url');
let htmlToText = require('html-to-text'); let htmlToText = require('html-to-text');
let premailerApi = require('premailer-api'); let premailerApi = require('premailer-api');
@ -68,7 +70,11 @@ let listImages = (dir, dirURL, callback) => {
}); });
}; };
let getStaticImageUrl = ({ dynamicUrl, staticDir, staticDirUrl }, callback) => { let getStaticImageUrl = ({
dynamicUrl,
staticDir,
staticDirUrl
}, callback) => {
mkdirp(staticDir, err => { mkdirp(staticDir, err => {
if (err) { if (err) {
return callback(dynamicUrl); return callback(dynamicUrl);
@ -94,33 +100,36 @@ let getStaticImageUrl = ({ dynamicUrl, staticDir, staticDirUrl }, callback) => {
} }
fetch(dynamicUrl, { fetch(dynamicUrl, {
headers headers
}) })
.then(res => { .then(res => {
return res.buffer(); return res.buffer();
}) })
.then(buffer => { .then(buffer => {
let ft = fileType(buffer); let ft = fileType(buffer);
if (!ft) { if (!ft) {
return callback(dynamicUrl); return callback(dynamicUrl);
} }
if (['image/jpeg', 'image/png', 'image/gif'].includes(ft.mime)) { if (['image/jpeg', 'image/png', 'image/gif'].includes(ft.mime)) {
fs.writeFile(path.join(staticDir, hash + '.' + ft.ext), buffer, err => { fs.writeFile(path.join(staticDir, hash + '.' + ft.ext), buffer, err => {
if (err) { if (err) {
return callback(dynamicUrl); return callback(dynamicUrl);
} }
let staticUrl = staticDirUrl + '/' + hash + '.' + ft.ext; let staticUrl = staticDirUrl + '/' + hash + '.' + ft.ext;
callback(staticUrl); callback(staticUrl);
}); });
} else { } else {
callback(dynamicUrl); callback(dynamicUrl);
} }
}); });
}); });
}); });
}; };
let prepareHtml = ({ editorName, html }, callback) => { let prepareHtml = ({
editorName,
html
}, callback) => {
settings.get('serviceUrl', (err, serviceUrl) => { settings.get('serviceUrl', (err, serviceUrl) => {
if (err) { if (err) {
return callback(err.message || err); return callback(err.message || err);
@ -163,7 +172,10 @@ let prepareHtml = ({ editorName, html }, callback) => {
}); });
}; };
let placeholderImage = (req, res, { width, height }) => { let placeholderImage = (req, res, {
width,
height
}) => {
let magick = gm(width, height, '#707070'); let magick = gm(width, height, '#707070');
let x = 0; let x = 0;
let y = 0; let y = 0;
@ -190,7 +202,12 @@ let placeholderImage = (req, res, { width, height }) => {
magick.stream('png').pipe(res); magick.stream('png').pipe(res);
}; };
let resizedImage = (req, res, { src, method, width, height }) => { let resizedImage = (req, res, {
src,
method,
width,
height
}) => {
let magick = gm(src); let magick = gm(src);
magick.format((err, format) => { magick.format((err, format) => {
if (err) { if (err) {
@ -229,19 +246,31 @@ router.get('/img', passport.csrfProtection, (req, res) => {
return res.status(500).send(err.message || err); return res.status(500).send(err.message || err);
} }
let { src, method, params = '600,null' } = req.query; let {
let width = params.split(',')[0]; src,
method,
params = '600,null'
} = req.query;
let width = params.split(',')[0];
let height = params.split(',')[1]; let height = params.split(',')[1];
width = (width === 'null') ? null : Number(width); width = (width === 'null') ? null : Number(width);
height = (height === 'null') ? null : Number(height); height = (height === 'null') ? null : Number(height);
switch (method) { switch (method) {
case 'placeholder': case 'placeholder':
return placeholderImage(req, res, { width, height }); return placeholderImage(req, res, {
width,
height
});
case 'resize': case 'resize':
case 'cover': case 'cover':
src = /^https?:\/\/|^\/\//i.test(src) ? src : url.resolve(serviceUrl, src); src = /^https?:\/\/|^\/\//i.test(src) ? src : url.resolve(serviceUrl, src);
return resizedImage(req, res, { src, method, width, height }); return resizedImage(req, res, {
src,
method,
width,
height
});
default: default:
return res.status(501).send(_('Method not supported')); return res.status(501).send(_('Method not supported'));
} }
@ -249,7 +278,10 @@ router.get('/img', passport.csrfProtection, (req, res) => {
}); });
router.post('/update', passport.parseForm, passport.csrfProtection, (req, res) => { router.post('/update', passport.parseForm, passport.csrfProtection, (req, res) => {
prepareHtml({ editorName: req.query.editor, html: req.body.html }, (err, html) => { prepareHtml({
editorName: req.query.editor,
html: req.body.html
}, (err, html) => {
if (err) { if (err) {
return res.status(500).send(err.message || err); return res.status(500).send(err.message || err);
} }
@ -297,20 +329,24 @@ router.get('/upload', passport.csrfProtection, (req, res) => {
if (req.query.type === 'campaign' && Number(req.query.id) > 0) { if (req.query.type === 'campaign' && Number(req.query.id) > 0) {
listImages(path.join(baseDir, req.query.id), baseDirUrl + '/' + req.query.id, (err, campaignImages) => { listImages(path.join(baseDir, req.query.id), baseDirUrl + '/' + req.query.id, (err, campaignImages) => {
err ? res.status(500).send(err.message || err) err ? res.status(500).send(err.message || err) :
: res.json({ files: sharedImages.concat(campaignImages) }); res.json({
files: sharedImages.concat(campaignImages)
});
}); });
} else { } else {
res.json({ files: sharedImages }); res.json({
files: sharedImages
});
} }
}); });
}); });
}); });
router.post('/upload', passport.csrfProtection, (req, res) => { router.post('/upload', passport.csrfProtection, (req, res) => {
let dirName = req.query.type === 'template' ? '0' let dirName = req.query.type === 'template' ? '0' :
: req.query.type === 'campaign' && Number(req.query.id) > 0 ? req.query.id req.query.type === 'campaign' && Number(req.query.id) > 0 ? req.query.id :
: null; null;
if (dirName === null) { if (dirName === null) {
return res.status(500).send(_('Invalid resource type or ID')); return res.status(500).send(_('Invalid resource type or ID'));
@ -318,10 +354,15 @@ router.post('/upload', passport.csrfProtection, (req, res) => {
let opts = { let opts = {
tmpDir: config.www.tmpdir || os.tmpdir(), tmpDir: config.www.tmpdir || os.tmpdir(),
imageVersions: req.query.editor === 'mosaico' ? { thumbnail: { width: 90, height: 90 } } : {}, imageVersions: req.query.editor === 'mosaico' ? {
thumbnail: {
width: 90,
height: 90
}
} : {},
uploadDir: path.join(__dirname, '..', 'public', req.query.editor, 'uploads', dirName), uploadDir: path.join(__dirname, '..', 'public', req.query.editor, 'uploads', dirName),
uploadUrl: '/' + req.query.editor + '/uploads/' + dirName, // must be root relative uploadUrl: '/' + req.query.editor + '/uploads/' + dirName, // must be root relative
acceptFileTypes:/(\.|\/)(gif|jpe?g|png)$/i, acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
}; };
let mockres = httpMocks.createResponse({ let mockres = httpMocks.createResponse({
@ -332,9 +373,13 @@ router.post('/upload', passport.csrfProtection, (req, res) => {
if (req.query.editor === 'grapejs') { if (req.query.editor === 'grapejs') {
let data = []; let data = [];
JSON.parse(mockres._getData()).files.forEach(file => { JSON.parse(mockres._getData()).files.forEach(file => {
data.push({ src: file.url }); data.push({
src: file.url
});
});
res.json({
data
}); });
res.json({ data });
} else { } else {
res.send(mockres._getData()); res.send(mockres._getData());
} }
@ -344,7 +389,10 @@ router.post('/upload', passport.csrfProtection, (req, res) => {
}); });
router.post('/download', passport.csrfProtection, (req, res) => { router.post('/download', passport.csrfProtection, (req, res) => {
prepareHtml({ editorName: req.query.editor, html: req.body.html }, (err, html) => { prepareHtml({
editorName: req.query.editor,
html: req.body.html
}, (err, html) => {
if (err) { if (err) {
return res.status(500).send(err.message || err); return res.status(500).send(err.message || err);
} }
@ -369,27 +417,36 @@ let parseGrapejsMultipartTestForm = (req, res, next) => {
}; };
router.post('/test', parseGrapejsMultipartTestForm, passport.csrfProtection, (req, res) => { router.post('/test', parseGrapejsMultipartTestForm, passport.csrfProtection, (req, res) => {
prepareHtml({ editorName: req.query.editor, html: req.body.html }, (err, html) => { prepareHtml({
editorName: req.query.editor,
html: req.body.html
}, (err, html) => {
if (err) { if (err) {
req.query.editor === 'grapejs' req.query.editor === 'grapejs' ?
? res.status(500).json({ errors: err.message || err }) res.status(500).json({
: res.status(500).send(err.message || err); errors: err.message || err
}) :
res.status(500).send(err.message || err);
return; return;
} }
settings.list(['defaultAddress', 'defaultFrom'], (err, configItems) => { settings.list(['defaultAddress', 'defaultFrom'], (err, configItems) => {
if (err) { if (err) {
req.query.editor === 'grapejs' req.query.editor === 'grapejs' ?
? res.status(500).json({ errors: err.message || err }) res.status(500).json({
: res.status(500).send(err.message || err); errors: err.message || err
}) :
res.status(500).send(err.message || err);
return; return;
} }
mailer.getMailer((err, transport) => { mailer.getMailer((err, transport) => {
if (err) { if (err) {
req.query.editor === 'grapejs' req.query.editor === 'grapejs' ?
? res.status(500).json({ errors: err.message || err }) res.status(500).json({
: res.status(500).send(err.message || err); errors: err.message || err
}) :
res.status(500).send(err.message || err);
return; return;
} }
@ -400,21 +457,27 @@ router.post('/test', parseGrapejsMultipartTestForm, passport.csrfProtection, (re
}, },
to: req.body.email, to: req.body.email,
subject: req.body.subject, subject: req.body.subject,
text: htmlToText.fromString(html, { wordwrap: 100 }), text: htmlToText.fromString(html, {
wordwrap: 100
}),
html, html,
}; };
transport.sendMail(opts, (err, info) => { transport.sendMail(opts, (err, info) => {
if (err) { if (err) {
req.query.editor === 'grapejs' req.query.editor === 'grapejs' ?
? res.status(500).json({ errors: err.message || err }) res.status(500).json({
: res.status(500).send(err.message || err); errors: err.message || err
}) :
res.status(500).send(err.message || err);
return; return;
} }
req.query.editor === 'grapejs' req.query.editor === 'grapejs' ?
? res.json({ data: 'ok' }) res.json({
: res.send('ok'); data: 'ok'
}) :
res.send('ok');
}); });
}); });
}); });
@ -422,7 +485,10 @@ router.post('/test', parseGrapejsMultipartTestForm, passport.csrfProtection, (re
}); });
router.post('/html-to-text', passport.parseForm, passport.csrfProtection, (req, res) => { router.post('/html-to-text', passport.parseForm, passport.csrfProtection, (req, res) => {
premailerApi.prepare({ html: req.body.html, fetchHTML: false }, (err, email) => { premailerApi.prepare({
html: req.body.html,
fetchHTML: false
}, (err, email) => {
if (err) { if (err) {
return res.status(500).send(err.message || err); return res.status(500).send(err.message || err);
} }

View file

@ -23,10 +23,12 @@ router.get('/editor', passport.csrfProtection, (req, res) => {
return res.redirect('/'); return res.redirect('/');
} }
resource.editorName = resource.editorName || 'grapejs'; resource.editorName = resource.editorName ||  'grapejs';
resource.editorData = !resource.editorData resource.editorData = !resource.editorData ?
? { template: req.query.template || 'demo' } {
: JSON.parse(resource.editorData); template: req.query.template || 'demo'
} :
JSON.parse(resource.editorData);
if (!resource.html && !resource.editorData.html) { if (!resource.html && !resource.editorData.html) {
try { try {

View file

@ -25,7 +25,7 @@ router.get('/editor', passport.csrfProtection, (req, res) => {
} }
let getLanguageStrings = language => { let getLanguageStrings = language => {
if (!language || language === 'en') { if (!language ||  language === 'en') {
return null; return null;
} }
language = language.split('_')[0]; language = language.split('_')[0];
@ -37,10 +37,12 @@ router.get('/editor', passport.csrfProtection, (req, res) => {
} }
} }
resource.editorName = resource.editorName || 'mosaico'; resource.editorName = resource.editorName ||  'mosaico';
resource.editorData = !resource.editorData resource.editorData = !resource.editorData ?
? { template: req.query.template || 'versafix-1' } {
: JSON.parse(resource.editorData); template: req.query.template || 'versafix-1'
} :
JSON.parse(resource.editorData);
res.render('mosaico/editor', { res.render('mosaico/editor', {
layout: 'mosaico/layout-editor', layout: 'mosaico/layout-editor',