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

View file

@ -11,39 +11,37 @@ module.exports = {
function getDefaultMergeTags(callback) {
// Using a callback for the sake of future-proofness
callback(null, [
{
key: 'LINK_UNSUBSCRIBE',
value: _('URL that points to the unsubscribe page')
}, {
key: 'LINK_PREFERENCES',
value: _('URL that points to the preferences page of the subscriber')
}, {
key: 'LINK_BROWSER',
value: _('URL to preview the message in a browser')
}, {
key: 'EMAIL',
value: _('Email address')
}, {
key: 'FIRST_NAME',
value: _('First name')
}, {
key: 'LAST_NAME',
value: _('Last name')
}, {
key: 'FULL_NAME',
value: _('Full name (first and last name combined)')
}, {
key: 'SUBSCRIPTION_ID',
value: _('Unique ID that identifies the recipient')
}, {
key: 'LIST_ID',
value: _('Unique ID that identifies the list used for this campaign')
}, {
key: 'CAMPAIGN_ID',
value: _('Unique ID that identifies current campaign')
}
]);
callback(null, [{
key: 'LINK_UNSUBSCRIBE',
value: _('URL that points to the unsubscribe page')
}, {
key: 'LINK_PREFERENCES',
value: _('URL that points to the preferences page of the subscriber')
}, {
key: 'LINK_BROWSER',
value: _('URL to preview the message in a browser')
}, {
key: 'EMAIL',
value: _('Email address')
}, {
key: 'FIRST_NAME',
value: _('First name')
}, {
key: 'LAST_NAME',
value: _('Last name')
}, {
key: 'FULL_NAME',
value: _('Full name (first and last name combined)')
}, {
key: 'SUBSCRIPTION_ID',
value: _('Unique ID that identifies the recipient')
}, {
key: 'LIST_ID',
value: _('Unique ID that identifies the list used for this campaign')
}, {
key: 'CAMPAIGN_ID',
value: _('Unique ID that identifies current campaign')
}]);
}
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(' '),
address: email
},
subject: util.format(_('%s: Please Confirm Subscription'),list.name),
subject: util.format(_('%s: Please Confirm Subscription'), list.name),
encryptionKeys
}, {
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') {
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;
render('archive/view-raw', 'archive/layout-raw');
});

View file

