diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-10-02 11:14:08 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-10-02 11:14:08 +0200 |
commit | 9f6bae3a9db13bf827f8aaff903aac06ec430903 (patch) | |
tree | 4c4735dfee42931ec0caf0de45941772b6c34312 | |
parent | a67b3e7619353d7eb1f3e6064ebe3041094a8b70 (diff) | |
download | PeerTube-9f6bae3a9db13bf827f8aaff903aac06ec430903.tar.gz PeerTube-9f6bae3a9db13bf827f8aaff903aac06ec430903.tar.zst PeerTube-9f6bae3a9db13bf827f8aaff903aac06ec430903.zip |
Server: reorganize constant file
-rw-r--r-- | server/initializers/constants.js | 111 |
1 files changed, 64 insertions, 47 deletions
diff --git a/server/initializers/constants.js b/server/initializers/constants.js index 02043bd45..b1d033377 100644 --- a/server/initializers/constants.js +++ b/server/initializers/constants.js | |||
@@ -3,10 +3,31 @@ | |||
3 | const config = require('config') | 3 | const config = require('config') |
4 | const path = require('path') | 4 | const path = require('path') |
5 | 5 | ||
6 | // API version of our pod | 6 | // --------------------------------------------------------------------------- |
7 | |||
8 | // API version | ||
7 | const API_VERSION = 'v1' | 9 | const API_VERSION = 'v1' |
8 | 10 | ||
9 | const BCRYPT_SALT_SIZE = 10 | 11 | // Number of results by default for the pagination |
12 | const PAGINATION_COUNT_DEFAULT = 15 | ||
13 | |||
14 | // Sortable columns per schema | ||
15 | const SEARCHABLE_COLUMNS = { | ||
16 | VIDEOS: [ 'name', 'magnetUri', 'podUrl', 'author', 'tags' ] | ||
17 | } | ||
18 | |||
19 | // Sortable columns per schema | ||
20 | const SORTABLE_COLUMNS = { | ||
21 | USERS: [ 'username', '-username', 'createdDate', '-createdDate' ], | ||
22 | VIDEOS: [ 'name', '-name', 'duration', '-duration', 'createdDate', '-createdDate' ] | ||
23 | } | ||
24 | |||
25 | const OAUTH_LIFETIME = { | ||
26 | ACCESS_TOKEN: 3600 * 4, // 4 hours | ||
27 | REFRESH_TOKEN: 1209600 // 2 weeks | ||
28 | } | ||
29 | |||
30 | // --------------------------------------------------------------------------- | ||
10 | 31 | ||
11 | const CONFIG = { | 32 | const CONFIG = { |
12 | DATABASE: { | 33 | DATABASE: { |
@@ -31,6 +52,8 @@ const CONFIG = { | |||
31 | } | 52 | } |
32 | CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOST + ':' + CONFIG.WEBSERVER.PORT | 53 | CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOST + ':' + CONFIG.WEBSERVER.PORT |
33 | 54 | ||
55 | // --------------------------------------------------------------------------- | ||
56 | |||
34 | const CONSTRAINTS_FIELDS = { | 57 | const CONSTRAINTS_FIELDS = { |
35 | USERS: { | 58 | USERS: { |
36 | USERNAME: { min: 3, max: 20 }, // Length | 59 | USERNAME: { min: 3, max: 20 }, // Length |
@@ -48,12 +71,16 @@ const CONSTRAINTS_FIELDS = { | |||
48 | } | 71 | } |
49 | } | 72 | } |
50 | 73 | ||
74 | // --------------------------------------------------------------------------- | ||
75 | |||
51 | // Score a pod has when we create it as a friend | 76 | // Score a pod has when we create it as a friend |
52 | const FRIEND_SCORE = { | 77 | const FRIEND_SCORE = { |
53 | BASE: 100, | 78 | BASE: 100, |
54 | MAX: 1000 | 79 | MAX: 1000 |
55 | } | 80 | } |
56 | 81 | ||
82 | // --------------------------------------------------------------------------- | ||
83 | |||
57 | const MONGO_MIGRATION_SCRIPTS = [ | 84 | const MONGO_MIGRATION_SCRIPTS = [ |
58 | { | 85 | { |
59 | script: '0005-create-application', | 86 | script: '0005-create-application', |
@@ -70,16 +97,7 @@ const MONGO_MIGRATION_SCRIPTS = [ | |||
70 | ] | 97 | ] |
71 | const LAST_MONGO_SCHEMA_VERSION = 15 | 98 | const LAST_MONGO_SCHEMA_VERSION = 15 |
72 | 99 | ||
73 | // Time to wait between requests to the friends (10 min) | 100 | // --------------------------------------------------------------------------- |
74 | let REQUESTS_INTERVAL = 600000 | ||
75 | |||
76 | const OAUTH_LIFETIME = { | ||
77 | ACCESS_TOKEN: 3600 * 4, // 4 hours | ||
78 | REFRESH_TOKEN: 1209600 // 2 weeks | ||
79 | } | ||
80 | |||
81 | // Number of results by default for the pagination | ||
82 | const PAGINATION_COUNT_DEFAULT = 15 | ||
83 | 101 | ||
84 | // 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 |
85 | const PODS_SCORE = { | 103 | const PODS_SCORE = { |
@@ -87,29 +105,22 @@ const PODS_SCORE = { | |||
87 | BONUS: 10 | 105 | BONUS: 10 |
88 | } | 106 | } |
89 | 107 | ||
108 | // Time to wait between requests to the friends (10 min) | ||
109 | let REQUESTS_INTERVAL = 600000 | ||
110 | |||
90 | // Number of requests in parallel we can make | 111 | // Number of requests in parallel we can make |
91 | const REQUESTS_IN_PARALLEL = 10 | 112 | const REQUESTS_IN_PARALLEL = 10 |
92 | 113 | ||
93 | // How many requests we put in request (request scheduler) | 114 | // How many requests we put in request |
94 | const REQUESTS_LIMIT = 10 | 115 | const REQUESTS_LIMIT = 10 |
95 | 116 | ||
96 | // Number of requests to retry for replay requests module | 117 | // Number of requests to retry for replay requests module |
97 | const RETRY_REQUESTS = 5 | 118 | const RETRY_REQUESTS = 5 |
98 | 119 | ||
99 | // Sortable columns per schema | 120 | // --------------------------------------------------------------------------- |
100 | const SEARCHABLE_COLUMNS = { | ||
101 | VIDEOS: [ 'name', 'magnetUri', 'podUrl', 'author', 'tags' ] | ||
102 | } | ||
103 | |||
104 | // Seeds in parallel we send to electron when "seed all" | ||
105 | // Once a video is in seeding state we seed another video etc | ||
106 | const SEEDS_IN_PARALLEL = 3 | ||
107 | 121 | ||
108 | // Sortable columns per schema | 122 | // Password encryption |
109 | const SORTABLE_COLUMNS = { | 123 | const BCRYPT_SALT_SIZE = 10 |
110 | USERS: [ 'username', '-username', 'createdDate', '-createdDate' ], | ||
111 | VIDEOS: [ 'name', '-name', 'duration', '-duration', 'createdDate', '-createdDate' ] | ||
112 | } | ||
113 | 124 | ||
114 | // Videos thumbnail size | 125 | // Videos thumbnail size |
115 | const THUMBNAILS_SIZE = '200x110' | 126 | const THUMBNAILS_SIZE = '200x110' |
@@ -122,36 +133,42 @@ const USER_ROLES = { | |||
122 | USER: 'user' | 133 | USER: 'user' |
123 | } | 134 | } |
124 | 135 | ||
136 | // Seeds in parallel we send to electron when "seed all" | ||
137 | // Once a video is in seeding state we seed another video etc | ||
138 | const SEEDS_IN_PARALLEL = 3 | ||
139 | |||
140 | // --------------------------------------------------------------------------- | ||
141 | |||
125 | // Special constants for a test instance | 142 | // Special constants for a test instance |
126 | if (isTestInstance() === true) { | 143 | if (isTestInstance() === true) { |
144 | CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14 | ||
127 | FRIEND_SCORE.BASE = 20 | 145 | FRIEND_SCORE.BASE = 20 |
128 | REQUESTS_INTERVAL = 10000 | 146 | REQUESTS_INTERVAL = 10000 |
129 | CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14 | ||
130 | } | 147 | } |
131 | 148 | ||
132 | // --------------------------------------------------------------------------- | 149 | // --------------------------------------------------------------------------- |
133 | 150 | ||
134 | module.exports = { | 151 | module.exports = { |
135 | API_VERSION: API_VERSION, | 152 | API_VERSION, |
136 | BCRYPT_SALT_SIZE: BCRYPT_SALT_SIZE, | 153 | BCRYPT_SALT_SIZE, |
137 | CONFIG: CONFIG, | 154 | CONFIG, |
138 | CONSTRAINTS_FIELDS: CONSTRAINTS_FIELDS, | 155 | CONSTRAINTS_FIELDS, |
139 | FRIEND_SCORE: FRIEND_SCORE, | 156 | FRIEND_SCORE, |
140 | LAST_MONGO_SCHEMA_VERSION: LAST_MONGO_SCHEMA_VERSION, | 157 | LAST_MONGO_SCHEMA_VERSION, |
141 | MONGO_MIGRATION_SCRIPTS: MONGO_MIGRATION_SCRIPTS, | 158 | MONGO_MIGRATION_SCRIPTS, |
142 | OAUTH_LIFETIME: OAUTH_LIFETIME, | 159 | OAUTH_LIFETIME, |
143 | PAGINATION_COUNT_DEFAULT: PAGINATION_COUNT_DEFAULT, | 160 | PAGINATION_COUNT_DEFAULT, |
144 | PODS_SCORE: PODS_SCORE, | 161 | PODS_SCORE, |
145 | REQUESTS_IN_PARALLEL: REQUESTS_IN_PARALLEL, | 162 | REQUESTS_IN_PARALLEL, |
146 | REQUESTS_INTERVAL: REQUESTS_INTERVAL, | 163 | REQUESTS_INTERVAL, |
147 | REQUESTS_LIMIT: REQUESTS_LIMIT, | 164 | REQUESTS_LIMIT, |
148 | RETRY_REQUESTS: RETRY_REQUESTS, | 165 | RETRY_REQUESTS, |
149 | SEARCHABLE_COLUMNS: SEARCHABLE_COLUMNS, | 166 | SEARCHABLE_COLUMNS, |
150 | SEEDS_IN_PARALLEL: SEEDS_IN_PARALLEL, | 167 | SEEDS_IN_PARALLEL, |
151 | SORTABLE_COLUMNS: SORTABLE_COLUMNS, | 168 | SORTABLE_COLUMNS, |
152 | THUMBNAILS_SIZE: THUMBNAILS_SIZE, | 169 | THUMBNAILS_SIZE, |
153 | THUMBNAILS_STATIC_PATH: THUMBNAILS_STATIC_PATH, | 170 | THUMBNAILS_STATIC_PATH, |
154 | USER_ROLES: USER_ROLES | 171 | USER_ROLES |
155 | } | 172 | } |
156 | 173 | ||
157 | // --------------------------------------------------------------------------- | 174 | // --------------------------------------------------------------------------- |