From c40b11aa6ed26c1fd9f8eb9f94d57e7aa7b630af Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Mon, 17 Jul 2017 10:47:56 -0400 Subject: [PATCH] updated site upload logic so that site logo is resized for email header, implemented site logo in email header --- src/controllers/admin/uploads.js | 16 ++++++++++++++++ src/emailer.js | 15 ++++++++++++++- src/meta/configs.js | 24 ++++++++++++++++++++---- src/views/emails/partials/header.tpl | 2 +- 4 files changed, 51 insertions(+), 6 deletions(-) diff --git a/src/controllers/admin/uploads.js b/src/controllers/admin/uploads.js index a040f12ba2..f4124549bc 100644 --- a/src/controllers/admin/uploads.js +++ b/src/controllers/admin/uploads.js @@ -146,6 +146,22 @@ function uploadImage(filename, folder, uploadedFile, req, res, next) { file.saveFileToLocal(filename, folder, uploadedFile.path, next); } }, + function (imageData, next) { + // Post-processing for site-logo + if (path.basename(filename, path.extname(filename)) === 'site-logo' && folder === 'system') { + var uploadPath = path.join(nconf.get('upload_path'), folder, 'site-logo-x50.png'); + image.resizeImage({ + path: uploadedFile.path, + target: uploadPath, + extension: 'png', + height: 50, + }, function (err) { + next(err, imageData); + }); + } else { + setImmediate(next, null, imageData); + } + }, ], function (err, image) { file.delete(uploadedFile.path); if (err) { diff --git a/src/emailer.js b/src/emailer.js index 5120ef9caf..947f5b35a7 100644 --- a/src/emailer.js +++ b/src/emailer.js @@ -14,6 +14,7 @@ var User = require('./user'); var Plugins = require('./plugins'); var meta = require('./meta'); var translator = require('./translator'); +var pubsub = require('./pubsub'); var transports = { sendmail: nodemailer.createTransport(sendmailTransport()), @@ -33,7 +34,11 @@ Emailer.registerApp = function (expressApp) { Emailer._defaultPayload = { url: nconf.get('url'), site_title: meta.config.title || 'NodeBB', - 'brand:logo': nconf.get('url') + meta.config['brand:logo'], + logo: { + src: nconf.get('url') + meta.config['brand:logo'].replace('.png', '-x50.png'), + height: meta.config['brand:emailLogo:height'], + width: meta.config['brand:emailLogo:width'], + }, }; // Enable Gmail transport if enabled in ACP @@ -52,6 +57,14 @@ Emailer.registerApp = function (expressApp) { fallbackTransport = transports.sendmail; } + // Update default payload if new logo is uploaded + pubsub.on('config:update', function (config) { + if (config) { + Emailer._defaultPayload.logo.height = config['brand:emailLogo:height']; + Emailer._defaultPayload.logo.width = config['brand:emailLogo:width']; + } + }); + return Emailer; }; diff --git a/src/meta/configs.js b/src/meta/configs.js index 925ff61255..e34e7de943 100644 --- a/src/meta/configs.js +++ b/src/meta/configs.js @@ -3,6 +3,7 @@ var async = require('async'); var nconf = require('nconf'); +var path = require('path'); var db = require('../database'); var pubsub = require('../pubsub'); @@ -80,13 +81,28 @@ Configs.setMultiple = function (data, callback) { }; function processConfig(data, callback) { - if (data.customCSS) { - return saveRenderedCss(data, callback); - } - setImmediate(callback); + async.parallel([ + async.apply(saveRenderedCss, data), + function (next) { + var image = require('../image'); + if (data['brand:logo']) { + image.size(path.join(nconf.get('upload_path'), 'system', 'site-logo-x50.png'), function (err, size) { + data['brand:emailLogo:height'] = size.height; + data['brand:emailLogo:width'] = size.width; + next(err); + }); + } + }, + ], function (err) { + callback(err); + }); } function saveRenderedCss(data, callback) { + if (!data.customCSS) { + return setImmediate(callback); + } + var less = require('less'); async.waterfall([ function (next) { diff --git a/src/views/emails/partials/header.tpl b/src/views/emails/partials/header.tpl index fd94ab4294..bc67621ffd 100644 --- a/src/views/emails/partials/header.tpl +++ b/src/views/emails/partials/header.tpl @@ -172,7 +172,7 @@
- {site_title} + {site_title}