aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/constants.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-10-02 15:39:09 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-10-02 15:39:09 +0200
commita6375e69668ea42e19531c6bc68dcd37f3f7cbd7 (patch)
tree03204a408d56311692c3528bedcf95d2455e94f2 /server/initializers/constants.js
parent052937db8a8d282eccdbdf38d487ed8d85d3c0a7 (diff)
parentc4403b29ad4db097af528a7f04eea07e0ed320d0 (diff)
downloadPeerTube-a6375e69668ea42e19531c6bc68dcd37f3f7cbd7.tar.gz
PeerTube-a6375e69668ea42e19531c6bc68dcd37f3f7cbd7.tar.zst
PeerTube-a6375e69668ea42e19531c6bc68dcd37f3f7cbd7.zip
Merge branch 'master' into webseed-merged
Diffstat (limited to 'server/initializers/constants.js')
-rw-r--r--server/initializers/constants.js175
1 files changed, 126 insertions, 49 deletions
diff --git a/server/initializers/constants.js b/server/initializers/constants.js
index e0ea188af..be2e3e943 100644
--- a/server/initializers/constants.js
+++ b/server/initializers/constants.js
@@ -1,24 +1,103 @@
1'use strict' 1'use strict'
2 2
3// API version of our pod 3const config = require('config')
4const path = require('path')
5
6// ---------------------------------------------------------------------------
7
8// API version
4const API_VERSION = 'v1' 9const API_VERSION = 'v1'
5 10
6// Score a pod has when we create it as a friend 11// Number of results by default for the pagination
7const FRIEND_SCORE = { 12const PAGINATION_COUNT_DEFAULT = 15
8 BASE: 100, 13
9 MAX: 1000 14// Sortable columns per schema
15const SEARCHABLE_COLUMNS = {
16 VIDEOS: [ 'name', 'magnetUri', 'podUrl', 'author', 'tags' ]
10} 17}
11 18
12// Time to wait between requests to the friends (10 min) 19// Sortable columns per schema
13let INTERVAL = 600000 20const SORTABLE_COLUMNS = {
21 USERS: [ 'username', '-username', 'createdDate', '-createdDate' ],
22 VIDEOS: [ 'name', '-name', 'duration', '-duration', 'createdDate', '-createdDate' ]
23}
14 24
15const OAUTH_LIFETIME = { 25const OAUTH_LIFETIME = {
16 ACCESS_TOKEN: 3600 * 4, // 4 hours 26 ACCESS_TOKEN: 3600 * 4, // 4 hours
17 REFRESH_TOKEN: 1209600 // 2 weeks 27 REFRESH_TOKEN: 1209600 // 2 weeks
18} 28}
19 29
20// Number of results by default for the pagination 30// ---------------------------------------------------------------------------
21const PAGINATION_COUNT_DEFAULT = 15 31
32const CONFIG = {
33 DATABASE: {
34 DBNAME: 'peertube' + config.get('database.suffix'),
35 HOST: config.get('database.host'),
36 PORT: config.get('database.port')
37 },
38 ELECTRON: {
39 DEBUG: config.get('electron.debug')
40 },
41 STORAGE: {
42 CERT_DIR: path.join(__dirname, '..', '..', config.get('storage.certs')),
43 LOG_DIR: path.join(__dirname, '..', '..', config.get('storage.logs')),
44 UPLOAD_DIR: path.join(__dirname, '..', '..', config.get('storage.uploads')),
45 THUMBNAILS_DIR: path.join(__dirname, '..', '..', config.get('storage.thumbnails'))
46 },
47 WEBSERVER: {
48 SCHEME: config.get('webserver.https') === true ? 'https' : 'http',
49 HOST: config.get('webserver.host'),
50 PORT: config.get('webserver.port')
51 }
52}
53CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOST + ':' + CONFIG.WEBSERVER.PORT
54
55// ---------------------------------------------------------------------------
56
57const CONSTRAINTS_FIELDS = {
58 USERS: {
59 USERNAME: { min: 3, max: 20 }, // Length
60 PASSWORD: { min: 6, max: 255 } // Length
61 },
62 VIDEOS: {
63 NAME: { min: 3, max: 50 }, // Length
64 DESCRIPTION: { min: 3, max: 250 }, // Length
65 MAGNET_URI: { min: 10 }, // Length
66 DURATION: { min: 1, max: 7200 }, // Number
67 TAGS: { min: 1, max: 3 }, // Number of total tags
68 TAG: { min: 2, max: 10 }, // Length
69 THUMBNAIL: { min: 2, max: 30 },
70 THUMBNAIL64: { min: 0, max: 20000 } // Bytes
71 }
72}
73
74// ---------------------------------------------------------------------------
75
76// Score a pod has when we create it as a friend
77const FRIEND_SCORE = {
78 BASE: 100,
79 MAX: 1000
80}
81
82// ---------------------------------------------------------------------------
83
84const MONGO_MIGRATION_SCRIPTS = [
85 {
86 script: '0005-create-application',
87 version: 5
88 },
89 {
90 script: '0010-users-password',
91 version: 10
92 },
93 {
94 script: '0015-admin-role',
95 version: 15
96 }
97]
98const LAST_MONGO_SCHEMA_VERSION = 15
99
100// ---------------------------------------------------------------------------
22 101
23// Number of points we add/remove from a friend after a successful/bad request 102// Number of points we add/remove from a friend after a successful/bad request
24const PODS_SCORE = { 103const PODS_SCORE = {
@@ -26,28 +105,22 @@ const PODS_SCORE = {
26 BONUS: 10 105 BONUS: 10
27} 106}
28 107
108// Time to wait between requests to the friends (10 min)
109let REQUESTS_INTERVAL = 600000
110
29// Number of requests in parallel we can make 111// Number of requests in parallel we can make
30const REQUESTS_IN_PARALLEL = 10 112const REQUESTS_IN_PARALLEL = 10
31 113
32// How many requests we put in request (request scheduler) 114// How many requests we put in request
33const REQUESTS_LIMIT = 10 115const REQUESTS_LIMIT = 10
34 116
35// Number of requests to retry for replay requests module 117// Number of requests to retry for replay requests module
36const RETRY_REQUESTS = 5 118const RETRY_REQUESTS = 5
37 119
38// Sortable columns per schema 120// ---------------------------------------------------------------------------
39const SEARCHABLE_COLUMNS = {
40 VIDEOS: [ 'name', 'magnetUri', 'podUrl', 'author', 'tags' ]
41}
42
43// Seeds in parallel we send to electron when "seed all"
44// Once a video is in seeding state we seed another video etc
45const SEEDS_IN_PARALLEL = 3
46 121
47// Sortable columns per schema 122// Password encryption
48const SORTABLE_COLUMNS = { 123const BCRYPT_SALT_SIZE = 10
49 VIDEOS: [ 'name', '-name', 'duration', '-duration', 'createdDate', '-createdDate' ]
50}
51 124
52// Express static paths (router) 125// Express static paths (router)
53const STATIC_PATHS = { 126const STATIC_PATHS = {
@@ -59,43 +132,47 @@ const STATIC_PATHS = {
59// Videos thumbnail size 132// Videos thumbnail size
60const THUMBNAILS_SIZE = '200x110' 133const THUMBNAILS_SIZE = '200x110'
61 134
62const VIDEOS_CONSTRAINTS_FIELDS = { 135const USER_ROLES = {
63 NAME: { min: 3, max: 50 }, // Length 136 ADMIN: 'admin',
64 DESCRIPTION: { min: 3, max: 250 }, // Length 137 USER: 'user'
65 MAGNET_URI: { min: 10 }, // Length
66 DURATION: { min: 1, max: 7200 }, // Number
67 AUTHOR: { min: 3, max: 20 }, // Length
68 TAGS: { min: 1, max: 3 }, // Number of total tags
69 TAG: { min: 2, max: 10 }, // Length
70 THUMBNAIL: { min: 2, max: 30 },
71 THUMBNAIL64: { min: 0, max: 20000 } // Bytes
72} 138}
73 139
140// Seeds in parallel we send to electron when "seed all"
141// Once a video is in seeding state we seed another video etc
142const SEEDS_IN_PARALLEL = 3
143
144// ---------------------------------------------------------------------------
145
74// Special constants for a test instance 146// Special constants for a test instance
75if (isTestInstance() === true) { 147if (isTestInstance() === true) {
148 CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14
76 FRIEND_SCORE.BASE = 20 149 FRIEND_SCORE.BASE = 20
77 INTERVAL = 10000 150 REQUESTS_INTERVAL = 10000
78 VIDEOS_CONSTRAINTS_FIELDS.DURATION.max = 14
79} 151}
80 152
81// --------------------------------------------------------------------------- 153// ---------------------------------------------------------------------------
82 154
83module.exports = { 155module.exports = {
84 API_VERSION: API_VERSION, 156 API_VERSION,
85 FRIEND_SCORE: FRIEND_SCORE, 157 BCRYPT_SALT_SIZE,
86 INTERVAL: INTERVAL, 158 CONFIG,
87 OAUTH_LIFETIME: OAUTH_LIFETIME, 159 CONSTRAINTS_FIELDS,
88 PAGINATION_COUNT_DEFAULT: PAGINATION_COUNT_DEFAULT, 160 FRIEND_SCORE,
89 PODS_SCORE: PODS_SCORE, 161 LAST_MONGO_SCHEMA_VERSION,
90 REQUESTS_IN_PARALLEL: REQUESTS_IN_PARALLEL, 162 MONGO_MIGRATION_SCRIPTS,
91 REQUESTS_LIMIT: REQUESTS_LIMIT, 163 OAUTH_LIFETIME,
92 RETRY_REQUESTS: RETRY_REQUESTS, 164 PAGINATION_COUNT_DEFAULT,
93 SEARCHABLE_COLUMNS: SEARCHABLE_COLUMNS, 165 PODS_SCORE,
94 SEEDS_IN_PARALLEL: SEEDS_IN_PARALLEL, 166 REQUESTS_IN_PARALLEL,
95 SORTABLE_COLUMNS: SORTABLE_COLUMNS, 167 REQUESTS_INTERVAL,
96 STATIC_PATHS: STATIC_PATHS, 168 REQUESTS_LIMIT,
97 THUMBNAILS_SIZE: THUMBNAILS_SIZE, 169 RETRY_REQUESTS,
98 VIDEOS_CONSTRAINTS_FIELDS: VIDEOS_CONSTRAINTS_FIELDS 170 SEARCHABLE_COLUMNS,
171 SEEDS_IN_PARALLEL,
172 SORTABLE_COLUMNS,
173 STATIC_PATHS,
174 THUMBNAILS_SIZE,
175 USER_ROLES
99} 176}
100 177
101// --------------------------------------------------------------------------- 178// ---------------------------------------------------------------------------