core/server/models/settings.js
function parseDefaultSettings() {
    var defaultSettingsInCategories = require('../data/schema/').defaultSettings,
        defaultSettingsFlattened = {},
        dynamicDefault = {
            db_hash: uuid.v4(),
            public_hash: crypto.randomBytes(15).toString('hex'),
            // @TODO: session_secret would ideally be named "admin_session_secret"
            session_secret: crypto.randomBytes(32).toString('hex'),
            members_session_secret: crypto.randomBytes(32).toString('hex'),
            theme_session_secret: crypto.randomBytes(32).toString('hex')
        };

    const membersKeypair = keypair({
        bits: 1024
    });

    dynamicDefault.members_public_key = membersKeypair.public;
    dynamicDefault.members_private_key = membersKeypair.private;

    _.each(defaultSettingsInCategories, function each(settings, categoryName) {
        _.each(settings, function each(setting, settingName) {
            setting.type = categoryName;
            setting.key = settingName;
            if (dynamicDefault[setting.key]) {
                setting.defaultValue = dynamicDefault[setting.key];
            }

            defaultSettingsFlattened[settingName] = setting;
        });
    });

    return defaultSettingsFlattened;
}
function parseDefaultSettings() {
    var defaultSettingsInCategories = require('../data/schema/').defaultSettings,
        defaultSettingsFlattened = {},
        dynamicDefault = {
            db_hash: uuid.v4(),
            public_hash: crypto.randomBytes(15).toString('hex'),
            // @TODO: session_secret would ideally be named "admin_session_secret"
            session_secret: crypto.randomBytes(32).toString('hex'),
            members_session_secret: crypto.randomBytes(32).toString('hex'),
            theme_session_secret: crypto.randomBytes(32).toString('hex')
        };

    const membersKeypair = keypair({
        bits: 1024
    });

    dynamicDefault.members_public_key = membersKeypair.public;
    dynamicDefault.members_private_key = membersKeypair.private;

    _.each(defaultSettingsInCategories, function each(settings, categoryName) {
        _.each(settings, function each(setting, settingName) {
            setting.type = categoryName;
            setting.key = settingName;
            if (dynamicDefault[setting.key]) {
                setting.defaultValue = dynamicDefault[setting.key];
            }

            defaultSettingsFlattened[settingName] = setting;
        });
    });

    return defaultSettingsFlattened;
}
function parseDefaultSettings ( ) { var defaultSettingsInCategories = require ( '../data/schema/' ) . defaultSettings , defaultSettingsFlattened = { } , dynamicDefault = { db_hash : uuid . v4 ( ) , public_hash : crypto . randomBytes ( 15 ) . toString ( 'hex' ) , // @TODO: session_secret would ideally be named "admin_session_secret" session_secret : crypto . randomBytes ( 32 ) . toString ( 'hex' ) , members_session_secret : crypto . randomBytes ( 32 ) . toString ( 'hex' ) , theme_session_secret : crypto . randomBytes ( 32 ) . toString ( 'hex' ) } ; const membersKeypair = keypair ( { bits : 1024 } ) ; dynamicDefault . members_public_key = membersKeypair . public ; dynamicDefault . members_private_key = membersKeypair . private ; _ . each ( defaultSettingsInCategories , function each ( settings , categoryName ) { _ . each ( settings , function each ( setting , settingName ) { setting . type = categoryName ; setting . key = settingName ; if ( dynamicDefault [ setting . key ] ) { setting . defaultValue = dynamicDefault [ setting . key ] ; } defaultSettingsFlattened [ settingName ] = setting ; } ) ; } ) ; return defaultSettingsFlattened ; }
For neatness, the defaults file is split into categories. It's much easier for us to work with it as a single level instead of iterating those categories every time
For neatness the defaults file is split into categories . It s much easier for us to work with it as a single level instead of iterating those categories every time