]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/initializers/constants.ts
adccb9f418b5234d9681782ee57e7301f7a64b52
[github/Chocobozzz/PeerTube.git] / server / initializers / constants.ts
1 import * as config from 'config'
2 import { join } from 'path'
3
4 // Do not use barrels, remain constants as independent as possible
5 import { root, isTestInstance } from '../helpers/core-utils'
6
7 import {
8 VideoRateType,
9 RequestEndpoint,
10 RequestVideoEventType,
11 RequestVideoQaduType,
12 RemoteVideoRequestType,
13 JobState
14 } from '../../shared/models'
15
16 // ---------------------------------------------------------------------------
17
18 const LAST_MIGRATION_VERSION = 90
19
20 // ---------------------------------------------------------------------------
21
22 // API version
23 const API_VERSION = 'v1'
24
25 // Number of results by default for the pagination
26 const PAGINATION_COUNT_DEFAULT = 15
27
28 // Sortable columns per schema
29 const SEARCHABLE_COLUMNS = {
30 VIDEOS: [ 'name', 'magnetUri', 'host', 'author', 'tags' ]
31 }
32
33 // Sortable columns per schema
34 const SORTABLE_COLUMNS = {
35 PODS: [ 'id', 'host', 'score', 'createdAt' ],
36 USERS: [ 'id', 'username', 'createdAt' ],
37 VIDEO_ABUSES: [ 'id', 'createdAt' ],
38 VIDEO_CHANNELS: [ 'id', 'name', 'updatedAt', 'createdAt' ],
39 VIDEOS: [ 'name', 'duration', 'createdAt', 'views', 'likes' ],
40 BLACKLISTS: [ 'id', 'name', 'duration', 'views', 'likes', 'dislikes', 'uuid', 'createdAt' ]
41 }
42
43 const OAUTH_LIFETIME = {
44 ACCESS_TOKEN: 3600 * 4, // 4 hours
45 REFRESH_TOKEN: 1209600 // 2 weeks
46 }
47
48 // ---------------------------------------------------------------------------
49
50 const CONFIG = {
51 LISTEN: {
52 PORT: config.get<number>('listen.port')
53 },
54 DATABASE: {
55 DBNAME: 'peertube' + config.get<string>('database.suffix'),
56 HOSTNAME: config.get<string>('database.hostname'),
57 PORT: config.get<number>('database.port'),
58 USERNAME: config.get<string>('database.username'),
59 PASSWORD: config.get<string>('database.password')
60 },
61 STORAGE: {
62 CERT_DIR: join(root(), config.get<string>('storage.certs')),
63 LOG_DIR: join(root(), config.get<string>('storage.logs')),
64 VIDEOS_DIR: join(root(), config.get<string>('storage.videos')),
65 THUMBNAILS_DIR: join(root(), config.get<string>('storage.thumbnails')),
66 PREVIEWS_DIR: join(root(), config.get<string>('storage.previews')),
67 TORRENTS_DIR: join(root(), config.get<string>('storage.torrents')),
68 CACHE_DIR: join(root(), config.get<string>('storage.cache'))
69 },
70 WEBSERVER: {
71 SCHEME: config.get<boolean>('webserver.https') === true ? 'https' : 'http',
72 WS: config.get<boolean>('webserver.https') === true ? 'wss' : 'ws',
73 HOSTNAME: config.get<string>('webserver.hostname'),
74 PORT: config.get<number>('webserver.port'),
75 URL: '',
76 HOST: ''
77 },
78 ADMIN: {
79 EMAIL: config.get<string>('admin.email')
80 },
81 SIGNUP: {
82 ENABLED: config.get<boolean>('signup.enabled'),
83 LIMIT: config.get<number>('signup.limit')
84 },
85 USER: {
86 VIDEO_QUOTA: config.get<number>('user.video_quota')
87 },
88 TRANSCODING: {
89 ENABLED: config.get<boolean>('transcoding.enabled'),
90 THREADS: config.get<number>('transcoding.threads'),
91 RESOLUTIONS: {
92 '240' : config.get<boolean>('transcoding.resolutions.240p'),
93 '360': config.get<boolean>('transcoding.resolutions.360p'),
94 '480': config.get<boolean>('transcoding.resolutions.480p'),
95 '720': config.get<boolean>('transcoding.resolutions.720p'),
96 '1080': config.get<boolean>('transcoding.resolutions.1080p')
97 }
98 },
99 CACHE: {
100 PREVIEWS: {
101 SIZE: config.get<number>('cache.previews.size')
102 }
103 }
104 }
105 CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
106 CONFIG.WEBSERVER.HOST = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
107
108 // ---------------------------------------------------------------------------
109
110 const CONSTRAINTS_FIELDS = {
111 USERS: {
112 USERNAME: { min: 3, max: 20 }, // Length
113 PASSWORD: { min: 6, max: 255 }, // Length
114 VIDEO_QUOTA: { min: -1 }
115 },
116 VIDEO_ABUSES: {
117 REASON: { min: 2, max: 300 } // Length
118 },
119 VIDEO_CHANNELS: {
120 NAME: { min: 3, max: 120 }, // Length
121 DESCRIPTION: { min: 3, max: 250 } // Length
122 },
123 VIDEOS: {
124 NAME: { min: 3, max: 120 }, // Length
125 TRUNCATED_DESCRIPTION: { min: 3, max: 250 }, // Length
126 DESCRIPTION: { min: 3, max: 3000 }, // Length
127 EXTNAME: [ '.mp4', '.ogv', '.webm' ],
128 INFO_HASH: { min: 40, max: 40 }, // Length, info hash is 20 bytes length but we represent it in hexadecimal so 20 * 2
129 DURATION: { min: 1, max: 7200 }, // Number
130 TAGS: { min: 0, max: 5 }, // Number of total tags
131 TAG: { min: 2, max: 30 }, // Length
132 THUMBNAIL: { min: 2, max: 30 },
133 THUMBNAIL_DATA: { min: 0, max: 20000 }, // Bytes
134 VIEWS: { min: 0 },
135 LIKES: { min: 0 },
136 DISLIKES: { min: 0 },
137 FILE_SIZE: { min: 10, max: 1024 * 1024 * 1024 * 3 /* 3Go */ }
138 },
139 VIDEO_EVENTS: {
140 COUNT: { min: 0 }
141 }
142 }
143
144 const VIDEO_RATE_TYPES: { [ id: string ]: VideoRateType } = {
145 LIKE: 'like',
146 DISLIKE: 'dislike'
147 }
148
149 const VIDEO_CATEGORIES = {
150 1: 'Music',
151 2: 'Films',
152 3: 'Vehicles',
153 4: 'Art',
154 5: 'Sports',
155 6: 'Travels',
156 7: 'Gaming',
157 8: 'People',
158 9: 'Comedy',
159 10: 'Entertainment',
160 11: 'News',
161 12: 'How To',
162 13: 'Education',
163 14: 'Activism',
164 15: 'Science & Technology',
165 16: 'Animals',
166 17: 'Kids',
167 18: 'Food'
168 }
169
170 // See https://creativecommons.org/licenses/?lang=en
171 const VIDEO_LICENCES = {
172 1: 'Attribution',
173 2: 'Attribution - Share Alike',
174 3: 'Attribution - No Derivatives',
175 4: 'Attribution - Non Commercial',
176 5: 'Attribution - Non Commercial - Share Alike',
177 6: 'Attribution - Non Commercial - No Derivatives',
178 7: 'Public Domain Dedication'
179 }
180
181 // See https://en.wikipedia.org/wiki/List_of_languages_by_number_of_native_speakers#Nationalencyklopedin
182 const VIDEO_LANGUAGES = {
183 1: 'English',
184 2: 'Spanish',
185 3: 'Mandarin',
186 4: 'Hindi',
187 5: 'Arabic',
188 6: 'Portuguese',
189 7: 'Bengali',
190 8: 'Russian',
191 9: 'Japanese',
192 10: 'Punjabi',
193 11: 'German',
194 12: 'Korean',
195 13: 'French',
196 14: 'Italian'
197 }
198
199 // ---------------------------------------------------------------------------
200
201 // Score a pod has when we create it as a friend
202 const FRIEND_SCORE = {
203 BASE: 100,
204 MAX: 1000
205 }
206
207 // ---------------------------------------------------------------------------
208
209 // Number of points we add/remove from a friend after a successful/bad request
210 const PODS_SCORE = {
211 PENALTY: -10,
212 BONUS: 10
213 }
214
215 // Time to wait between requests to the friends (10 min)
216 let REQUESTS_INTERVAL = 600000
217
218 // Number of requests in parallel we can make
219 const REQUESTS_IN_PARALLEL = 10
220
221 // To how many pods we send requests
222 const REQUESTS_LIMIT_PODS = 10
223 // How many requests we send to a pod per interval
224 const REQUESTS_LIMIT_PER_POD = 5
225
226 const REQUESTS_VIDEO_QADU_LIMIT_PODS = 10
227 // The QADU requests are not big
228 const REQUESTS_VIDEO_QADU_LIMIT_PER_POD = 50
229
230 const REQUESTS_VIDEO_EVENT_LIMIT_PODS = 10
231 // The EVENTS requests are not big
232 const REQUESTS_VIDEO_EVENT_LIMIT_PER_POD = 50
233
234 // Number of requests to retry for replay requests module
235 const RETRY_REQUESTS = 5
236
237 const REQUEST_ENDPOINTS: { [ id: string ]: RequestEndpoint } = {
238 VIDEOS: 'videos'
239 }
240
241 const REQUEST_ENDPOINT_ACTIONS: {
242 [ id: string ]: {
243 [ id: string ]: RemoteVideoRequestType
244 }
245 } = {}
246 REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS] = {
247 ADD_VIDEO: 'add-video',
248 UPDATE_VIDEO: 'update-video',
249 REMOVE_VIDEO: 'remove-video',
250 ADD_CHANNEL: 'add-channel',
251 UPDATE_CHANNEL: 'update-channel',
252 REMOVE_CHANNEL: 'remove-channel',
253 ADD_AUTHOR: 'add-author',
254 REMOVE_AUTHOR: 'remove-author',
255 REPORT_ABUSE: 'report-abuse'
256 }
257
258 const REQUEST_VIDEO_QADU_ENDPOINT = 'videos/qadu'
259 const REQUEST_VIDEO_EVENT_ENDPOINT = 'videos/events'
260
261 const REQUEST_VIDEO_QADU_TYPES: { [ id: string ]: RequestVideoQaduType } = {
262 LIKES: 'likes',
263 DISLIKES: 'dislikes',
264 VIEWS: 'views'
265 }
266
267 const REQUEST_VIDEO_EVENT_TYPES: { [ id: string ]: RequestVideoEventType } = {
268 LIKES: 'likes',
269 DISLIKES: 'dislikes',
270 VIEWS: 'views'
271 }
272
273 const REMOTE_SCHEME = {
274 HTTP: 'https',
275 WS: 'wss'
276 }
277
278 const JOB_STATES: { [ id: string ]: JobState } = {
279 PENDING: 'pending',
280 PROCESSING: 'processing',
281 ERROR: 'error',
282 SUCCESS: 'success'
283 }
284 // How many maximum jobs we fetch from the database per cycle
285 const JOBS_FETCH_LIMIT_PER_CYCLE = 10
286 // 1 minutes
287 let JOBS_FETCHING_INTERVAL = 60000
288
289 // ---------------------------------------------------------------------------
290
291 const PRIVATE_CERT_NAME = 'peertube.key.pem'
292 const PUBLIC_CERT_NAME = 'peertube.pub'
293 const SIGNATURE_ALGORITHM = 'RSA-SHA256'
294 const SIGNATURE_ENCODING = 'hex'
295
296 // Password encryption
297 const BCRYPT_SALT_SIZE = 10
298
299 // ---------------------------------------------------------------------------
300
301 // Express static paths (router)
302 const STATIC_PATHS = {
303 PREVIEWS: '/static/previews/',
304 THUMBNAILS: '/static/thumbnails/',
305 TORRENTS: '/static/torrents/',
306 WEBSEED: '/static/webseed/'
307 }
308
309 // Cache control
310 let STATIC_MAX_AGE = '30d'
311
312 // Videos thumbnail size
313 const THUMBNAILS_SIZE = {
314 width: 200,
315 height: 110
316 }
317 const PREVIEWS_SIZE = {
318 width: 560,
319 height: 315
320 }
321
322 const EMBED_SIZE = {
323 width: 560,
324 height: 315
325 }
326
327 // Sub folders of cache directory
328 const CACHE = {
329 DIRECTORIES: {
330 PREVIEWS: join(CONFIG.STORAGE.CACHE_DIR, 'previews')
331 }
332 }
333
334 // ---------------------------------------------------------------------------
335
336 const OPENGRAPH_AND_OEMBED_COMMENT = '<!-- open graph and oembed tags -->'
337
338 // ---------------------------------------------------------------------------
339
340 // Special constants for a test instance
341 if (isTestInstance() === true) {
342 CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14
343 FRIEND_SCORE.BASE = 20
344 REQUESTS_INTERVAL = 10000
345 JOBS_FETCHING_INTERVAL = 10000
346 REMOTE_SCHEME.HTTP = 'http'
347 REMOTE_SCHEME.WS = 'ws'
348 STATIC_MAX_AGE = '0'
349 }
350
351 // ---------------------------------------------------------------------------
352
353 export {
354 API_VERSION,
355 BCRYPT_SALT_SIZE,
356 CACHE,
357 CONFIG,
358 CONSTRAINTS_FIELDS,
359 EMBED_SIZE,
360 FRIEND_SCORE,
361 JOB_STATES,
362 JOBS_FETCH_LIMIT_PER_CYCLE,
363 JOBS_FETCHING_INTERVAL,
364 LAST_MIGRATION_VERSION,
365 OAUTH_LIFETIME,
366 OPENGRAPH_AND_OEMBED_COMMENT,
367 PAGINATION_COUNT_DEFAULT,
368 PODS_SCORE,
369 PREVIEWS_SIZE,
370 PRIVATE_CERT_NAME,
371 PUBLIC_CERT_NAME,
372 REMOTE_SCHEME,
373 REQUEST_ENDPOINT_ACTIONS,
374 REQUEST_ENDPOINTS,
375 REQUEST_VIDEO_EVENT_ENDPOINT,
376 REQUEST_VIDEO_EVENT_TYPES,
377 REQUEST_VIDEO_QADU_ENDPOINT,
378 REQUEST_VIDEO_QADU_TYPES,
379 REQUESTS_IN_PARALLEL,
380 REQUESTS_INTERVAL,
381 REQUESTS_LIMIT_PER_POD,
382 REQUESTS_LIMIT_PODS,
383 REQUESTS_VIDEO_EVENT_LIMIT_PER_POD,
384 REQUESTS_VIDEO_EVENT_LIMIT_PODS,
385 REQUESTS_VIDEO_QADU_LIMIT_PER_POD,
386 REQUESTS_VIDEO_QADU_LIMIT_PODS,
387 RETRY_REQUESTS,
388 SEARCHABLE_COLUMNS,
389 SIGNATURE_ALGORITHM,
390 SIGNATURE_ENCODING,
391 SORTABLE_COLUMNS,
392 STATIC_MAX_AGE,
393 STATIC_PATHS,
394 THUMBNAILS_SIZE,
395 VIDEO_CATEGORIES,
396 VIDEO_LANGUAGES,
397 VIDEO_LICENCES,
398 VIDEO_RATE_TYPES
399 }