diff options
Diffstat (limited to 'server/initializers/constants.ts')
-rw-r--r-- | server/initializers/constants.ts | 343 |
1 files changed, 343 insertions, 0 deletions
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts new file mode 100644 index 000000000..6bdc261ad --- /dev/null +++ b/server/initializers/constants.ts | |||
@@ -0,0 +1,343 @@ | |||
1 | import config = require('config') | ||
2 | import { join } from 'path' | ||
3 | |||
4 | // --------------------------------------------------------------------------- | ||
5 | |||
6 | const LAST_MIGRATION_VERSION = 50 | ||
7 | |||
8 | // --------------------------------------------------------------------------- | ||
9 | |||
10 | // API version | ||
11 | const API_VERSION = 'v1' | ||
12 | |||
13 | // Number of results by default for the pagination | ||
14 | const PAGINATION_COUNT_DEFAULT = 15 | ||
15 | |||
16 | // Sortable columns per schema | ||
17 | const SEARCHABLE_COLUMNS = { | ||
18 | VIDEOS: [ 'name', 'magnetUri', 'host', 'author', 'tags' ] | ||
19 | } | ||
20 | |||
21 | // Sortable columns per schema | ||
22 | const SORTABLE_COLUMNS = { | ||
23 | USERS: [ 'id', 'username', 'createdAt' ], | ||
24 | VIDEO_ABUSES: [ 'id', 'createdAt' ], | ||
25 | VIDEOS: [ 'name', 'duration', 'createdAt', 'views', 'likes' ] | ||
26 | } | ||
27 | |||
28 | const OAUTH_LIFETIME = { | ||
29 | ACCESS_TOKEN: 3600 * 4, // 4 hours | ||
30 | REFRESH_TOKEN: 1209600 // 2 weeks | ||
31 | } | ||
32 | |||
33 | // --------------------------------------------------------------------------- | ||
34 | |||
35 | const CONFIG = { | ||
36 | LISTEN: { | ||
37 | PORT: config.get<number>('listen.port') | ||
38 | }, | ||
39 | DATABASE: { | ||
40 | DBNAME: 'peertube' + config.get<string>('database.suffix'), | ||
41 | HOSTNAME: config.get<string>('database.hostname'), | ||
42 | PORT: config.get<number>('database.port'), | ||
43 | USERNAME: config.get<string>('database.username'), | ||
44 | PASSWORD: config.get<string>('database.password') | ||
45 | }, | ||
46 | STORAGE: { | ||
47 | CERT_DIR: join(__dirname, '..', '..', config.get<string>('storage.certs')), | ||
48 | LOG_DIR: join(__dirname, '..', '..', config.get<string>('storage.logs')), | ||
49 | VIDEOS_DIR: join(__dirname, '..', '..', config.get<string>('storage.videos')), | ||
50 | THUMBNAILS_DIR: join(__dirname, '..', '..', config.get<string>('storage.thumbnails')), | ||
51 | PREVIEWS_DIR: join(__dirname, '..', '..', config.get<string>('storage.previews')), | ||
52 | TORRENTS_DIR: join(__dirname, '..', '..', config.get<string>('storage.torrents')) | ||
53 | }, | ||
54 | WEBSERVER: { | ||
55 | SCHEME: config.get<boolean>('webserver.https') === true ? 'https' : 'http', | ||
56 | WS: config.get<boolean>('webserver.https') === true ? 'wss' : 'ws', | ||
57 | HOSTNAME: config.get<string>('webserver.hostname'), | ||
58 | PORT: config.get<number>('webserver.port'), | ||
59 | URL: '', | ||
60 | HOST: '' | ||
61 | }, | ||
62 | ADMIN: { | ||
63 | EMAIL: config.get<string>('admin.email') | ||
64 | }, | ||
65 | SIGNUP: { | ||
66 | ENABLED: config.get<boolean>('signup.enabled') | ||
67 | }, | ||
68 | TRANSCODING: { | ||
69 | ENABLED: config.get<boolean>('transcoding.enabled'), | ||
70 | THREADS: config.get<number>('transcoding.threads') | ||
71 | } | ||
72 | } | ||
73 | CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT | ||
74 | CONFIG.WEBSERVER.HOST = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT | ||
75 | |||
76 | // --------------------------------------------------------------------------- | ||
77 | |||
78 | const CONSTRAINTS_FIELDS = { | ||
79 | USERS: { | ||
80 | USERNAME: { min: 3, max: 20 }, // Length | ||
81 | PASSWORD: { min: 6, max: 255 } // Length | ||
82 | }, | ||
83 | VIDEO_ABUSES: { | ||
84 | REASON: { min: 2, max: 300 } // Length | ||
85 | }, | ||
86 | VIDEOS: { | ||
87 | NAME: { min: 3, max: 50 }, // Length | ||
88 | DESCRIPTION: { min: 3, max: 250 }, // Length | ||
89 | EXTNAME: [ '.mp4', '.ogv', '.webm' ], | ||
90 | INFO_HASH: { min: 40, max: 40 }, // Length, infohash is 20 bytes length but we represent it in hexa so 20 * 2 | ||
91 | DURATION: { min: 1, max: 7200 }, // Number | ||
92 | TAGS: { min: 0, max: 3 }, // Number of total tags | ||
93 | TAG: { min: 2, max: 10 }, // Length | ||
94 | THUMBNAIL: { min: 2, max: 30 }, | ||
95 | THUMBNAIL_DATA: { min: 0, max: 20000 }, // Bytes | ||
96 | VIEWS: { min: 0 }, | ||
97 | LIKES: { min: 0 }, | ||
98 | DISLIKES: { min: 0 } | ||
99 | }, | ||
100 | VIDEO_EVENTS: { | ||
101 | COUNT: { min: 0 } | ||
102 | } | ||
103 | } | ||
104 | |||
105 | const VIDEO_RATE_TYPES = { | ||
106 | LIKE: 'like', | ||
107 | DISLIKE: 'dislike' | ||
108 | } | ||
109 | |||
110 | const VIDEO_CATEGORIES = { | ||
111 | 1: 'Music', | ||
112 | 2: 'Films', | ||
113 | 3: 'Vehicles', | ||
114 | 4: 'Art', | ||
115 | 5: 'Sports', | ||
116 | 6: 'Travels', | ||
117 | 7: 'Gaming', | ||
118 | 8: 'People', | ||
119 | 9: 'Comedy', | ||
120 | 10: 'Entertainment', | ||
121 | 11: 'News', | ||
122 | 12: 'Howto', | ||
123 | 13: 'Education', | ||
124 | 14: 'Activism', | ||
125 | 15: 'Science & Technology', | ||
126 | 16: 'Animals', | ||
127 | 17: 'Kids', | ||
128 | 18: 'Food' | ||
129 | } | ||
130 | |||
131 | // See https://creativecommons.org/licenses/?lang=en | ||
132 | const VIDEO_LICENCES = { | ||
133 | 1: 'Attribution', | ||
134 | 2: 'Attribution - Share Alike', | ||
135 | 3: 'Attribution - No Derivatives', | ||
136 | 4: 'Attribution - Non Commercial', | ||
137 | 5: 'Attribution - Non Commercial - Share Alike', | ||
138 | 6: 'Attribution - Non Commercial - No Derivatives', | ||
139 | 7: 'Public Domain Dedication' | ||
140 | } | ||
141 | |||
142 | // See https://en.wikipedia.org/wiki/List_of_languages_by_number_of_native_speakers#Nationalencyklopedin | ||
143 | const VIDEO_LANGUAGES = { | ||
144 | 1: 'English', | ||
145 | 2: 'Spanish', | ||
146 | 3: 'Mandarin', | ||
147 | 4: 'Hindi', | ||
148 | 5: 'Arabic', | ||
149 | 6: 'Portuguese', | ||
150 | 7: 'Bengali', | ||
151 | 8: 'Russian', | ||
152 | 9: 'Japanese', | ||
153 | 10: 'Punjabi', | ||
154 | 11: 'German', | ||
155 | 12: 'Korean', | ||
156 | 13: 'French', | ||
157 | 14: 'Italien' | ||
158 | } | ||
159 | |||
160 | // --------------------------------------------------------------------------- | ||
161 | |||
162 | // Score a pod has when we create it as a friend | ||
163 | const FRIEND_SCORE = { | ||
164 | BASE: 100, | ||
165 | MAX: 1000 | ||
166 | } | ||
167 | |||
168 | // --------------------------------------------------------------------------- | ||
169 | |||
170 | // Number of points we add/remove from a friend after a successful/bad request | ||
171 | const PODS_SCORE = { | ||
172 | MALUS: -10, | ||
173 | BONUS: 10 | ||
174 | } | ||
175 | |||
176 | // Time to wait between requests to the friends (10 min) | ||
177 | let REQUESTS_INTERVAL = 600000 | ||
178 | |||
179 | // Number of requests in parallel we can make | ||
180 | const REQUESTS_IN_PARALLEL = 10 | ||
181 | |||
182 | // To how many pods we send requests | ||
183 | const REQUESTS_LIMIT_PODS = 10 | ||
184 | // How many requests we send to a pod per interval | ||
185 | const REQUESTS_LIMIT_PER_POD = 5 | ||
186 | |||
187 | const REQUESTS_VIDEO_QADU_LIMIT_PODS = 10 | ||
188 | // The QADU requests are not big | ||
189 | const REQUESTS_VIDEO_QADU_LIMIT_PER_POD = 50 | ||
190 | |||
191 | const REQUESTS_VIDEO_EVENT_LIMIT_PODS = 10 | ||
192 | // The EVENTS requests are not big | ||
193 | const REQUESTS_VIDEO_EVENT_LIMIT_PER_POD = 50 | ||
194 | |||
195 | // Number of requests to retry for replay requests module | ||
196 | const RETRY_REQUESTS = 5 | ||
197 | |||
198 | const REQUEST_ENDPOINTS = { | ||
199 | VIDEOS: 'videos' | ||
200 | } | ||
201 | |||
202 | const REQUEST_ENDPOINT_ACTIONS = {} | ||
203 | REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS] = { | ||
204 | ADD: 'add', | ||
205 | UPDATE: 'update', | ||
206 | REMOVE: 'remove', | ||
207 | REPORT_ABUSE: 'report-abuse' | ||
208 | } | ||
209 | |||
210 | const REQUEST_VIDEO_QADU_ENDPOINT = 'videos/qadu' | ||
211 | const REQUEST_VIDEO_EVENT_ENDPOINT = 'videos/events' | ||
212 | |||
213 | const REQUEST_VIDEO_QADU_TYPES = { | ||
214 | LIKES: 'likes', | ||
215 | DISLIKES: 'dislikes', | ||
216 | VIEWS: 'views' | ||
217 | } | ||
218 | |||
219 | const REQUEST_VIDEO_EVENT_TYPES = { | ||
220 | LIKES: 'likes', | ||
221 | DISLIKES: 'dislikes', | ||
222 | VIEWS: 'views' | ||
223 | } | ||
224 | |||
225 | const REMOTE_SCHEME = { | ||
226 | HTTP: 'https', | ||
227 | WS: 'wss' | ||
228 | } | ||
229 | |||
230 | const JOB_STATES = { | ||
231 | PENDING: 'pending', | ||
232 | PROCESSING: 'processing', | ||
233 | ERROR: 'error', | ||
234 | SUCCESS: 'success' | ||
235 | } | ||
236 | // How many maximum jobs we fetch from the database per cycle | ||
237 | const JOBS_FETCH_LIMIT_PER_CYCLE = 10 | ||
238 | const JOBS_CONCURRENCY = 1 | ||
239 | // 1 minutes | ||
240 | let JOBS_FETCHING_INTERVAL = 60000 | ||
241 | |||
242 | // --------------------------------------------------------------------------- | ||
243 | |||
244 | const PRIVATE_CERT_NAME = 'peertube.key.pem' | ||
245 | const PUBLIC_CERT_NAME = 'peertube.pub' | ||
246 | const SIGNATURE_ALGORITHM = 'RSA-SHA256' | ||
247 | const SIGNATURE_ENCODING = 'hex' | ||
248 | |||
249 | // Password encryption | ||
250 | const BCRYPT_SALT_SIZE = 10 | ||
251 | |||
252 | // --------------------------------------------------------------------------- | ||
253 | |||
254 | // Express static paths (router) | ||
255 | const STATIC_PATHS = { | ||
256 | PREVIEWS: '/static/previews/', | ||
257 | THUMBNAILS: '/static/thumbnails/', | ||
258 | TORRENTS: '/static/torrents/', | ||
259 | WEBSEED: '/static/webseed/' | ||
260 | } | ||
261 | |||
262 | // Cache control | ||
263 | let STATIC_MAX_AGE = '30d' | ||
264 | |||
265 | // Videos thumbnail size | ||
266 | const THUMBNAILS_SIZE = '200x110' | ||
267 | const PREVIEWS_SIZE = '640x480' | ||
268 | |||
269 | // --------------------------------------------------------------------------- | ||
270 | |||
271 | const USER_ROLES = { | ||
272 | ADMIN: 'admin', | ||
273 | USER: 'user' | ||
274 | } | ||
275 | |||
276 | // --------------------------------------------------------------------------- | ||
277 | |||
278 | // Special constants for a test instance | ||
279 | if (isTestInstance() === true) { | ||
280 | CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14 | ||
281 | FRIEND_SCORE.BASE = 20 | ||
282 | REQUESTS_INTERVAL = 10000 | ||
283 | JOBS_FETCHING_INTERVAL = 10000 | ||
284 | REMOTE_SCHEME.HTTP = 'http' | ||
285 | REMOTE_SCHEME.WS = 'ws' | ||
286 | STATIC_MAX_AGE = '0' | ||
287 | } | ||
288 | |||
289 | // --------------------------------------------------------------------------- | ||
290 | |||
291 | export { | ||
292 | API_VERSION, | ||
293 | BCRYPT_SALT_SIZE, | ||
294 | CONFIG, | ||
295 | CONSTRAINTS_FIELDS, | ||
296 | FRIEND_SCORE, | ||
297 | JOBS_FETCHING_INTERVAL, | ||
298 | JOB_STATES, | ||
299 | JOBS_CONCURRENCY, | ||
300 | JOBS_FETCH_LIMIT_PER_CYCLE, | ||
301 | LAST_MIGRATION_VERSION, | ||
302 | OAUTH_LIFETIME, | ||
303 | PAGINATION_COUNT_DEFAULT, | ||
304 | PODS_SCORE, | ||
305 | PREVIEWS_SIZE, | ||
306 | PRIVATE_CERT_NAME, | ||
307 | PUBLIC_CERT_NAME, | ||
308 | REMOTE_SCHEME, | ||
309 | REQUEST_ENDPOINT_ACTIONS, | ||
310 | REQUEST_ENDPOINTS, | ||
311 | REQUEST_VIDEO_EVENT_ENDPOINT, | ||
312 | REQUEST_VIDEO_EVENT_TYPES, | ||
313 | REQUEST_VIDEO_QADU_ENDPOINT, | ||
314 | REQUEST_VIDEO_QADU_TYPES, | ||
315 | REQUESTS_IN_PARALLEL, | ||
316 | REQUESTS_INTERVAL, | ||
317 | REQUESTS_LIMIT_PER_POD, | ||
318 | REQUESTS_LIMIT_PODS, | ||
319 | REQUESTS_VIDEO_EVENT_LIMIT_PER_POD, | ||
320 | REQUESTS_VIDEO_EVENT_LIMIT_PODS, | ||
321 | REQUESTS_VIDEO_QADU_LIMIT_PER_POD, | ||
322 | REQUESTS_VIDEO_QADU_LIMIT_PODS, | ||
323 | RETRY_REQUESTS, | ||
324 | SEARCHABLE_COLUMNS, | ||
325 | SIGNATURE_ALGORITHM, | ||
326 | SIGNATURE_ENCODING, | ||
327 | SORTABLE_COLUMNS, | ||
328 | STATIC_MAX_AGE, | ||
329 | STATIC_PATHS, | ||
330 | THUMBNAILS_SIZE, | ||
331 | USER_ROLES, | ||
332 | VIDEO_CATEGORIES, | ||
333 | VIDEO_LANGUAGES, | ||
334 | VIDEO_LICENCES, | ||
335 | VIDEO_RATE_TYPES | ||
336 | } | ||
337 | |||
338 | // --------------------------------------------------------------------------- | ||
339 | |||
340 | // This method exists in utils module but we want to let the constants module independent | ||
341 | function isTestInstance () { | ||
342 | return (process.env.NODE_ENV === 'test') | ||
343 | } | ||