aboutsummaryrefslogtreecommitdiffhomepage
path: root/initializers
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-02-07 11:23:23 +0100
committerChocobozzz <florian.bigard@gmail.com>2016-02-07 11:23:23 +0100
commit9f10b2928df655c3672d9607e864e667d4bc903a (patch)
tree7743911b974b3a7fb0d4c7cec2a723942466b7f1 /initializers
parentd7c01e7793d813d804a3b5716d8288f9dcf71a16 (diff)
downloadPeerTube-9f10b2928df655c3672d9607e864e667d4bc903a.tar.gz
PeerTube-9f10b2928df655c3672d9607e864e667d4bc903a.tar.zst
PeerTube-9f10b2928df655c3672d9607e864e667d4bc903a.zip
Remove useless anonymous functions of files
Diffstat (limited to 'initializers')
-rw-r--r--initializers/checker.js84
-rw-r--r--initializers/constants.js86
-rw-r--r--initializers/database.js46
3 files changed, 105 insertions, 111 deletions
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 @@
1;(function () { 1'use strict'
2 'use strict' 2
3 3var config = require('config')
4 var config = require('config') 4var mkdirp = require('mkdirp')
5 var mkdirp = require('mkdirp') 5var path = require('path')
6 var path = require('path') 6
7 7var checker = {
8 var checker = { 8 checkConfig: checkConfig,
9 checkConfig: checkConfig, 9 createDirectoriesIfNotExist: createDirectoriesIfNotExist
10 createDirectoriesIfNotExist: createDirectoriesIfNotExist 10}
11 } 11
12 12// Check the config files
13 // Check the config files 13function checkConfig () {
14 function checkConfig () { 14 var required = [ 'listen.port',
15 var required = [ 'listen.port', 15 'webserver.https', 'webserver.host', 'webserver.port',
16 'webserver.https', 'webserver.host', 'webserver.port', 16 'database.host', 'database.port', 'database.suffix',
17 'database.host', 'database.port', 'database.suffix', 17 'storage.certs', 'storage.uploads', 'storage.logs',
18 'storage.certs', 'storage.uploads', 'storage.logs', 18 'network.friends' ]
19 'network.friends' ] 19 var miss = []
20 var miss = [] 20
21 21 for (var key of required) {
22 for (var key of required) { 22 if (!config.has(key)) {
23 if (!config.has(key)) { 23 miss.push(key)
24 miss.push(key)
25 }
26 } 24 }
27
28 return miss
29 } 25 }
30 26
31 // Create directories for the storage if it doesn't exist 27 return miss
32 function createDirectoriesIfNotExist () { 28}
33 var storages = config.get('storage') 29
34 30// Create directories for the storage if it doesn't exist
35 for (var key of Object.keys(storages)) { 31function createDirectoriesIfNotExist () {
36 var dir = storages[key] 32 var storages = config.get('storage')
37 try { 33
38 mkdirp.sync(path.join(__dirname, '..', dir)) 34 for (var key of Object.keys(storages)) {
39 } catch (error) { 35 var dir = storages[key]
40 // Do not use logger 36 try {
41 console.error('Cannot create ' + path + ':' + error) 37 mkdirp.sync(path.join(__dirname, '..', dir))
42 process.exit(0) 38 } catch (error) {
43 } 39 // Do not use logger
40 console.error('Cannot create ' + path + ':' + error)
41 process.exit(0)
44 } 42 }
45 } 43 }
44}
46 45
47 // --------------------------------------------------------------------------- 46// ---------------------------------------------------------------------------
48 47
49 module.exports = checker 48module.exports = checker
50})()
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 @@
1;(function () { 1'use strict'
2 'use strict' 2
3 3// API version of our pod
4 // API version of our pod 4var API_VERSION = 'v1'
5 var API_VERSION = 'v1' 5
6 6// Score a pod has when we create it as a friend
7 // Score a pod has when we create it as a friend 7var FRIEND_BASE_SCORE = 100
8 var FRIEND_BASE_SCORE = 100 8
9 9// Time to wait between requests to the friends
10 // Time to wait between requests to the friends 10var INTERVAL = 60000
11 var INTERVAL = 60000 11
12 12// Number of points we add/remove from a friend after a successful/bad request
13 // Number of points we add/remove from a friend after a successful/bad request 13var PODS_SCORE = {
14 var PODS_SCORE = { 14 MALUS: -10,
15 MALUS: -10, 15 BONUS: 10
16 BONUS: 10 16}
17 } 17
18 18// Number of retries we make for the make retry requests (to friends...)
19 // Number of retries we make for the make retry requests (to friends...) 19var REQUEST_RETRIES = 10
20 var REQUEST_RETRIES = 10 20
21 21// Special constants for a test instance
22 // Special constants for a test instance 22if (isTestInstance() === true) {
23 if (isTestInstance() === true) { 23 FRIEND_BASE_SCORE = 20
24 FRIEND_BASE_SCORE = 20 24 INTERVAL = 10000
25 INTERVAL = 10000 25 REQUEST_RETRIES = 2
26 REQUEST_RETRIES = 2 26}
27 } 27
28 28// ---------------------------------------------------------------------------
29 // --------------------------------------------------------------------------- 29
30 30module.exports = {
31 module.exports = { 31 API_VERSION: API_VERSION,
32 API_VERSION: API_VERSION, 32 FRIEND_BASE_SCORE: FRIEND_BASE_SCORE,
33 FRIEND_BASE_SCORE: FRIEND_BASE_SCORE, 33 INTERVAL: INTERVAL,
34 INTERVAL: INTERVAL, 34 PODS_SCORE: PODS_SCORE,
35 PODS_SCORE: PODS_SCORE, 35 REQUEST_RETRIES: REQUEST_RETRIES
36 REQUEST_RETRIES: REQUEST_RETRIES 36}
37 } 37
38 38// ---------------------------------------------------------------------------
39 // --------------------------------------------------------------------------- 39
40 40function isTestInstance () {
41 function isTestInstance () { 41 return (process.env.NODE_ENV === 'test')
42 return (process.env.NODE_ENV === 'test') 42}
43 }
44})()
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 @@
1;(function () { 1'use strict'
2 'use strict'
3 2
4 var config = require('config') 3var config = require('config')
5 var mongoose = require('mongoose') 4var mongoose = require('mongoose')
6 5
7 var logger = require('../helpers/logger') 6var logger = require('../helpers/logger')
8 7
9 var dbname = 'peertube' + config.get('database.suffix') 8var dbname = 'peertube' + config.get('database.suffix')
10 var host = config.get('database.host') 9var host = config.get('database.host')
11 var port = config.get('database.port') 10var port = config.get('database.port')
12 11
13 var database = { 12var database = {
14 connect: connect 13 connect: connect
15 } 14}
16 15
17 function connect () { 16function connect () {
18 mongoose.connect('mongodb://' + host + ':' + port + '/' + dbname) 17 mongoose.connect('mongodb://' + host + ':' + port + '/' + dbname)
19 mongoose.connection.on('error', function () { 18 mongoose.connection.on('error', function () {
20 logger.error('Mongodb connection error.') 19 logger.error('Mongodb connection error.')
21 process.exit(0) 20 process.exit(0)
22 }) 21 })
23 22
24 mongoose.connection.on('open', function () { 23 mongoose.connection.on('open', function () {
25 logger.info('Connected to mongodb.') 24 logger.info('Connected to mongodb.')
26 }) 25 })
27 } 26}
28 27
29 // --------------------------------------------------------------------------- 28// ---------------------------------------------------------------------------
30 29
31 module.exports = database 30module.exports = database
32})()