From 714c7356f98481ea64b4cfa5c35c483640c14365 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Sat, 23 May 2015 22:11:20 -0400 Subject: [PATCH] closes #3176 --- install/data/defaults.json | 134 ++++++++----------------------------- src/install.js | 39 +++++++---- 2 files changed, 55 insertions(+), 118 deletions(-) diff --git a/install/data/defaults.json b/install/data/defaults.json index 9a0d6eb1ec..4e5ebc035e 100644 --- a/install/data/defaults.json +++ b/install/data/defaults.json @@ -1,106 +1,28 @@ -[ - { - "field": "title", - "value": "NodeBB" - }, - { - "field": "showSiteTitle", - "value": "1" - }, - { - "field": "postDelay", - "value": 10 - }, - { - "field": "initialPostDelay", - "value": 10 - }, - { - "field": "newbiePostDelay", - "value": 120 - }, - { - "field": "newbiePostDelayThreshold", - "value": 3 - }, - { - "field": "minimumPostLength", - "value": 8 - }, - { - "field": "maximumPostLength", - "value": 32767 - }, - { - "field": "allowGuestSearching", - "value": 0 - }, - { - "field": "allowTopicsThumbnail", - "value": 0 - }, - { - "field": "allowRegistration", - "value": 1 - }, - { - "field": "allowLocalLogin", - "value": 1 - }, - { - "field": "allowAccountDelete", - "value": 1 - }, - { - "field": "allowFileUploads", - "value": 0 - }, - { - "field": "maximumFileSize", - "value": 2048 - }, - { - "field": "minimumTitleLength", - "value": 3 - }, - { - "field": "maximumTitleLength", - "value": 255 - }, - { - "field": "minimumUsernameLength", - "value": 2 - }, - { - "field": "maximumUsernameLength", - "value": 16 - }, - { - "field": "minimumPasswordLength", - "value": 6 - }, - { - "field": "maximumSignatureLength", - "value": 255 - }, - { - "field": "maximumAboutMeLength", - "value": 1000 - }, - { - "field": "maximumProfileImageSize", - "value": 256 - }, - { - "field": "profileImageDimension", - "value": 128 - }, - { - "field": "requireEmailConfirmation", - "value": 0 - }, - { - "field": "profile:allowProfileImageUploads", - "value": 1 - } -] +{ + "title": "NodeBB", + "showSiteTitle": 1, + "postDelay": 10, + "initialPostDelay": 10, + "newbiePostDelay": 120, + "newbiePostDelayThreshold": 3, + "minimumPostLength": 8, + "maximumPostLength": 32767, + "allowGuestSearching": 0, + "allowTopicsThumbnail": 0, + "allowRegistration": 1, + "allowLocalLogin": 1, + "allowAccountDelete": 1, + "allowFileUploads": 0, + "maximumFileSize": 2048, + "minimumTitleLength": 3, + "maximumTitleLength": 255, + "minimumUsernameLength": 2, + "maximumUsernameLength": 16, + "minimumPasswordLength": 6, + "maximumSignatureLength": 255, + "maximumAboutMeLength": 1000, + "maximumProfileImageSize": 256, + "profileImageDimension": 128, + "requireEmailConfirmation": 0, + "profile:allowProfileImageUploads": 1 +} diff --git a/src/install.js b/src/install.js index 8b7c97ffc5..93597029f6 100644 --- a/src/install.js +++ b/src/install.js @@ -239,24 +239,39 @@ function setupDefaultConfigs(next) { var meta = require('./meta'), defaults = require(path.join(__dirname, '../', 'install/data/defaults.json')); - async.each(defaults, function (configObj, next) { - meta.configs.setOnEmpty(configObj.field, configObj.value, next); + async.each(Object.keys(defaults), function (key, next) { + meta.configs.setOnEmpty(key, defaults[key], next); }, function (err) { - meta.configs.init(next); - }); + if (err) { + return next(err); + } - if (install.values) { - setIfPaired('social:twitter:key', 'social:twitter:secret'); - setIfPaired('social:google:id', 'social:google:secret'); - setIfPaired('social:facebook:app_id', 'social:facebook:secret'); - } + if (install.values) { + async.parallel([ + async.apply(setIfPaired, 'social:twitter:key', 'social:twitter:secret'), + async.apply(setIfPaired, 'social:google:id', 'social:google:secret'), + async.apply(setIfPaired, 'social:facebook:app_id', 'social:facebook:secret') + ], function(err) { + if (err) { + return next(err); + } + meta.configs.init(next); + }); + } else { + meta.configs.init(next); + } + }); } -function setIfPaired(key1, key2) { +function setIfPaired(key1, key2, callback) { var meta = require('./meta'); if (install.values[key1] && install.values[key2]) { - meta.configs.setOnEmpty(key1, install.values[key1]); - meta.configs.setOnEmpty(key2, install.values[key2]); + async.parallel([ + async.apply(meta.configs.setOnEmpty, key1, install.values[key1]), + async.apply(meta.configs.setOnEmpty, key2, install.values[key2]) + ], callback); + } else { + callback(); } }