Added initial support for trigger based automation

This commit is contained in:
Andris Reinman 2016-06-03 13:15:33 +03:00
parent cc1c70d57f
commit b16209f23e
36 changed files with 2025 additions and 263 deletions

View file

@ -30,12 +30,28 @@ router.get('/:campaign/:list/:subscription', (req, res) => {
res.end(trackImg);
});
router.get('/:campaign/:list/:subscription/:link', (req, res, next) => {
links.resolve(req.params.campaign, req.params.link, (err, linkId, url) => {
router.get('/:campaign/:list/:subscription/:link', (req, res) => {
let notFound = () => {
res.status(404);
return res.render('archive/view', {
layout: 'archive/layout',
message: 'Oops, we couldn\'t find a link for the URL you clicked',
campaign: {
subject: 'Error 404'
}
});
};
links.resolve(req.params.link, (err, linkId, url) => {
if (err) {
req.flash('danger', err.message || err);
return res.redirect('/');
}
if (!linkId || !url) {
log.error('Redirect', 'Unresolved URL: <%s>', req.url);
return notFound();
}
links.countClick(req.ip, req.params.campaign, req.params.list, req.params.subscription, linkId, (err, status) => {
if (err) {
log.error('Redirect', err.stack || err);
@ -58,9 +74,8 @@ router.get('/:campaign/:list/:subscription/:link', (req, res, next) => {
}
if (!list) {
err = new Error('Not Found');
err.status = 404;
return next(err);
log.error('Redirect', 'Could not resolve list for merge tags: <%s>', req.url);
return notFound();
}
settings.get('serviceUrl', (err, serviceUrl) => {
@ -76,9 +91,8 @@ router.get('/:campaign/:list/:subscription/:link', (req, res, next) => {
}
if (!subscription) {
err = new Error('Not Found');
err.status = 404;
return next(err);
log.error('Redirect', 'Could not resolve subscription for merge tags: <%s>', req.url);
return notFound();
}
url = tools.formatMessage(serviceUrl, {