diff --git a/public/src/forum/admin/settings.js b/public/src/forum/admin/settings.js index 8e8fc359df..b384b3b378 100644 --- a/public/src/forum/admin/settings.js +++ b/public/src/forum/admin/settings.js @@ -75,13 +75,20 @@ define(['uploader'], function(uploader) { }); $('#uploadLogoBtn').on('click', function() { - uploader.open(RELATIVE_PATH + '/admin/uploadlogo', function(image) { $('#logoUrl').val(image); }); uploader.hideAlerts(); }); + + $('#uploadFaviconBtn').on('click', function() { + uploader.open(RELATIVE_PATH + '/admin/uploadfavicon', function(icon) { + $('#faviconUrl').val(icon); + }); + + uploader.hideAlerts(); + }); }; Settings.remove = function(key) { diff --git a/public/templates/admin/settings.tpl b/public/templates/admin/settings.tpl index a5e6192b1b..4a72c95fcc 100644 --- a/public/templates/admin/settings.tpl +++ b/public/templates/admin/settings.tpl @@ -12,11 +12,14 @@

-
+

- +
+
+
+
diff --git a/public/templates/header.tpl b/public/templates/header.tpl index f08ff9680f..bd7a330b6c 100644 --- a/public/templates/header.tpl +++ b/public/templates/header.tpl @@ -3,8 +3,10 @@ {browserTitle} {meta_tags} + + {link_tags} @@ -25,8 +27,6 @@ } }); - - diff --git a/src/routes/admin.js b/src/routes/admin.js index 495b341a31..cd3994f144 100644 --- a/src/routes/admin.js +++ b/src/routes/admin.js @@ -145,6 +145,53 @@ var nconf = require('nconf'), is.pipe(os); }); + app.post('/uploadfavicon', function(req, res) { + if (!req.user) + return res.redirect('/403'); + + var allowedTypes = ['image/x-icon', 'image/vnd.microsoft.icon']; + + if (allowedTypes.indexOf(req.files.userPhoto.type) === -1) { + res.send({ + error: 'You can only upload icon file type!' + }); + return; + } + + var tempPath = req.files.userPhoto.path; + var extension = path.extname(req.files.userPhoto.name); + + if (!extension) { + res.send({ + error: 'Error uploading file! Error : Invalid extension!' + }); + return; + } + + var filename = 'favicon.ico'; + var uploadPath = path.join(nconf.get('base_dir'), nconf.get('upload_path'), filename); + + winston.info('Attempting upload to: ' + uploadPath); + + var is = fs.createReadStream(tempPath); + var os = fs.createWriteStream(uploadPath); + + is.on('end', function () { + fs.unlinkSync(tempPath); + + res.json({ + path: nconf.get('upload_url') + filename + }); + }); + + os.on('error', function (err) { + fs.unlinkSync(tempPath); + winston.err(err); + }); + + is.pipe(os); + }); + app.post('/uploadlogo', function(req, res) { if (!req.user) diff --git a/src/upgrade.js b/src/upgrade.js index 0970bcbcbc..dac9e4a015 100644 --- a/src/upgrade.js +++ b/src/upgrade.js @@ -38,7 +38,8 @@ Upgrade.upgrade = function(callback) { Upgrade.upgradeRedis = function(callback) { - var RDB = db.client; + var RDB = db.client, + updatesMade = false; winston.info('Beginning Redis database schema update'); @@ -52,6 +53,7 @@ Upgrade.upgradeRedis = function(callback) { function(next) { thisSchemaDate = new Date(2013, 9, 3).getTime(); if (schemaDate < thisSchemaDate) { + updatesMade = true; async.series([ function(next) { RDB.keys('uid:*:notifications:flag', function(err, keys) { @@ -110,6 +112,7 @@ Upgrade.upgradeRedis = function(callback) { function(next) { thisSchemaDate = new Date(2013, 9, 23).getTime(); if (schemaDate < thisSchemaDate) { + updatesMade = true; RDB.keys('notifications:*', function(err, keys) { keys = keys.filter(function(key) { @@ -139,6 +142,7 @@ Upgrade.upgradeRedis = function(callback) { function(next) { thisSchemaDate = new Date(2013, 10, 11).getTime(); if (schemaDate < thisSchemaDate) { + updatesMade = true; RDB.hset('config', 'postDelay', 10, function(err, success) { winston.info('[2013/11/11] Updated postDelay to 10 seconds.'); next(); @@ -151,6 +155,7 @@ Upgrade.upgradeRedis = function(callback) { function(next) { thisSchemaDate = new Date(2013, 10, 22).getTime(); if (schemaDate < thisSchemaDate) { + updatesMade = true; RDB.keys('category:*', function(err, categories) { async.each(categories, function(categoryStr, next) { var hex; @@ -197,6 +202,7 @@ Upgrade.upgradeRedis = function(callback) { function(next) { thisSchemaDate = new Date(2013, 10, 26).getTime(); if (schemaDate < thisSchemaDate) { + updatesMade = true; categories.getAllCategories(0, function(err, categories) { function updateIcon(category, next) { @@ -245,7 +251,7 @@ Upgrade.upgradeRedis = function(callback) { thisSchemaDate = new Date(2013, 11, 2).getTime(); if (schemaDate < thisSchemaDate) { - + updatesMade = true; var keys = [ 'global:next_user_id', 'next_topic_id', @@ -297,14 +303,18 @@ Upgrade.upgradeRedis = function(callback) { winston.info('[2013/12/2] Update to global keys skipped'); next(); } - }, + } // Add new schema updates here // IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 12!!! ], function(err) { if (!err) { RDB.set('schemaDate', thisSchemaDate, function(err) { if (!err) { - winston.info('[upgrade] Redis schema update complete!'); + if(updatesMade) { + winston.info('[upgrade] Redis schema update complete!'); + } else { + winston.info('[upgrade] Redis schema already up to date!'); + } if (callback) { callback(err); } else { diff --git a/src/webserver.js b/src/webserver.js index ad8614911d..f2a1c4f858 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -90,6 +90,7 @@ var path = require('path'), description: meta.config.description || '', 'brand:logo': meta.config['brand:logo'] || '', 'brand:logo:display': meta.config['brand:logo']?'':'hide', + 'brand:favicon': meta.config['brand:favicon'] || nconf.get('relative_path') + 'favicon.ico', browserTitle: meta.config.title || 'NodeBB', csrf: options.res.locals.csrf_token, relative_path: nconf.get('relative_path'),