aboutsummaryrefslogtreecommitdiffhomepage
path: root/initializers
diff options
context:
space:
mode:
Diffstat (limited to 'initializers')
-rw-r--r--initializers/checker.js12
-rw-r--r--initializers/constants.js39
-rw-r--r--initializers/database.js37
3 files changed, 50 insertions, 38 deletions
diff --git a/initializers/checker.js b/initializers/checker.js
index 7a3a53616..7a09c02d1 100644
--- a/initializers/checker.js
+++ b/initializers/checker.js
@@ -4,10 +4,13 @@
4 var config = require('config') 4 var config = require('config')
5 var mkdirp = require('mkdirp') 5 var mkdirp = require('mkdirp')
6 6
7 var checker = {} 7 var checker = {
8 checkConfig: checkConfig,
9 createDirectoriesIfNotExist: createDirectoriesIfNotExist
10 }
8 11
9 // Check the config files 12 // Check the config files
10 checker.checkConfig = function () { 13 function checkConfig () {
11 var required = [ 'listen.port', 14 var required = [ 'listen.port',
12 'webserver.https', 'webserver.host', 'webserver.port', 15 'webserver.https', 'webserver.host', 'webserver.port',
13 'database.host', 'database.port', 'database.suffix', 16 'database.host', 'database.port', 'database.suffix',
@@ -25,7 +28,7 @@
25 } 28 }
26 29
27 // Create directories for the storage if it doesn't exist 30 // Create directories for the storage if it doesn't exist
28 checker.createDirectoriesIfNotExist = function () { 31 function createDirectoriesIfNotExist () {
29 var storages = config.get('storage') 32 var storages = config.get('storage')
30 33
31 for (var key of Object.keys(storages)) { 34 for (var key of Object.keys(storages)) {
@@ -40,6 +43,7 @@
40 } 43 }
41 } 44 }
42 45
43 // ----------- Export ----------- 46 // ---------------------------------------------------------------------------
47
44 module.exports = checker 48 module.exports = checker
45})() 49})()
diff --git a/initializers/constants.js b/initializers/constants.js
index 00b713961..1e101a747 100644
--- a/initializers/constants.js
+++ b/initializers/constants.js
@@ -1,37 +1,44 @@
1;(function () { 1;(function () {
2 'use strict' 2 'use strict'
3 3
4 var constants = {}
5
6 function isTestInstance () {
7 return (process.env.NODE_ENV === 'test')
8 }
9
10 // API version of our pod 4 // API version of our pod
11 constants.API_VERSION = 'v1' 5 var API_VERSION = 'v1'
12 6
13 // Score a pod has when we create it as a friend 7 // Score a pod has when we create it as a friend
14 constants.FRIEND_BASE_SCORE = 100 8 var FRIEND_BASE_SCORE = 100
15 9
16 // Time to wait between requests to the friends 10 // Time to wait between requests to the friends
17 constants.INTERVAL = 60000 11 var INTERVAL = 60000
18 12
19 // 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
20 constants.PODS_SCORE = { 14 var PODS_SCORE = {
21 MALUS: -10, 15 MALUS: -10,
22 BONUS: 10 16 BONUS: 10
23 } 17 }
24 18
25 // 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...)
26 constants.REQUEST_RETRIES = 10 20 var REQUEST_RETRIES = 10
27 21
28 // Special constants for a test instance 22 // Special constants for a test instance
29 if (isTestInstance() === true) { 23 if (isTestInstance() === true) {
30 constants.FRIEND_BASE_SCORE = 20 24 FRIEND_BASE_SCORE = 20
31 constants.INTERVAL = 10000 25 INTERVAL = 10000
32 constants.REQUEST_RETRIES = 2 26 REQUEST_RETRIES = 2
27 }
28
29 // ---------------------------------------------------------------------------
30
31 module.exports = {
32 API_VERSION: API_VERSION,
33 FRIEND_BASE_SCORE: FRIEND_BASE_SCORE,
34 INTERVAL: INTERVAL,
35 PODS_SCORE: PODS_SCORE,
36 REQUEST_RETRIES: REQUEST_RETRIES
33 } 37 }
34 38
35 // ----------- Export ----------- 39 // ---------------------------------------------------------------------------
36 module.exports = constants 40
41 function isTestInstance () {
42 return (process.env.NODE_ENV === 'test')
43 }
37})() 44})()
diff --git a/initializers/database.js b/initializers/database.js
index 4570d3739..e041d5c4b 100644
--- a/initializers/database.js
+++ b/initializers/database.js
@@ -11,17 +11,6 @@
11 var host = config.get('database.host') 11 var host = config.get('database.host')
12 var port = config.get('database.port') 12 var port = config.get('database.port')
13 13
14 // ----------- Videos -----------
15 var videosSchema = mongoose.Schema({
16 name: String,
17 namePath: String,
18 description: String,
19 magnetUri: String,
20 podUrl: String
21 })
22
23 var VideosDB = mongoose.model('videos', videosSchema)
24
25 // ----------- Pods ----------- 14 // ----------- Pods -----------
26 var podsSchema = mongoose.Schema({ 15 var podsSchema = mongoose.Schema({
27 url: String, 16 url: String,
@@ -40,6 +29,25 @@
40 29
41 var PoolRequestsDB = mongoose.model('poolRequests', poolRequestsSchema) 30 var PoolRequestsDB = mongoose.model('poolRequests', poolRequestsSchema)
42 31
32 // ----------- Videos -----------
33 var videosSchema = mongoose.Schema({
34 name: String,
35 namePath: String,
36 description: String,
37 magnetUri: String,
38 podUrl: String
39 })
40
41 var VideosDB = mongoose.model('videos', videosSchema)
42
43 // ---------------------------------------------------------------------------
44
45 module.exports = {
46 PodsDB: PodsDB,
47 PoolRequestsDB: PoolRequestsDB,
48 VideosDB: VideosDB
49 }
50
43 // ----------- Connection ----------- 51 // ----------- Connection -----------
44 52
45 mongoose.connect('mongodb://' + host + ':' + port + '/' + dbname) 53 mongoose.connect('mongodb://' + host + ':' + port + '/' + dbname)
@@ -51,11 +59,4 @@
51 mongoose.connection.on('open', function () { 59 mongoose.connection.on('open', function () {
52 logger.info('Connected to mongodb.') 60 logger.info('Connected to mongodb.')
53 }) 61 })
54
55 // ----------- Export -----------
56 module.exports = {
57 VideosDB: VideosDB,
58 PodsDB: PodsDB,
59 PoolRequestsDB: PoolRequestsDB
60 }
61})() 62})()