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