@ -17,7 +17,9 @@ let multiparty = require('multiparty');
let fileType = require('file-type');
let escapeStringRegexp = require('escape-string-regexp');
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 htmlToText = require('html-to-text');
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 => {
if (err) {
return callback(dynamicUrl);
@ -94,33 +100,36 @@ let getStaticImageUrl = ({ dynamicUrl, staticDir, staticDirUrl }, callback) => {
}
fetch(dynamicUrl, {
headers
})
.then(res => {
return res.buffer();
})
.then(buffer => {
let ft = fileType(buffer);
if (!ft) {
return callback(dynamicUrl);
}
if (['image/jpeg', 'image/png', 'image/gif'].includes(ft.mime)) {
fs.writeFile(path.join(staticDir, hash + '.' + ft.ext), buffer, err => {
if (err) {
return callback(dynamicUrl);
}
let staticUrl = staticDirUrl + '/' + hash + '.' + ft.ext;
callback(staticUrl);
});
} else {
callback(dynamicUrl);
}
});
headers
})
.then(res => {
return res.buffer();
})
.then(buffer => {
let ft = fileType(buffer);
if (!ft) {
return callback(dynamicUrl);
}
if (['image/jpeg', 'image/png', 'image/gif'].includes(ft.mime)) {
fs.writeFile(path.join(staticDir, hash + '.' + ft.ext), buffer, err => {
if (err) {
return callback(dynamicUrl);
}
let staticUrl = staticDirUrl + '/' + hash + '.' + ft.ext;
callback(staticUrl);
});
} else {
callback(dynamicUrl);
}
});
});
});
};
let prepareHtml = ({ editorName, html }, callback) => {
let prepareHtml = ({
editorName,
html
}, callback) => {
settings.get('serviceUrl', (err, serviceUrl) => {
if (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 x = 0;
let y = 0;
@ -190,7 +202,12 @@ let placeholderImage = (req, res, { width, height }) => {
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);
magick.format((err, format) => {
if (err) {
@ -229,19 +246,31 @@ router.get('/img', passport.csrfProtection, (req, res) => {
return res.status(500).send(err.message || err);
}
let { src, method, params = '600,null' } = req.query;
let width = params.split(',')[0];
let {
src,
method,
params = '600,null'
} = req.query;
let width = params.split(',')[0];
let height = params.split(',')[1];
width = (width === 'null') ? null : Number(width);
width = (width === 'null') ? null : Number(width);
height = (height === 'null') ? null : Number(height);
switch (method) {
case 'placeholder':
return placeholderImage(req, res, { width, height });
return placeholderImage(req, res, {
width,
height
});
case 'resize':
case 'cover':
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:
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) => {
prepareHtml({ editorName: req.query.editor, html: req.body.html }, (err, html) => {
prepareHtml({
editorName: req.query.editor,
html: req.body.html
}, (err, html) => {
if (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) {
listImages(path.join(baseDir, req.query.id), baseDirUrl + '/' + req.query.id, (err, campaignImages) => {
err ? res.status(500).send(err.message || err)
: res.json({ files: sharedImages.concat(campaignImages) });
err ? res.status(500).send(err.message || err) :
res.json({
files: sharedImages.concat(campaignImages)
});
});
} else {
res.json({ files: sharedImages });
res.json({
files: sharedImages
});
}
});
});
});
router.post('/upload', passport.csrfProtection, (req, res) => {
let dirName = req.query.type === 'template' ? '0'
: req.query.type === 'campaign' && Number(req.query.id) > 0 ? req.query.id
: null;
let dirName = req.query.type === 'template' ? '0' :
req.query.type === 'campaign' && Number(req.query.id) > 0 ? req.query.id :
null;
if (dirName === null) {
return res.status(500).send(_('Invalid resource type or ID'));
@ -318,10 +354,15 @@ router.post('/upload', passport.csrfProtection, (req, res) => {
let opts = {
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),
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({
@ -332,9 +373,13 @@ router.post('/upload', passport.csrfProtection, (req, res) => {
if (req.query.editor === 'grapejs') {
let data = [];
JSON.parse(mockres._getData()).files.forEach(file => {
data.push({ src: file.url });
data.push({
src: file.url
});
});
res.json({
data
});
res.json({ data });
} else {
res.send(mockres._getData());
}
@ -344,7 +389,10 @@ router.post('/upload', 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) {
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) => {
prepareHtml({ editorName: req.query.editor, html: req.body.html }, (err, html) => {
prepareHtml({
editorName: req.query.editor,
html: req.body.html
}, (err, html) => {
if (err) {
req.query.editor === 'grapejs'
? res.status(500).json({ errors: err.message || err })
: res.status(500).send(err.message || err);
req.query.editor === 'grapejs' ?
res.status(500).json({
errors: err.message || err
}) :
res.status(500).send(err.message || err);
return;
}
settings.list(['defaultAddress', 'defaultFrom'], (err, configItems) => {
if (err) {
req.query.editor === 'grapejs'
? res.status(500).json({ errors: err.message || err })
: res.status(500).send(err.message || err);
req.query.editor === 'grapejs' ?
res.status(500).json({
errors: err.message || err
}) :
res.status(500).send(err.message || err);
return;
}
mailer.getMailer((err, transport) => {
if (err) {
req.query.editor === 'grapejs'
? res.status(500).json({ errors: err.message || err })
: res.status(500).send(err.message || err);
req.query.editor === 'grapejs' ?
res.status(500).json({
errors: err.message || err
}) :
res.status(500).send(err.message || err);
return;
}
@ -400,21 +457,27 @@ router.post('/test', parseGrapejsMultipartTestForm, passport.csrfProtection, (re
},
to: req.body.email,
subject: req.body.subject,
text: htmlToText.fromString(html, { wordwrap: 100 }),
text: htmlToText.fromString(html, {
wordwrap: 100
}),
html,
};
transport.sendMail(opts, (err, info) => {
if (err) {
req.query.editor === 'grapejs'
? res.status(500).json({ errors: err.message || err })
: res.status(500).send(err.message || err);
req.query.editor === 'grapejs' ?
res.status(500).json({
errors: err.message || err
}) :
res.status(500).send(err.message || err);
return;
}
req.query.editor === 'grapejs'
? res.json({ data: 'ok' })
: res.send('ok');
req.query.editor === 'grapejs' ?
res.json({
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) => {
premailerApi.prepare({ html: req.body.html, fetchHTML: false }, (err, email) => {
premailerApi.prepare({
html: req.body.html,
fetchHTML: false
}, (err, email) => {
if (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('/');
}
resource.editorName = resource.editorName || 'grapejs';
resource.editorData = !resource.editorData
? { template: req.query.template || 'demo' }
: JSON.parse(resource.editorData);
resource.editorName = resource.editorName ||  'grapejs';
resource.editorData = !resource.editorData ?
{
template: req.query.template || 'demo'
} :
JSON.parse(resource.editorData);
if (!resource.html && !resource.editorData.html) {
try {

View file

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