From f709dcb7989af3049148a98deb27f743aaa86dd7 Mon Sep 17 00:00:00 2001 From: Gabor Javorszky Date: Sat, 28 Sep 2013 15:42:42 +0100 Subject: [PATCH] Adds error message to blog import on empty / bad file Closes #840 * Checks file to be size > 0 * Checks file to be .json * Fails if either of them are not good --- core/server/controllers/admin.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/core/server/controllers/admin.js b/core/server/controllers/admin.js index 36d97de7cd..9a3d94fc96 100644 --- a/core/server/controllers/admin.js +++ b/core/server/controllers/admin.js @@ -317,11 +317,18 @@ adminControllers = { }); }, 'import': function (req, res) { - if (!req.files.importfile) { - // Notify of an error if it occurs + if (!req.files.importfile || req.files.importfile.size === 0 || req.files.importfile.name.indexOf('json') === -1) { + /** + * Notify of an error if it occurs + * + * - If there's no file (although if you don't select anything, the input is still submitted, so + * !req.files.importfile will always be false) + * - If the size is 0 + * - If the name doesn't have json in it + */ var notification = { type: 'error', - message: "Must select a file to import", + message: "Must select a .json file to import", status: 'persistent', id: 'per-' + (ghost.notifications.length + 1) };