From 9f10b2928df655c3672d9607e864e667d4bc903a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Sun, 7 Feb 2016 11:23:23 +0100 Subject: Remove useless anonymous functions of files --- initializers/checker.js | 84 ++++++++++++++++++++++----------------------- initializers/constants.js | 86 +++++++++++++++++++++++------------------------ initializers/database.js | 46 ++++++++++++------------- 3 files changed, 105 insertions(+), 111 deletions(-) (limited to 'initializers') diff --git a/initializers/checker.js b/initializers/checker.js index f4458c5cf..9a7d04ed4 100644 --- a/initializers/checker.js +++ b/initializers/checker.js @@ -1,50 +1,48 @@ -;(function () { - 'use strict' - - var config = require('config') - var mkdirp = require('mkdirp') - var path = require('path') - - var checker = { - checkConfig: checkConfig, - createDirectoriesIfNotExist: createDirectoriesIfNotExist - } - - // Check the config files - function checkConfig () { - var required = [ 'listen.port', - 'webserver.https', 'webserver.host', 'webserver.port', - 'database.host', 'database.port', 'database.suffix', - 'storage.certs', 'storage.uploads', 'storage.logs', - 'network.friends' ] - var miss = [] - - for (var key of required) { - if (!config.has(key)) { - miss.push(key) - } +'use strict' + +var config = require('config') +var mkdirp = require('mkdirp') +var path = require('path') + +var checker = { + checkConfig: checkConfig, + createDirectoriesIfNotExist: createDirectoriesIfNotExist +} + +// Check the config files +function checkConfig () { + var required = [ 'listen.port', + 'webserver.https', 'webserver.host', 'webserver.port', + 'database.host', 'database.port', 'database.suffix', + 'storage.certs', 'storage.uploads', 'storage.logs', + 'network.friends' ] + var miss = [] + + for (var key of required) { + if (!config.has(key)) { + miss.push(key) } - - return miss } - // Create directories for the storage if it doesn't exist - function createDirectoriesIfNotExist () { - var storages = config.get('storage') - - for (var key of Object.keys(storages)) { - var dir = storages[key] - try { - mkdirp.sync(path.join(__dirname, '..', dir)) - } catch (error) { - // Do not use logger - console.error('Cannot create ' + path + ':' + error) - process.exit(0) - } + return miss +} + +// Create directories for the storage if it doesn't exist +function createDirectoriesIfNotExist () { + var storages = config.get('storage') + + for (var key of Object.keys(storages)) { + var dir = storages[key] + try { + mkdirp.sync(path.join(__dirname, '..', dir)) + } catch (error) { + // Do not use logger + console.error('Cannot create ' + path + ':' + error) + process.exit(0) } } +} - // --------------------------------------------------------------------------- +// --------------------------------------------------------------------------- - module.exports = checker -})() +module.exports = checker diff --git a/initializers/constants.js b/initializers/constants.js index 1e101a747..16e50443b 100644 --- a/initializers/constants.js +++ b/initializers/constants.js @@ -1,44 +1,42 @@ -;(function () { - 'use strict' - - // API version of our pod - var API_VERSION = 'v1' - - // Score a pod has when we create it as a friend - var FRIEND_BASE_SCORE = 100 - - // Time to wait between requests to the friends - var INTERVAL = 60000 - - // Number of points we add/remove from a friend after a successful/bad request - var PODS_SCORE = { - MALUS: -10, - BONUS: 10 - } - - // Number of retries we make for the make retry requests (to friends...) - var REQUEST_RETRIES = 10 - - // Special constants for a test instance - if (isTestInstance() === true) { - FRIEND_BASE_SCORE = 20 - INTERVAL = 10000 - REQUEST_RETRIES = 2 - } - - // --------------------------------------------------------------------------- - - module.exports = { - API_VERSION: API_VERSION, - FRIEND_BASE_SCORE: FRIEND_BASE_SCORE, - INTERVAL: INTERVAL, - PODS_SCORE: PODS_SCORE, - REQUEST_RETRIES: REQUEST_RETRIES - } - - // --------------------------------------------------------------------------- - - function isTestInstance () { - return (process.env.NODE_ENV === 'test') - } -})() +'use strict' + +// API version of our pod +var API_VERSION = 'v1' + +// Score a pod has when we create it as a friend +var FRIEND_BASE_SCORE = 100 + +// Time to wait between requests to the friends +var INTERVAL = 60000 + +// Number of points we add/remove from a friend after a successful/bad request +var PODS_SCORE = { + MALUS: -10, + BONUS: 10 +} + +// Number of retries we make for the make retry requests (to friends...) +var REQUEST_RETRIES = 10 + +// Special constants for a test instance +if (isTestInstance() === true) { + FRIEND_BASE_SCORE = 20 + INTERVAL = 10000 + REQUEST_RETRIES = 2 +} + +// --------------------------------------------------------------------------- + +module.exports = { + API_VERSION: API_VERSION, + FRIEND_BASE_SCORE: FRIEND_BASE_SCORE, + INTERVAL: INTERVAL, + PODS_SCORE: PODS_SCORE, + REQUEST_RETRIES: REQUEST_RETRIES +} + +// --------------------------------------------------------------------------- + +function isTestInstance () { + return (process.env.NODE_ENV === 'test') +} diff --git a/initializers/database.js b/initializers/database.js index 96c172637..6e3f11df3 100644 --- a/initializers/database.js +++ b/initializers/database.js @@ -1,32 +1,30 @@ -;(function () { - 'use strict' +'use strict' - var config = require('config') - var mongoose = require('mongoose') +var config = require('config') +var mongoose = require('mongoose') - var logger = require('../helpers/logger') +var logger = require('../helpers/logger') - var dbname = 'peertube' + config.get('database.suffix') - var host = config.get('database.host') - var port = config.get('database.port') +var dbname = 'peertube' + config.get('database.suffix') +var host = config.get('database.host') +var port = config.get('database.port') - var database = { - connect: connect - } +var database = { + connect: connect +} - function connect () { - mongoose.connect('mongodb://' + host + ':' + port + '/' + dbname) - mongoose.connection.on('error', function () { - logger.error('Mongodb connection error.') - process.exit(0) - }) +function connect () { + mongoose.connect('mongodb://' + host + ':' + port + '/' + dbname) + mongoose.connection.on('error', function () { + logger.error('Mongodb connection error.') + process.exit(0) + }) - mongoose.connection.on('open', function () { - logger.info('Connected to mongodb.') - }) - } + mongoose.connection.on('open', function () { + logger.info('Connected to mongodb.') + }) +} - // --------------------------------------------------------------------------- +// --------------------------------------------------------------------------- - module.exports = database -})() +module.exports = database -- cgit v1.2.3