]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/initializers/constants.ts
Added "zxx" (no linguistic content) in available video languages (#4631)
[github/Chocobozzz/PeerTube.git] / server / initializers / constants.ts
1 import { CronRepeatOptions, EveryRepeatOptions } from 'bull'
2 import { randomBytes } from 'crypto'
3 import { invert } from 'lodash'
4 import { join } from 'path'
5 import { randomInt } from '../../shared/core-utils/common/miscs'
6 import {
7 AbuseState,
8 JobType,
9 VideoImportState,
10 VideoPrivacy,
11 VideoRateType,
12 VideoResolution,
13 VideoState,
14 VideoTranscodingFPS
15 } from '../../shared/models'
16 import { ActivityPubActorType } from '../../shared/models/activitypub'
17 import { FollowState } from '../../shared/models/actors'
18 import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type'
19 import { VideoPlaylistPrivacy } from '../../shared/models/videos/playlist/video-playlist-privacy.model'
20 import { VideoPlaylistType } from '../../shared/models/videos/playlist/video-playlist-type.model'
21 // Do not use barrels, remain constants as independent as possible
22 import { isTestInstance, root, sanitizeHost, sanitizeUrl } from '../helpers/core-utils'
23 import { CONFIG, registerConfigChangedHandler } from './config'
24
25 // ---------------------------------------------------------------------------
26
27 const LAST_MIGRATION_VERSION = 670
28
29 // ---------------------------------------------------------------------------
30
31 const API_VERSION = 'v1'
32 const PEERTUBE_VERSION: string = require(join(root(), 'package.json')).version
33
34 const PAGINATION = {
35 GLOBAL: {
36 COUNT: {
37 DEFAULT: 15,
38 MAX: 100
39 }
40 },
41 OUTBOX: {
42 COUNT: {
43 MAX: 50
44 }
45 }
46 }
47
48 const WEBSERVER = {
49 URL: '',
50 HOST: '',
51 SCHEME: '',
52 WS: '',
53 HOSTNAME: '',
54 PORT: 0,
55 RTMP_URL: '',
56 RTMPS_URL: ''
57 }
58
59 // Sortable columns per schema
60 const SORTABLE_COLUMNS = {
61 USERS: [ 'id', 'username', 'videoQuotaUsed', 'createdAt', 'lastLoginDate', 'role' ],
62 USER_SUBSCRIPTIONS: [ 'id', 'createdAt' ],
63 ACCOUNTS: [ 'createdAt' ],
64 JOBS: [ 'createdAt' ],
65 VIDEO_CHANNELS: [ 'id', 'name', 'updatedAt', 'createdAt' ],
66 VIDEO_IMPORTS: [ 'createdAt' ],
67
68 VIDEO_COMMENT_THREADS: [ 'createdAt', 'totalReplies' ],
69 VIDEO_COMMENTS: [ 'createdAt' ],
70
71 VIDEO_RATES: [ 'createdAt' ],
72 BLACKLISTS: [ 'id', 'name', 'duration', 'views', 'likes', 'dislikes', 'uuid', 'createdAt' ],
73
74 INSTANCE_FOLLOWERS: [ 'createdAt', 'state', 'score' ],
75 INSTANCE_FOLLOWING: [ 'createdAt', 'redundancyAllowed', 'state' ],
76 ACCOUNT_FOLLOWERS: [ 'createdAt' ],
77 CHANNEL_FOLLOWERS: [ 'createdAt' ],
78
79 VIDEOS: [ 'name', 'duration', 'createdAt', 'publishedAt', 'originallyPublishedAt', 'views', 'likes', 'trending', 'hot', 'best' ],
80
81 // Don't forget to update peertube-search-index with the same values
82 VIDEOS_SEARCH: [ 'name', 'duration', 'createdAt', 'publishedAt', 'originallyPublishedAt', 'views', 'likes', 'match' ],
83 VIDEO_CHANNELS_SEARCH: [ 'match', 'displayName', 'createdAt' ],
84 VIDEO_PLAYLISTS_SEARCH: [ 'match', 'displayName', 'createdAt' ],
85
86 ABUSES: [ 'id', 'createdAt', 'state' ],
87
88 ACCOUNTS_BLOCKLIST: [ 'createdAt' ],
89 SERVERS_BLOCKLIST: [ 'createdAt' ],
90
91 USER_NOTIFICATIONS: [ 'createdAt', 'read' ],
92
93 VIDEO_PLAYLISTS: [ 'name', 'displayName', 'createdAt', 'updatedAt' ],
94
95 PLUGINS: [ 'name', 'createdAt', 'updatedAt' ],
96
97 AVAILABLE_PLUGINS: [ 'npmName', 'popularity' ],
98
99 VIDEO_REDUNDANCIES: [ 'name' ]
100 }
101
102 const OAUTH_LIFETIME = {
103 ACCESS_TOKEN: 3600 * 24, // 1 day, for upload
104 REFRESH_TOKEN: 1209600 // 2 weeks
105 }
106
107 const ROUTE_CACHE_LIFETIME = {
108 FEEDS: '15 minutes',
109 ROBOTS: '2 hours',
110 SITEMAP: '1 day',
111 SECURITYTXT: '2 hours',
112 NODEINFO: '10 minutes',
113 DNT_POLICY: '1 week',
114 ACTIVITY_PUB: {
115 VIDEOS: '1 second' // 1 second, cache concurrent requests after a broadcast for example
116 },
117 STATS: '4 hours'
118 }
119
120 // ---------------------------------------------------------------------------
121
122 // Number of points we add/remove after a successful/bad request
123 const ACTOR_FOLLOW_SCORE = {
124 PENALTY: -10,
125 BONUS: 10,
126 BASE: 1000,
127 MAX: 10000
128 }
129
130 const FOLLOW_STATES: { [ id: string ]: FollowState } = {
131 PENDING: 'pending',
132 ACCEPTED: 'accepted'
133 }
134
135 const REMOTE_SCHEME = {
136 HTTP: 'https',
137 WS: 'wss'
138 }
139
140 const JOB_ATTEMPTS: { [id in JobType]: number } = {
141 'activitypub-http-broadcast': 1,
142 'activitypub-http-unicast': 1,
143 'activitypub-http-fetcher': 2,
144 'activitypub-follow': 5,
145 'activitypub-cleaner': 1,
146 'video-file-import': 1,
147 'video-transcoding': 1,
148 'video-import': 1,
149 'email': 5,
150 'actor-keys': 3,
151 'videos-views-stats': 1,
152 'activitypub-refresher': 1,
153 'video-redundancy': 1,
154 'video-live-ending': 1,
155 'move-to-object-storage': 3
156 }
157 // Excluded keys are jobs that can be configured by admins
158 const JOB_CONCURRENCY: { [id in Exclude<JobType, 'video-transcoding' | 'video-import'>]: number } = {
159 'activitypub-http-broadcast': 1,
160 'activitypub-http-unicast': 10,
161 'activitypub-http-fetcher': 3,
162 'activitypub-cleaner': 1,
163 'activitypub-follow': 1,
164 'video-file-import': 1,
165 'email': 5,
166 'actor-keys': 1,
167 'videos-views-stats': 1,
168 'activitypub-refresher': 1,
169 'video-redundancy': 1,
170 'video-live-ending': 10,
171 'move-to-object-storage': 1
172 }
173 const JOB_TTL: { [id in JobType]: number } = {
174 'activitypub-http-broadcast': 60000 * 10, // 10 minutes
175 'activitypub-http-unicast': 60000 * 10, // 10 minutes
176 'activitypub-http-fetcher': 1000 * 3600 * 10, // 10 hours
177 'activitypub-follow': 60000 * 10, // 10 minutes
178 'activitypub-cleaner': 1000 * 3600, // 1 hour
179 'video-file-import': 1000 * 3600, // 1 hour
180 'video-transcoding': 1000 * 3600 * 48, // 2 days, transcoding could be long
181 'video-import': 1000 * 3600 * 2, // 2 hours
182 'email': 60000 * 10, // 10 minutes
183 'actor-keys': 60000 * 20, // 20 minutes
184 'videos-views-stats': undefined, // Unlimited
185 'activitypub-refresher': 60000 * 10, // 10 minutes
186 'video-redundancy': 1000 * 3600 * 3, // 3 hours
187 'video-live-ending': 1000 * 60 * 10, // 10 minutes
188 'move-to-object-storage': 1000 * 60 * 60 * 3 // 3 hours
189 }
190 const REPEAT_JOBS: { [ id in JobType ]?: EveryRepeatOptions | CronRepeatOptions } = {
191 'videos-views-stats': {
192 cron: randomInt(1, 20) + ' * * * *' // Between 1-20 minutes past the hour
193 },
194 'activitypub-cleaner': {
195 cron: '30 5 * * ' + randomInt(0, 7) // 1 time per week (random day) at 5:30 AM
196 }
197 }
198 const JOB_PRIORITY = {
199 TRANSCODING: 100
200 }
201
202 const BROADCAST_CONCURRENCY = 30 // How many requests in parallel we do in activitypub-http-broadcast job
203 const AP_CLEANER_CONCURRENCY = 10 // How many requests in parallel we do in activitypub-cleaner job
204 const CRAWL_REQUEST_CONCURRENCY = 1 // How many requests in parallel to fetch remote data (likes, shares...)
205 const REQUEST_TIMEOUTS = {
206 DEFAULT: 7000, // 7 seconds
207 FILE: 30000, // 30 seconds
208 REDUNDANCY: JOB_TTL['video-redundancy']
209 }
210
211 const JOB_COMPLETED_LIFETIME = 60000 * 60 * 24 * 2 // 2 days
212 const VIDEO_IMPORT_TIMEOUT = 1000 * 3600 // 1 hour
213
214 const SCHEDULER_INTERVALS_MS = {
215 ACTOR_FOLLOW_SCORES: 60000 * 60, // 1 hour
216 REMOVE_OLD_JOBS: 60000 * 60, // 1 hour
217 UPDATE_VIDEOS: 60000, // 1 minute
218 YOUTUBE_DL_UPDATE: 60000 * 60 * 24, // 1 day
219 VIDEO_VIEWS_BUFFER_UPDATE: CONFIG.VIEWS.VIDEOS.LOCAL_BUFFER_UPDATE_INTERVAL,
220 CHECK_PLUGINS: CONFIG.PLUGINS.INDEX.CHECK_LATEST_VERSIONS_INTERVAL,
221 CHECK_PEERTUBE_VERSION: 60000 * 60 * 24, // 1 day
222 AUTO_FOLLOW_INDEX_INSTANCES: 60000 * 60 * 24, // 1 day
223 REMOVE_OLD_VIEWS: 60000 * 60 * 24, // 1 day
224 REMOVE_OLD_HISTORY: 60000 * 60 * 24, // 1 day
225 UPDATE_INBOX_STATS: 1000 * 60, // 1 minute
226 REMOVE_DANGLING_RESUMABLE_UPLOADS: 60000 * 60 // 1 hour
227 }
228
229 // ---------------------------------------------------------------------------
230
231 const CONSTRAINTS_FIELDS = {
232 USERS: {
233 NAME: { min: 1, max: 120 }, // Length
234 DESCRIPTION: { min: 3, max: 1000 }, // Length
235 USERNAME: { min: 1, max: 50 }, // Length
236 PASSWORD: { min: 6, max: 255 }, // Length
237 VIDEO_QUOTA: { min: -1 },
238 VIDEO_QUOTA_DAILY: { min: -1 },
239 VIDEO_LANGUAGES: { max: 500 }, // Array length
240 BLOCKED_REASON: { min: 3, max: 250 } // Length
241 },
242 ABUSES: {
243 REASON: { min: 2, max: 3000 }, // Length
244 MODERATION_COMMENT: { min: 2, max: 3000 } // Length
245 },
246 ABUSE_MESSAGES: {
247 MESSAGE: { min: 2, max: 3000 } // Length
248 },
249 VIDEO_BLACKLIST: {
250 REASON: { min: 2, max: 300 } // Length
251 },
252 VIDEO_CHANNELS: {
253 NAME: { min: 1, max: 120 }, // Length
254 DESCRIPTION: { min: 3, max: 1000 }, // Length
255 SUPPORT: { min: 3, max: 1000 }, // Length
256 URL: { min: 3, max: 2000 } // Length
257 },
258 VIDEO_CAPTIONS: {
259 CAPTION_FILE: {
260 EXTNAME: [ '.vtt', '.srt' ],
261 FILE_SIZE: {
262 max: 4 * 1024 * 1024 // 4MB
263 }
264 }
265 },
266 VIDEO_IMPORTS: {
267 URL: { min: 3, max: 2000 }, // Length
268 TORRENT_NAME: { min: 3, max: 255 }, // Length
269 TORRENT_FILE: {
270 EXTNAME: [ '.torrent' ],
271 FILE_SIZE: {
272 max: 1024 * 200 // 200 KB
273 }
274 }
275 },
276 VIDEOS_REDUNDANCY: {
277 URL: { min: 3, max: 2000 } // Length
278 },
279 VIDEO_RATES: {
280 URL: { min: 3, max: 2000 } // Length
281 },
282 VIDEOS: {
283 NAME: { min: 3, max: 120 }, // Length
284 LANGUAGE: { min: 1, max: 10 }, // Length
285 TRUNCATED_DESCRIPTION: { min: 3, max: 250 }, // Length
286 DESCRIPTION: { min: 3, max: 10000 }, // Length
287 SUPPORT: { min: 3, max: 1000 }, // Length
288 IMAGE: {
289 EXTNAME: [ '.png', '.jpg', '.jpeg', '.webp' ],
290 FILE_SIZE: {
291 max: 4 * 1024 * 1024 // 4MB
292 }
293 },
294 EXTNAME: [] as string[],
295 INFO_HASH: { min: 40, max: 40 }, // Length, info hash is 20 bytes length but we represent it in hexadecimal so 20 * 2
296 DURATION: { min: 0 }, // Number
297 TAGS: { min: 0, max: 5 }, // Number of total tags
298 TAG: { min: 2, max: 30 }, // Length
299 VIEWS: { min: 0 },
300 LIKES: { min: 0 },
301 DISLIKES: { min: 0 },
302 FILE_SIZE: { min: -1 },
303 PARTIAL_UPLOAD_SIZE: { max: 50 * 1024 * 1024 * 1024 }, // 50GB
304 URL: { min: 3, max: 2000 } // Length
305 },
306 VIDEO_PLAYLISTS: {
307 NAME: { min: 1, max: 120 }, // Length
308 DESCRIPTION: { min: 3, max: 1000 }, // Length
309 URL: { min: 3, max: 2000 }, // Length
310 IMAGE: {
311 EXTNAME: [ '.jpg', '.jpeg' ],
312 FILE_SIZE: {
313 max: 4 * 1024 * 1024 // 4MB
314 }
315 }
316 },
317 ACTORS: {
318 PUBLIC_KEY: { min: 10, max: 5000 }, // Length
319 PRIVATE_KEY: { min: 10, max: 5000 }, // Length
320 URL: { min: 3, max: 2000 }, // Length
321 IMAGE: {
322 EXTNAME: [ '.png', '.jpeg', '.jpg', '.gif', '.webp' ],
323 FILE_SIZE: {
324 max: 4 * 1024 * 1024 // 4MB
325 }
326 }
327 },
328 VIDEO_EVENTS: {
329 COUNT: { min: 0 }
330 },
331 VIDEO_COMMENTS: {
332 TEXT: { min: 1, max: 10000 }, // Length
333 URL: { min: 3, max: 2000 } // Length
334 },
335 VIDEO_SHARE: {
336 URL: { min: 3, max: 2000 } // Length
337 },
338 CONTACT_FORM: {
339 FROM_NAME: { min: 1, max: 120 }, // Length
340 BODY: { min: 3, max: 5000 } // Length
341 },
342 PLUGINS: {
343 NAME: { min: 1, max: 214 }, // Length
344 DESCRIPTION: { min: 1, max: 20000 } // Length
345 },
346 COMMONS: {
347 URL: { min: 5, max: 2000 } // Length
348 }
349 }
350
351 const VIEW_LIFETIME = {
352 VIEW: CONFIG.VIEWS.VIDEOS.IP_VIEW_EXPIRATION,
353 VIEWER: 60000 * 5 // 5 minutes
354 }
355
356 let CONTACT_FORM_LIFETIME = 60000 * 60 // 1 hour
357
358 const VIDEO_TRANSCODING_FPS: VideoTranscodingFPS = {
359 MIN: 1,
360 STANDARD: [ 24, 25, 30 ],
361 HD_STANDARD: [ 50, 60 ],
362 AVERAGE: 30,
363 MAX: 60,
364 KEEP_ORIGIN_FPS_RESOLUTION_MIN: 720 // We keep the original FPS on high resolutions (720 minimum)
365 }
366
367 const DEFAULT_AUDIO_RESOLUTION = VideoResolution.H_480P
368
369 const VIDEO_RATE_TYPES: { [ id: string ]: VideoRateType } = {
370 LIKE: 'like',
371 DISLIKE: 'dislike'
372 }
373
374 const FFMPEG_NICE: { [ id: string ]: number } = {
375 // parent process defaults to niceness = 0
376 // reminder: lower = higher priority, max value is 19, lowest is -20
377 LIVE: 5, // prioritize over VOD and THUMBNAIL
378 THUMBNAIL: 10,
379 VOD: 15
380 }
381
382 const VIDEO_CATEGORIES = {
383 1: 'Music',
384 2: 'Films',
385 3: 'Vehicles',
386 4: 'Art',
387 5: 'Sports',
388 6: 'Travels',
389 7: 'Gaming',
390 8: 'People',
391 9: 'Comedy',
392 10: 'Entertainment',
393 11: 'News & Politics',
394 12: 'How To',
395 13: 'Education',
396 14: 'Activism',
397 15: 'Science & Technology',
398 16: 'Animals',
399 17: 'Kids',
400 18: 'Food'
401 }
402
403 // See https://creativecommons.org/licenses/?lang=en
404 const VIDEO_LICENCES = {
405 1: 'Attribution',
406 2: 'Attribution - Share Alike',
407 3: 'Attribution - No Derivatives',
408 4: 'Attribution - Non Commercial',
409 5: 'Attribution - Non Commercial - Share Alike',
410 6: 'Attribution - Non Commercial - No Derivatives',
411 7: 'Public Domain Dedication'
412 }
413
414 const VIDEO_LANGUAGES: { [id: string]: string } = {}
415
416 const VIDEO_PRIVACIES: { [ id in VideoPrivacy ]: string } = {
417 [VideoPrivacy.PUBLIC]: 'Public',
418 [VideoPrivacy.UNLISTED]: 'Unlisted',
419 [VideoPrivacy.PRIVATE]: 'Private',
420 [VideoPrivacy.INTERNAL]: 'Internal'
421 }
422
423 const VIDEO_STATES: { [ id in VideoState ]: string } = {
424 [VideoState.PUBLISHED]: 'Published',
425 [VideoState.TO_TRANSCODE]: 'To transcode',
426 [VideoState.TO_IMPORT]: 'To import',
427 [VideoState.WAITING_FOR_LIVE]: 'Waiting for livestream',
428 [VideoState.LIVE_ENDED]: 'Livestream ended',
429 [VideoState.TO_MOVE_TO_EXTERNAL_STORAGE]: 'To move to an external storage',
430 [VideoState.TRANSCODING_FAILED]: 'Transcoding failed'
431 }
432
433 const VIDEO_IMPORT_STATES: { [ id in VideoImportState ]: string } = {
434 [VideoImportState.FAILED]: 'Failed',
435 [VideoImportState.PENDING]: 'Pending',
436 [VideoImportState.SUCCESS]: 'Success',
437 [VideoImportState.REJECTED]: 'Rejected'
438 }
439
440 const ABUSE_STATES: { [ id in AbuseState ]: string } = {
441 [AbuseState.PENDING]: 'Pending',
442 [AbuseState.REJECTED]: 'Rejected',
443 [AbuseState.ACCEPTED]: 'Accepted'
444 }
445
446 const VIDEO_PLAYLIST_PRIVACIES: { [ id in VideoPlaylistPrivacy ]: string } = {
447 [VideoPlaylistPrivacy.PUBLIC]: 'Public',
448 [VideoPlaylistPrivacy.UNLISTED]: 'Unlisted',
449 [VideoPlaylistPrivacy.PRIVATE]: 'Private'
450 }
451
452 const VIDEO_PLAYLIST_TYPES: { [ id in VideoPlaylistType ]: string } = {
453 [VideoPlaylistType.REGULAR]: 'Regular',
454 [VideoPlaylistType.WATCH_LATER]: 'Watch later'
455 }
456
457 const MIMETYPES = {
458 AUDIO: {
459 MIMETYPE_EXT: {
460 'audio/mpeg': '.mp3',
461 'audio/mp3': '.mp3',
462 'application/ogg': '.ogg',
463 'audio/ogg': '.ogg',
464 'audio/x-ms-wma': '.wma',
465 'audio/wav': '.wav',
466 'audio/x-wav': '.wav',
467 'audio/x-flac': '.flac',
468 'audio/flac': '.flac',
469 'audio/aac': '.aac',
470 'audio/m4a': '.m4a',
471 'audio/mp4': '.m4a',
472 'audio/x-m4a': '.m4a',
473 'audio/ac3': '.ac3'
474 },
475 EXT_MIMETYPE: null as { [ id: string ]: string }
476 },
477 VIDEO: {
478 MIMETYPE_EXT: null as { [ id: string ]: string | string[] },
479 MIMETYPES_REGEX: null as string,
480 EXT_MIMETYPE: null as { [ id: string ]: string }
481 },
482 IMAGE: {
483 MIMETYPE_EXT: {
484 'image/png': '.png',
485 'image/gif': '.gif',
486 'image/webp': '.webp',
487 'image/jpg': '.jpg',
488 'image/jpeg': '.jpg'
489 },
490 EXT_MIMETYPE: null as { [ id: string ]: string }
491 },
492 VIDEO_CAPTIONS: {
493 MIMETYPE_EXT: {
494 'text/vtt': '.vtt',
495 'application/x-subrip': '.srt',
496 'text/plain': '.srt'
497 }
498 },
499 TORRENT: {
500 MIMETYPE_EXT: {
501 'application/x-bittorrent': '.torrent'
502 }
503 }
504 }
505 MIMETYPES.AUDIO.EXT_MIMETYPE = invert(MIMETYPES.AUDIO.MIMETYPE_EXT)
506 MIMETYPES.IMAGE.EXT_MIMETYPE = invert(MIMETYPES.IMAGE.MIMETYPE_EXT)
507
508 const BINARY_CONTENT_TYPES = new Set([
509 'binary/octet-stream',
510 'application/octet-stream',
511 'application/x-binary'
512 ])
513
514 // ---------------------------------------------------------------------------
515
516 const OVERVIEWS = {
517 VIDEOS: {
518 SAMPLE_THRESHOLD: 6,
519 SAMPLES_COUNT: 20
520 }
521 }
522
523 // ---------------------------------------------------------------------------
524
525 const SERVER_ACTOR_NAME = 'peertube'
526
527 const ACTIVITY_PUB = {
528 POTENTIAL_ACCEPT_HEADERS: [
529 'application/activity+json',
530 'application/ld+json',
531 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
532 ],
533 ACCEPT_HEADER: 'application/activity+json, application/ld+json',
534 PUBLIC: 'https://www.w3.org/ns/activitystreams#Public',
535 COLLECTION_ITEMS_PER_PAGE: 10,
536 FETCH_PAGE_LIMIT: 2000,
537 URL_MIME_TYPES: {
538 VIDEO: [] as string[],
539 TORRENT: [ 'application/x-bittorrent' ],
540 MAGNET: [ 'application/x-bittorrent;x-scheme-handler/magnet' ]
541 },
542 MAX_RECURSION_COMMENTS: 100,
543 ACTOR_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2, // 2 days
544 VIDEO_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2, // 2 days
545 VIDEO_PLAYLIST_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2 // 2 days
546 }
547
548 const ACTIVITY_PUB_ACTOR_TYPES: { [ id: string ]: ActivityPubActorType } = {
549 GROUP: 'Group',
550 PERSON: 'Person',
551 APPLICATION: 'Application',
552 ORGANIZATION: 'Organization',
553 SERVICE: 'Service'
554 }
555
556 const HTTP_SIGNATURE = {
557 HEADER_NAME: 'signature',
558 ALGORITHM: 'rsa-sha256',
559 HEADERS_TO_SIGN: [ '(request-target)', 'host', 'date', 'digest' ],
560 REQUIRED_HEADERS: {
561 ALL: [ '(request-target)', 'host', 'date' ],
562 POST: [ '(request-target)', 'host', 'date', 'digest' ]
563 },
564 CLOCK_SKEW_SECONDS: 1800
565 }
566
567 // ---------------------------------------------------------------------------
568
569 let PRIVATE_RSA_KEY_SIZE = 2048
570
571 // Password encryption
572 const BCRYPT_SALT_SIZE = 10
573
574 const USER_PASSWORD_RESET_LIFETIME = 60000 * 60 // 60 minutes
575 const USER_PASSWORD_CREATE_LIFETIME = 60000 * 60 * 24 * 7 // 7 days
576
577 const USER_EMAIL_VERIFY_LIFETIME = 60000 * 60 // 60 minutes
578
579 const NSFW_POLICY_TYPES: { [ id: string ]: NSFWPolicyType } = {
580 DO_NOT_LIST: 'do_not_list',
581 BLUR: 'blur',
582 DISPLAY: 'display'
583 }
584
585 // ---------------------------------------------------------------------------
586
587 // Express static paths (router)
588 const STATIC_PATHS = {
589 THUMBNAILS: '/static/thumbnails/',
590 WEBSEED: '/static/webseed/',
591 REDUNDANCY: '/static/redundancy/',
592 STREAMING_PLAYLISTS: {
593 HLS: '/static/streaming-playlists/hls'
594 }
595 }
596 const STATIC_DOWNLOAD_PATHS = {
597 TORRENTS: '/download/torrents/',
598 VIDEOS: '/download/videos/',
599 HLS_VIDEOS: '/download/streaming-playlists/hls/videos/'
600 }
601 const LAZY_STATIC_PATHS = {
602 BANNERS: '/lazy-static/banners/',
603 AVATARS: '/lazy-static/avatars/',
604 PREVIEWS: '/lazy-static/previews/',
605 VIDEO_CAPTIONS: '/lazy-static/video-captions/',
606 TORRENTS: '/lazy-static/torrents/'
607 }
608
609 // Cache control
610 const STATIC_MAX_AGE = {
611 SERVER: '2h',
612 LAZY_SERVER: '2d',
613 CLIENT: '30d'
614 }
615
616 // Videos thumbnail size
617 const THUMBNAILS_SIZE = {
618 width: 280,
619 height: 157,
620 minWidth: 150
621 }
622 const PREVIEWS_SIZE = {
623 width: 850,
624 height: 480,
625 minWidth: 400
626 }
627 const ACTOR_IMAGES_SIZE = {
628 AVATARS: {
629 width: 120,
630 height: 120
631 },
632 BANNERS: {
633 width: 1920,
634 height: 317 // 6/1 ratio
635 }
636 }
637
638 const EMBED_SIZE = {
639 width: 560,
640 height: 315
641 }
642
643 // Sub folders of cache directory
644 const FILES_CACHE = {
645 PREVIEWS: {
646 DIRECTORY: join(CONFIG.STORAGE.CACHE_DIR, 'previews'),
647 MAX_AGE: 1000 * 3600 * 3 // 3 hours
648 },
649 VIDEO_CAPTIONS: {
650 DIRECTORY: join(CONFIG.STORAGE.CACHE_DIR, 'video-captions'),
651 MAX_AGE: 1000 * 3600 * 3 // 3 hours
652 },
653 TORRENTS: {
654 DIRECTORY: join(CONFIG.STORAGE.CACHE_DIR, 'torrents'),
655 MAX_AGE: 1000 * 3600 * 3 // 3 hours
656 }
657 }
658
659 const LRU_CACHE = {
660 USER_TOKENS: {
661 MAX_SIZE: 1000
662 },
663 ACTOR_IMAGE_STATIC: {
664 MAX_SIZE: 500
665 }
666 }
667
668 const RESUMABLE_UPLOAD_DIRECTORY = join(CONFIG.STORAGE.TMP_DIR, 'resumable-uploads')
669 const HLS_STREAMING_PLAYLIST_DIRECTORY = join(CONFIG.STORAGE.STREAMING_PLAYLISTS_DIR, 'hls')
670 const HLS_REDUNDANCY_DIRECTORY = join(CONFIG.STORAGE.REDUNDANCY_DIR, 'hls')
671
672 const RESUMABLE_UPLOAD_SESSION_LIFETIME = SCHEDULER_INTERVALS_MS.REMOVE_DANGLING_RESUMABLE_UPLOADS
673
674 const VIDEO_LIVE = {
675 EXTENSION: '.ts',
676 CLEANUP_DELAY: 1000 * 60 * 5, // 5 minutes
677 SEGMENT_TIME_SECONDS: 4, // 4 seconds
678 SEGMENTS_LIST_SIZE: 15, // 15 maximum segments in live playlist
679 REPLAY_DIRECTORY: 'replay',
680 EDGE_LIVE_DELAY_SEGMENTS_NOTIFICATION: 4,
681 MAX_SOCKET_WAITING_DATA: 1024 * 1000 * 100, // 100MB
682 RTMP: {
683 CHUNK_SIZE: 60000,
684 GOP_CACHE: true,
685 PING: 60,
686 PING_TIMEOUT: 30,
687 BASE_PATH: 'live'
688 }
689 }
690
691 const MEMOIZE_TTL = {
692 OVERVIEWS_SAMPLE: 1000 * 3600 * 4, // 4 hours
693 INFO_HASH_EXISTS: 1000 * 3600 * 12, // 12 hours
694 LIVE_ABLE_TO_UPLOAD: 1000 * 60, // 1 minute
695 LIVE_CHECK_SOCKET_HEALTH: 1000 * 60 // 1 minute
696 }
697
698 const MEMOIZE_LENGTH = {
699 INFO_HASH_EXISTS: 200
700 }
701
702 const QUEUE_CONCURRENCY = {
703 ACTOR_PROCESS_IMAGE: 3
704 }
705
706 const REDUNDANCY = {
707 VIDEOS: {
708 RANDOMIZED_FACTOR: 5
709 }
710 }
711
712 const ACCEPT_HEADERS = [ 'html', 'application/json' ].concat(ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS)
713
714 const ASSETS_PATH = {
715 DEFAULT_AUDIO_BACKGROUND: join(root(), 'dist', 'server', 'assets', 'default-audio-background.jpg'),
716 DEFAULT_LIVE_BACKGROUND: join(root(), 'dist', 'server', 'assets', 'default-live-background.jpg')
717 }
718
719 // ---------------------------------------------------------------------------
720
721 const CUSTOM_HTML_TAG_COMMENTS = {
722 TITLE: '<!-- title tag -->',
723 DESCRIPTION: '<!-- description tag -->',
724 CUSTOM_CSS: '<!-- custom css tag -->',
725 META_TAGS: '<!-- meta tags -->',
726 SERVER_CONFIG: '<!-- server config -->'
727 }
728
729 // ---------------------------------------------------------------------------
730
731 const FEEDS = {
732 COUNT: 20
733 }
734
735 const MAX_LOGS_OUTPUT_CHARACTERS = 10 * 1000 * 1000
736 const LOG_FILENAME = 'peertube.log'
737 const AUDIT_LOG_FILENAME = 'peertube-audit.log'
738
739 // ---------------------------------------------------------------------------
740
741 const TRACKER_RATE_LIMITS = {
742 INTERVAL: 60000 * 5, // 5 minutes
743 ANNOUNCES_PER_IP_PER_INFOHASH: 15, // maximum announces per torrent in the interval
744 ANNOUNCES_PER_IP: 30, // maximum announces for all our torrents in the interval
745 BLOCK_IP_LIFETIME: 60000 * 3 // 3 minutes
746 }
747
748 const P2P_MEDIA_LOADER_PEER_VERSION = 2
749
750 // ---------------------------------------------------------------------------
751
752 const PLUGIN_GLOBAL_CSS_FILE_NAME = 'plugins-global.css'
753 const PLUGIN_GLOBAL_CSS_PATH = join(CONFIG.STORAGE.TMP_DIR, PLUGIN_GLOBAL_CSS_FILE_NAME)
754
755 let PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME = 1000 * 60 * 5 // 5 minutes
756
757 const DEFAULT_THEME_NAME = 'default'
758 const DEFAULT_USER_THEME_NAME = 'instance-default'
759
760 // ---------------------------------------------------------------------------
761
762 const SEARCH_INDEX = {
763 ROUTES: {
764 VIDEOS: '/api/v1/search/videos',
765 VIDEO_CHANNELS: '/api/v1/search/video-channels'
766 }
767 }
768
769 // ---------------------------------------------------------------------------
770
771 // Special constants for a test instance
772 if (isTestInstance() === true) {
773 PRIVATE_RSA_KEY_SIZE = 1024
774
775 ACTOR_FOLLOW_SCORE.BASE = 20
776
777 REMOTE_SCHEME.HTTP = 'http'
778 REMOTE_SCHEME.WS = 'ws'
779
780 STATIC_MAX_AGE.SERVER = '0'
781
782 ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE = 2
783 ACTIVITY_PUB.ACTOR_REFRESH_INTERVAL = 10 * 1000 // 10 seconds
784 ACTIVITY_PUB.VIDEO_REFRESH_INTERVAL = 10 * 1000 // 10 seconds
785 ACTIVITY_PUB.VIDEO_PLAYLIST_REFRESH_INTERVAL = 10 * 1000 // 10 seconds
786
787 CONSTRAINTS_FIELDS.ACTORS.IMAGE.FILE_SIZE.max = 100 * 1024 // 100KB
788 CONSTRAINTS_FIELDS.VIDEOS.IMAGE.FILE_SIZE.max = 400 * 1024 // 400KB
789
790 SCHEDULER_INTERVALS_MS.ACTOR_FOLLOW_SCORES = 1000
791 SCHEDULER_INTERVALS_MS.REMOVE_OLD_JOBS = 10000
792 SCHEDULER_INTERVALS_MS.REMOVE_OLD_HISTORY = 5000
793 SCHEDULER_INTERVALS_MS.REMOVE_OLD_VIEWS = 5000
794 SCHEDULER_INTERVALS_MS.UPDATE_VIDEOS = 5000
795 SCHEDULER_INTERVALS_MS.AUTO_FOLLOW_INDEX_INSTANCES = 5000
796 SCHEDULER_INTERVALS_MS.UPDATE_INBOX_STATS = 5000
797 SCHEDULER_INTERVALS_MS.CHECK_PEERTUBE_VERSION = 2000
798 REPEAT_JOBS['videos-views-stats'] = { every: 5000 }
799 REPEAT_JOBS['activitypub-cleaner'] = { every: 5000 }
800
801 REDUNDANCY.VIDEOS.RANDOMIZED_FACTOR = 1
802
803 VIEW_LIFETIME.VIEWER = 1000 * 5 // 5 second
804 CONTACT_FORM_LIFETIME = 1000 // 1 second
805
806 JOB_ATTEMPTS['email'] = 1
807
808 FILES_CACHE.VIDEO_CAPTIONS.MAX_AGE = 3000
809 MEMOIZE_TTL.OVERVIEWS_SAMPLE = 3000
810 MEMOIZE_TTL.LIVE_ABLE_TO_UPLOAD = 3000
811 OVERVIEWS.VIDEOS.SAMPLE_THRESHOLD = 2
812
813 PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME = 5000
814
815 VIDEO_LIVE.CLEANUP_DELAY = 5000
816 VIDEO_LIVE.SEGMENT_TIME_SECONDS = 2
817 VIDEO_LIVE.EDGE_LIVE_DELAY_SEGMENTS_NOTIFICATION = 1
818 }
819
820 updateWebserverUrls()
821 updateWebserverConfig()
822
823 registerConfigChangedHandler(() => {
824 updateWebserverUrls()
825 updateWebserverConfig()
826 })
827
828 // ---------------------------------------------------------------------------
829
830 const FILES_CONTENT_HASH = {
831 MANIFEST: generateContentHash(),
832 FAVICON: generateContentHash(),
833 LOGO: generateContentHash()
834 }
835
836 // ---------------------------------------------------------------------------
837
838 export {
839 WEBSERVER,
840 API_VERSION,
841 VIDEO_LIVE,
842 PEERTUBE_VERSION,
843 LAZY_STATIC_PATHS,
844 SEARCH_INDEX,
845 RESUMABLE_UPLOAD_DIRECTORY,
846 RESUMABLE_UPLOAD_SESSION_LIFETIME,
847 HLS_REDUNDANCY_DIRECTORY,
848 P2P_MEDIA_LOADER_PEER_VERSION,
849 ACTOR_IMAGES_SIZE,
850 ACCEPT_HEADERS,
851 BCRYPT_SALT_SIZE,
852 TRACKER_RATE_LIMITS,
853 FILES_CACHE,
854 LOG_FILENAME,
855 CONSTRAINTS_FIELDS,
856 EMBED_SIZE,
857 REDUNDANCY,
858 JOB_CONCURRENCY,
859 JOB_ATTEMPTS,
860 AP_CLEANER_CONCURRENCY,
861 LAST_MIGRATION_VERSION,
862 OAUTH_LIFETIME,
863 CUSTOM_HTML_TAG_COMMENTS,
864 BROADCAST_CONCURRENCY,
865 AUDIT_LOG_FILENAME,
866 PAGINATION,
867 ACTOR_FOLLOW_SCORE,
868 PREVIEWS_SIZE,
869 REMOTE_SCHEME,
870 FOLLOW_STATES,
871 DEFAULT_USER_THEME_NAME,
872 SERVER_ACTOR_NAME,
873 PLUGIN_GLOBAL_CSS_FILE_NAME,
874 PLUGIN_GLOBAL_CSS_PATH,
875 PRIVATE_RSA_KEY_SIZE,
876 ROUTE_CACHE_LIFETIME,
877 SORTABLE_COLUMNS,
878 HLS_STREAMING_PLAYLIST_DIRECTORY,
879 FEEDS,
880 JOB_TTL,
881 DEFAULT_THEME_NAME,
882 NSFW_POLICY_TYPES,
883 STATIC_MAX_AGE,
884 STATIC_PATHS,
885 VIDEO_IMPORT_TIMEOUT,
886 VIDEO_PLAYLIST_TYPES,
887 MAX_LOGS_OUTPUT_CHARACTERS,
888 ACTIVITY_PUB,
889 ACTIVITY_PUB_ACTOR_TYPES,
890 THUMBNAILS_SIZE,
891 VIDEO_CATEGORIES,
892 MEMOIZE_LENGTH,
893 VIDEO_LANGUAGES,
894 VIDEO_PRIVACIES,
895 VIDEO_LICENCES,
896 VIDEO_STATES,
897 QUEUE_CONCURRENCY,
898 VIDEO_RATE_TYPES,
899 JOB_PRIORITY,
900 VIDEO_TRANSCODING_FPS,
901 FFMPEG_NICE,
902 ABUSE_STATES,
903 LRU_CACHE,
904 REQUEST_TIMEOUTS,
905 USER_PASSWORD_RESET_LIFETIME,
906 USER_PASSWORD_CREATE_LIFETIME,
907 MEMOIZE_TTL,
908 USER_EMAIL_VERIFY_LIFETIME,
909 OVERVIEWS,
910 SCHEDULER_INTERVALS_MS,
911 REPEAT_JOBS,
912 STATIC_DOWNLOAD_PATHS,
913 MIMETYPES,
914 CRAWL_REQUEST_CONCURRENCY,
915 DEFAULT_AUDIO_RESOLUTION,
916 BINARY_CONTENT_TYPES,
917 JOB_COMPLETED_LIFETIME,
918 HTTP_SIGNATURE,
919 VIDEO_IMPORT_STATES,
920 VIEW_LIFETIME,
921 CONTACT_FORM_LIFETIME,
922 VIDEO_PLAYLIST_PRIVACIES,
923 PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME,
924 ASSETS_PATH,
925 FILES_CONTENT_HASH,
926 loadLanguages,
927 buildLanguages,
928 generateContentHash
929 }
930
931 // ---------------------------------------------------------------------------
932
933 function buildVideoMimetypeExt () {
934 const data = {
935 // streamable formats that warrant cross-browser compatibility
936 'video/webm': '.webm',
937 // We'll add .ogg if additional extensions are enabled
938 // We could add .ogg here but since it could be an audio file,
939 // it would be confusing for users because PeerTube will refuse their file (based on the mimetype)
940 'video/ogg': [ '.ogv' ],
941 'video/mp4': '.mp4'
942 }
943
944 if (CONFIG.TRANSCODING.ENABLED) {
945 if (CONFIG.TRANSCODING.ALLOW_ADDITIONAL_EXTENSIONS) {
946 data['video/ogg'].push('.ogg')
947
948 Object.assign(data, {
949 'video/x-matroska': '.mkv',
950
951 // Developed by Apple
952 'video/quicktime': [ '.mov', '.qt', '.mqv' ], // often used as output format by editing software
953 'video/x-m4v': '.m4v',
954 'video/m4v': '.m4v',
955
956 // Developed by the Adobe Flash Platform
957 'video/x-flv': '.flv',
958 'video/x-f4v': '.f4v', // replacement for flv
959
960 // Developed by Microsoft
961 'video/x-ms-wmv': '.wmv',
962 'video/x-msvideo': '.avi',
963 'video/avi': '.avi',
964
965 // Developed by 3GPP
966 // common video formats for cell phones
967 'video/3gpp': [ '.3gp', '.3gpp' ],
968 'video/3gpp2': [ '.3g2', '.3gpp2' ],
969
970 // Developed by FFmpeg/Mplayer
971 'application/x-nut': '.nut',
972
973 // The standard video format used by many Sony and Panasonic HD camcorders.
974 // It is also used for storing high definition video on Blu-ray discs.
975 'video/mp2t': '.mts',
976 'video/m2ts': '.m2ts',
977
978 // Old formats reliant on MPEG-1/MPEG-2
979 'video/mpv': '.mpv',
980 'video/mpeg2': '.m2v',
981 'video/mpeg': [ '.m1v', '.mpg', '.mpe', '.mpeg', '.vob' ],
982 'video/dvd': '.vob',
983
984 // Could be anything
985 'application/octet-stream': null,
986 'application/mxf': '.mxf' // often used as exchange format by editing software
987 })
988 }
989
990 if (CONFIG.TRANSCODING.ALLOW_AUDIO_FILES) {
991 Object.assign(data, MIMETYPES.AUDIO.MIMETYPE_EXT)
992 }
993 }
994
995 return data
996 }
997
998 function updateWebserverUrls () {
999 WEBSERVER.URL = sanitizeUrl(CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT)
1000 WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT, REMOTE_SCHEME.HTTP)
1001 WEBSERVER.WS = CONFIG.WEBSERVER.WS
1002
1003 WEBSERVER.SCHEME = CONFIG.WEBSERVER.SCHEME
1004 WEBSERVER.HOSTNAME = CONFIG.WEBSERVER.HOSTNAME
1005 WEBSERVER.PORT = CONFIG.WEBSERVER.PORT
1006
1007 WEBSERVER.RTMP_URL = 'rtmp://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.LIVE.RTMP.PORT + '/' + VIDEO_LIVE.RTMP.BASE_PATH
1008 WEBSERVER.RTMPS_URL = 'rtmps://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.LIVE.RTMPS.PORT + '/' + VIDEO_LIVE.RTMP.BASE_PATH
1009 }
1010
1011 function updateWebserverConfig () {
1012 MIMETYPES.VIDEO.MIMETYPE_EXT = buildVideoMimetypeExt()
1013 MIMETYPES.VIDEO.MIMETYPES_REGEX = buildMimetypesRegex(MIMETYPES.VIDEO.MIMETYPE_EXT)
1014
1015 ACTIVITY_PUB.URL_MIME_TYPES.VIDEO = Object.keys(MIMETYPES.VIDEO.MIMETYPE_EXT)
1016
1017 MIMETYPES.VIDEO.EXT_MIMETYPE = buildVideoExtMimetype(MIMETYPES.VIDEO.MIMETYPE_EXT)
1018
1019 CONSTRAINTS_FIELDS.VIDEOS.EXTNAME = Object.keys(MIMETYPES.VIDEO.EXT_MIMETYPE)
1020 }
1021
1022 function buildVideoExtMimetype (obj: { [ id: string ]: string | string[] }) {
1023 const result: { [id: string]: string } = {}
1024
1025 for (const mimetype of Object.keys(obj)) {
1026 const value = obj[mimetype]
1027 if (!value) continue
1028
1029 const extensions = Array.isArray(value) ? value : [ value ]
1030
1031 for (const extension of extensions) {
1032 result[extension] = mimetype
1033 }
1034 }
1035
1036 return result
1037 }
1038
1039 function buildMimetypesRegex (obj: { [id: string]: string | string[] }) {
1040 return Object.keys(obj)
1041 .map(m => `(${m})`)
1042 .join('|')
1043 }
1044
1045 function loadLanguages () {
1046 Object.assign(VIDEO_LANGUAGES, buildLanguages())
1047 }
1048
1049 function buildLanguages () {
1050 const iso639 = require('iso-639-3')
1051
1052 const languages: { [id: string]: string } = {}
1053
1054 const additionalLanguages = {
1055 sgn: true, // Sign languages (macro language)
1056 ase: true, // American sign language
1057 sdl: true, // Arabian sign language
1058 bfi: true, // British sign language
1059 bzs: true, // Brazilian sign language
1060 csl: true, // Chinese sign language
1061 cse: true, // Czech sign language
1062 dsl: true, // Danish sign language
1063 fsl: true, // French sign language
1064 gsg: true, // German sign language
1065 pks: true, // Pakistan sign language
1066 jsl: true, // Japanese sign language
1067 sfs: true, // South African sign language
1068 swl: true, // Swedish sign language
1069 rsl: true, // Russian sign language
1070
1071 kab: true, // Kabyle
1072
1073 lat: true, // Latin
1074
1075 epo: true, // Esperanto
1076 tlh: true, // Klingon
1077 jbo: true, // Lojban
1078 avk: true, // Kotava
1079
1080 zxx: true // No linguistic content (ISO-639-2)
1081 }
1082
1083 // Only add ISO639-1 languages and some sign languages (ISO639-3)
1084 iso639
1085 .filter(l => {
1086 return (l.iso6391 !== undefined && l.type === 'living') ||
1087 additionalLanguages[l.iso6393] === true
1088 })
1089 .forEach(l => { languages[l.iso6391 || l.iso6393] = l.name })
1090
1091 // Override Occitan label
1092 languages['oc'] = 'Occitan'
1093 languages['el'] = 'Greek'
1094
1095 return languages
1096 }
1097
1098 function generateContentHash () {
1099 return randomBytes(20).toString('hex')
1100 }