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/miscs/miscs'
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'
25 // ---------------------------------------------------------------------------
27 const LAST_MIGRATION_VERSION = 650
29 // ---------------------------------------------------------------------------
31 const API_VERSION = 'v1'
32 const PEERTUBE_VERSION: string = require(join(root(), 'package.json')).version
58 // Sortable columns per schema
59 const SORTABLE_COLUMNS = {
60 USERS: [ 'id', 'username', 'videoQuotaUsed', 'createdAt', 'lastLoginDate', 'role' ],
61 USER_SUBSCRIPTIONS: [ 'id', 'createdAt' ],
62 ACCOUNTS: [ 'createdAt' ],
63 JOBS: [ 'createdAt' ],
64 VIDEO_CHANNELS: [ 'id', 'name', 'updatedAt', 'createdAt' ],
65 VIDEO_IMPORTS: [ 'createdAt' ],
67 VIDEO_COMMENT_THREADS: [ 'createdAt', 'totalReplies' ],
68 VIDEO_COMMENTS: [ 'createdAt' ],
70 VIDEO_RATES: [ 'createdAt' ],
71 BLACKLISTS: [ 'id', 'name', 'duration', 'views', 'likes', 'dislikes', 'uuid', 'createdAt' ],
72 FOLLOWERS: [ 'createdAt', 'state', 'score' ],
73 FOLLOWING: [ 'createdAt', 'redundancyAllowed', 'state' ],
75 VIDEOS: [ 'name', 'duration', 'createdAt', 'publishedAt', 'originallyPublishedAt', 'views', 'likes', 'trending', 'hot', 'best' ],
77 // Don't forget to update peertube-search-index with the same values
78 VIDEOS_SEARCH: [ 'name', 'duration', 'createdAt', 'publishedAt', 'originallyPublishedAt', 'views', 'likes', 'match' ],
79 VIDEO_CHANNELS_SEARCH: [ 'match', 'displayName', 'createdAt' ],
81 ABUSES: [ 'id', 'createdAt', 'state' ],
83 ACCOUNTS_BLOCKLIST: [ 'createdAt' ],
84 SERVERS_BLOCKLIST: [ 'createdAt' ],
86 USER_NOTIFICATIONS: [ 'createdAt', 'read' ],
88 VIDEO_PLAYLISTS: [ 'name', 'displayName', 'createdAt', 'updatedAt' ],
90 PLUGINS: [ 'name', 'createdAt', 'updatedAt' ],
92 AVAILABLE_PLUGINS: [ 'npmName', 'popularity' ],
94 VIDEO_REDUNDANCIES: [ 'name' ]
97 const OAUTH_LIFETIME = {
98 ACCESS_TOKEN: 3600 * 24, // 1 day, for upload
99 REFRESH_TOKEN: 1209600 // 2 weeks
102 const ROUTE_CACHE_LIFETIME = {
106 SECURITYTXT: '2 hours',
107 NODEINFO: '10 minutes',
108 DNT_POLICY: '1 week',
110 VIDEOS: '1 second' // 1 second, cache concurrent requests after a broadcast for example
115 // ---------------------------------------------------------------------------
117 // Number of points we add/remove after a successful/bad request
118 const ACTOR_FOLLOW_SCORE = {
125 const FOLLOW_STATES: { [ id: string ]: FollowState } = {
130 const REMOTE_SCHEME = {
135 const JOB_ATTEMPTS: { [id in JobType]: number } = {
136 'activitypub-http-broadcast': 5,
137 'activitypub-http-unicast': 5,
138 'activitypub-http-fetcher': 5,
139 'activitypub-follow': 5,
140 'activitypub-cleaner': 1,
141 'video-file-import': 1,
142 'video-transcoding': 1,
147 'activitypub-refresher': 1,
148 'video-redundancy': 1,
149 'video-live-ending': 1
151 // Excluded keys are jobs that can be configured by admins
152 const JOB_CONCURRENCY: { [id in Exclude<JobType, 'video-transcoding' | 'video-import'>]: number } = {
153 'activitypub-http-broadcast': 1,
154 'activitypub-http-unicast': 5,
155 'activitypub-http-fetcher': 1,
156 'activitypub-cleaner': 1,
157 'activitypub-follow': 1,
158 'video-file-import': 1,
162 'activitypub-refresher': 1,
163 'video-redundancy': 1,
164 'video-live-ending': 10
166 const JOB_TTL: { [id in JobType]: number } = {
167 'activitypub-http-broadcast': 60000 * 10, // 10 minutes
168 'activitypub-http-unicast': 60000 * 10, // 10 minutes
169 'activitypub-http-fetcher': 1000 * 3600 * 10, // 10 hours
170 'activitypub-follow': 60000 * 10, // 10 minutes
171 'activitypub-cleaner': 1000 * 3600, // 1 hour
172 'video-file-import': 1000 * 3600, // 1 hour
173 'video-transcoding': 1000 * 3600 * 48, // 2 days, transcoding could be long
174 'video-import': 1000 * 3600 * 2, // 2 hours
175 'email': 60000 * 10, // 10 minutes
176 'actor-keys': 60000 * 20, // 20 minutes
177 'videos-views': undefined, // Unlimited
178 'activitypub-refresher': 60000 * 10, // 10 minutes
179 'video-redundancy': 1000 * 3600 * 3, // 3 hours
180 'video-live-ending': 1000 * 60 * 10 // 10 minutes
182 const REPEAT_JOBS: { [ id: string ]: EveryRepeatOptions | CronRepeatOptions } = {
184 cron: randomInt(1, 20) + ' * * * *' // Between 1-20 minutes past the hour
186 'activitypub-cleaner': {
187 cron: '30 5 * * ' + randomInt(0, 7) // 1 time per week (random day) at 5:30 AM
190 const JOB_PRIORITY = {
194 const BROADCAST_CONCURRENCY = 30 // How many requests in parallel we do in activitypub-http-broadcast job
195 const AP_CLEANER_CONCURRENCY = 10 // How many requests in parallel we do in activitypub-cleaner job
196 const CRAWL_REQUEST_CONCURRENCY = 1 // How many requests in parallel to fetch remote data (likes, shares...)
197 const REQUEST_TIMEOUT = 7000 // 7 seconds
198 const JOB_COMPLETED_LIFETIME = 60000 * 60 * 24 * 2 // 2 days
199 const VIDEO_IMPORT_TIMEOUT = 1000 * 3600 // 1 hour
201 const SCHEDULER_INTERVALS_MS = {
202 actorFollowScores: 60000 * 60, // 1 hour
203 removeOldJobs: 60000 * 60, // 1 hour
204 updateVideos: 60000, // 1 minute
205 youtubeDLUpdate: 60000 * 60 * 24, // 1 day
206 checkPlugins: CONFIG.PLUGINS.INDEX.CHECK_LATEST_VERSIONS_INTERVAL,
207 checkPeerTubeVersion: 60000 * 60 * 24, // 1 day
208 autoFollowIndexInstances: 60000 * 60 * 24, // 1 day
209 removeOldViews: 60000 * 60 * 24, // 1 day
210 removeOldHistory: 60000 * 60 * 24, // 1 day
211 updateInboxStats: 1000 * 60, // 1 minute
212 removeDanglingResumableUploads: 60000 * 60 * 16 // 16 hours
215 // ---------------------------------------------------------------------------
217 const CONSTRAINTS_FIELDS = {
219 NAME: { min: 1, max: 120 }, // Length
220 DESCRIPTION: { min: 3, max: 1000 }, // Length
221 USERNAME: { min: 1, max: 50 }, // Length
222 PASSWORD: { min: 6, max: 255 }, // Length
223 VIDEO_QUOTA: { min: -1 },
224 VIDEO_QUOTA_DAILY: { min: -1 },
225 VIDEO_LANGUAGES: { max: 500 }, // Array length
226 BLOCKED_REASON: { min: 3, max: 250 } // Length
229 REASON: { min: 2, max: 3000 }, // Length
230 MODERATION_COMMENT: { min: 2, max: 3000 } // Length
233 MESSAGE: { min: 2, max: 3000 } // Length
236 REASON: { min: 2, max: 300 } // Length
239 NAME: { min: 1, max: 120 }, // Length
240 DESCRIPTION: { min: 3, max: 1000 }, // Length
241 SUPPORT: { min: 3, max: 1000 }, // Length
242 URL: { min: 3, max: 2000 } // Length
246 EXTNAME: [ '.vtt', '.srt' ],
248 max: 2 * 1024 * 1024 // 2MB
253 URL: { min: 3, max: 2000 }, // Length
254 TORRENT_NAME: { min: 3, max: 255 }, // Length
256 EXTNAME: [ '.torrent' ],
258 max: 1024 * 200 // 200 KB
263 URL: { min: 3, max: 2000 } // Length
266 URL: { min: 3, max: 2000 } // Length
269 NAME: { min: 3, max: 120 }, // Length
270 LANGUAGE: { min: 1, max: 10 }, // Length
271 TRUNCATED_DESCRIPTION: { min: 3, max: 250 }, // Length
272 DESCRIPTION: { min: 3, max: 10000 }, // Length
273 SUPPORT: { min: 3, max: 1000 }, // Length
275 EXTNAME: [ '.png', '.jpg', '.jpeg', '.webp' ],
277 max: 2 * 1024 * 1024 // 2MB
280 EXTNAME: [] as string[],
281 INFO_HASH: { min: 40, max: 40 }, // Length, info hash is 20 bytes length but we represent it in hexadecimal so 20 * 2
282 DURATION: { min: 0 }, // Number
283 TAGS: { min: 0, max: 5 }, // Number of total tags
284 TAG: { min: 2, max: 30 }, // Length
287 DISLIKES: { min: 0 },
288 FILE_SIZE: { min: -1 },
289 PARTIAL_UPLOAD_SIZE: { max: 50 * 1024 * 1024 * 1024 }, // 50GB
290 URL: { min: 3, max: 2000 } // Length
293 NAME: { min: 1, max: 120 }, // Length
294 DESCRIPTION: { min: 3, max: 1000 }, // Length
295 URL: { min: 3, max: 2000 }, // Length
297 EXTNAME: [ '.jpg', '.jpeg' ],
299 max: 2 * 1024 * 1024 // 2MB
304 PUBLIC_KEY: { min: 10, max: 5000 }, // Length
305 PRIVATE_KEY: { min: 10, max: 5000 }, // Length
306 URL: { min: 3, max: 2000 }, // Length
308 EXTNAME: [ '.png', '.jpeg', '.jpg', '.gif', '.webp' ],
310 max: 2 * 1024 * 1024 // 2MB
318 TEXT: { min: 1, max: 10000 }, // Length
319 URL: { min: 3, max: 2000 } // Length
322 URL: { min: 3, max: 2000 } // Length
325 FROM_NAME: { min: 1, max: 120 }, // Length
326 BODY: { min: 3, max: 5000 } // Length
329 NAME: { min: 1, max: 214 }, // Length
330 DESCRIPTION: { min: 1, max: 20000 } // Length
333 URL: { min: 5, max: 2000 } // Length
337 const VIEW_LIFETIME = {
338 VIDEO: 60000 * 60, // 1 hour
339 LIVE: 60000 * 5 // 5 minutes
342 let CONTACT_FORM_LIFETIME = 60000 * 60 // 1 hour
344 const VIDEO_TRANSCODING_FPS: VideoTranscodingFPS = {
346 STANDARD: [ 24, 25, 30 ],
347 HD_STANDARD: [ 50, 60 ],
350 KEEP_ORIGIN_FPS_RESOLUTION_MIN: 720 // We keep the original FPS on high resolutions (720 minimum)
353 const DEFAULT_AUDIO_RESOLUTION = VideoResolution.H_480P
355 const VIDEO_RATE_TYPES: { [ id: string ]: VideoRateType } = {
360 const FFMPEG_NICE: { [ id: string ]: number } = {
361 // parent process defaults to niceness = 0
362 // reminder: lower = higher priority, max value is 19, lowest is -20
363 LIVE: 5, // prioritize over VOD and THUMBNAIL
368 const VIDEO_CATEGORIES = {
379 11: 'News & Politics',
383 15: 'Science & Technology',
389 // See https://creativecommons.org/licenses/?lang=en
390 const VIDEO_LICENCES = {
392 2: 'Attribution - Share Alike',
393 3: 'Attribution - No Derivatives',
394 4: 'Attribution - Non Commercial',
395 5: 'Attribution - Non Commercial - Share Alike',
396 6: 'Attribution - Non Commercial - No Derivatives',
397 7: 'Public Domain Dedication'
400 const VIDEO_LANGUAGES: { [id: string]: string } = {}
402 const VIDEO_PRIVACIES: { [ id in VideoPrivacy ]: string } = {
403 [VideoPrivacy.PUBLIC]: 'Public',
404 [VideoPrivacy.UNLISTED]: 'Unlisted',
405 [VideoPrivacy.PRIVATE]: 'Private',
406 [VideoPrivacy.INTERNAL]: 'Internal'
409 const VIDEO_STATES: { [ id in VideoState ]: string } = {
410 [VideoState.PUBLISHED]: 'Published',
411 [VideoState.TO_TRANSCODE]: 'To transcode',
412 [VideoState.TO_IMPORT]: 'To import',
413 [VideoState.WAITING_FOR_LIVE]: 'Waiting for livestream',
414 [VideoState.LIVE_ENDED]: 'Livestream ended'
417 const VIDEO_IMPORT_STATES: { [ id in VideoImportState ]: string } = {
418 [VideoImportState.FAILED]: 'Failed',
419 [VideoImportState.PENDING]: 'Pending',
420 [VideoImportState.SUCCESS]: 'Success',
421 [VideoImportState.REJECTED]: 'Rejected'
424 const ABUSE_STATES: { [ id in AbuseState ]: string } = {
425 [AbuseState.PENDING]: 'Pending',
426 [AbuseState.REJECTED]: 'Rejected',
427 [AbuseState.ACCEPTED]: 'Accepted'
430 const VIDEO_PLAYLIST_PRIVACIES: { [ id in VideoPlaylistPrivacy ]: string } = {
431 [VideoPlaylistPrivacy.PUBLIC]: 'Public',
432 [VideoPlaylistPrivacy.UNLISTED]: 'Unlisted',
433 [VideoPlaylistPrivacy.PRIVATE]: 'Private'
436 const VIDEO_PLAYLIST_TYPES: { [ id in VideoPlaylistType ]: string } = {
437 [VideoPlaylistType.REGULAR]: 'Regular',
438 [VideoPlaylistType.WATCH_LATER]: 'Watch later'
444 'audio/mpeg': '.mp3',
446 'application/ogg': '.ogg',
448 'audio/x-ms-wma': '.wma',
450 'audio/x-flac': '.flac',
451 'audio/flac': '.flac',
452 '‎audio/aac': '.aac',
455 'audio/x-m4a': '.m4a',
458 EXT_MIMETYPE: null as { [ id: string ]: string }
461 MIMETYPE_EXT: null as { [ id: string ]: string | string[] },
462 MIMETYPES_REGEX: null as string,
463 EXT_MIMETYPE: null as { [ id: string ]: string }
469 'image/webp': '.webp',
473 EXT_MIMETYPE: null as { [ id: string ]: string }
478 'application/x-subrip': '.srt',
484 'application/x-bittorrent': '.torrent'
488 MIMETYPES.AUDIO.EXT_MIMETYPE = invert(MIMETYPES.AUDIO.MIMETYPE_EXT)
489 MIMETYPES.IMAGE.EXT_MIMETYPE = invert(MIMETYPES.IMAGE.MIMETYPE_EXT)
491 // ---------------------------------------------------------------------------
500 const VIDEO_CHANNELS = {
504 // ---------------------------------------------------------------------------
506 const SERVER_ACTOR_NAME = 'peertube'
508 const ACTIVITY_PUB = {
509 POTENTIAL_ACCEPT_HEADERS: [
510 'application/activity+json',
511 'application/ld+json',
512 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
514 ACCEPT_HEADER: 'application/activity+json, application/ld+json',
515 PUBLIC: 'https://www.w3.org/ns/activitystreams#Public',
516 COLLECTION_ITEMS_PER_PAGE: 10,
517 FETCH_PAGE_LIMIT: 2000,
519 VIDEO: [] as string[],
520 TORRENT: [ 'application/x-bittorrent' ],
521 MAGNET: [ 'application/x-bittorrent;x-scheme-handler/magnet' ]
523 MAX_RECURSION_COMMENTS: 100,
524 ACTOR_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2, // 2 days
525 VIDEO_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2, // 2 days
526 VIDEO_PLAYLIST_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2 // 2 days
529 const ACTIVITY_PUB_ACTOR_TYPES: { [ id: string ]: ActivityPubActorType } = {
532 APPLICATION: 'Application',
533 ORGANIZATION: 'Organization',
537 const HTTP_SIGNATURE = {
538 HEADER_NAME: 'signature',
539 ALGORITHM: 'rsa-sha256',
540 HEADERS_TO_SIGN: [ '(request-target)', 'host', 'date', 'digest' ],
542 ALL: [ '(request-target)', 'host', 'date' ],
543 POST: [ '(request-target)', 'host', 'date', 'digest' ]
545 CLOCK_SKEW_SECONDS: 1800
548 // ---------------------------------------------------------------------------
550 let PRIVATE_RSA_KEY_SIZE = 2048
552 // Password encryption
553 const BCRYPT_SALT_SIZE = 10
555 const USER_PASSWORD_RESET_LIFETIME = 60000 * 60 // 60 minutes
556 const USER_PASSWORD_CREATE_LIFETIME = 60000 * 60 * 24 * 7 // 7 days
558 const USER_EMAIL_VERIFY_LIFETIME = 60000 * 60 // 60 minutes
560 const NSFW_POLICY_TYPES: { [ id: string ]: NSFWPolicyType } = {
561 DO_NOT_LIST: 'do_not_list',
566 // ---------------------------------------------------------------------------
568 // Express static paths (router)
569 const STATIC_PATHS = {
570 THUMBNAILS: '/static/thumbnails/',
571 TORRENTS: '/static/torrents/',
572 WEBSEED: '/static/webseed/',
573 REDUNDANCY: '/static/redundancy/',
574 STREAMING_PLAYLISTS: {
575 HLS: '/static/streaming-playlists/hls'
578 const STATIC_DOWNLOAD_PATHS = {
579 TORRENTS: '/download/torrents/',
580 VIDEOS: '/download/videos/',
581 HLS_VIDEOS: '/download/streaming-playlists/hls/videos/'
583 const LAZY_STATIC_PATHS = {
584 BANNERS: '/lazy-static/banners/',
585 AVATARS: '/lazy-static/avatars/',
586 PREVIEWS: '/lazy-static/previews/',
587 VIDEO_CAPTIONS: '/lazy-static/video-captions/',
588 TORRENTS: '/lazy-static/torrents/'
592 const STATIC_MAX_AGE = {
598 // Videos thumbnail size
599 const THUMBNAILS_SIZE = {
604 const PREVIEWS_SIZE = {
609 const ACTOR_IMAGES_SIZE = {
616 height: 317 // 6/1 ratio
625 // Sub folders of cache directory
626 const FILES_CACHE = {
628 DIRECTORY: join(CONFIG.STORAGE.CACHE_DIR, 'previews'),
629 MAX_AGE: 1000 * 3600 * 3 // 3 hours
632 DIRECTORY: join(CONFIG.STORAGE.CACHE_DIR, 'video-captions'),
633 MAX_AGE: 1000 * 3600 * 3 // 3 hours
636 DIRECTORY: join(CONFIG.STORAGE.CACHE_DIR, 'torrents'),
637 MAX_AGE: 1000 * 3600 * 3 // 3 hours
645 ACTOR_IMAGE_STATIC: {
650 const RESUMABLE_UPLOAD_DIRECTORY = join(CONFIG.STORAGE.TMP_DIR, 'resumable-uploads')
651 const HLS_STREAMING_PLAYLIST_DIRECTORY = join(CONFIG.STORAGE.STREAMING_PLAYLISTS_DIR, 'hls')
652 const HLS_REDUNDANCY_DIRECTORY = join(CONFIG.STORAGE.REDUNDANCY_DIR, 'hls')
656 CLEANUP_DELAY: 1000 * 60 * 5, // 5 minutes
657 SEGMENT_TIME_SECONDS: 4, // 4 seconds
658 SEGMENTS_LIST_SIZE: 15, // 15 maximum segments in live playlist
659 REPLAY_DIRECTORY: 'replay',
660 EDGE_LIVE_DELAY_SEGMENTS_NOTIFICATION: 4,
661 MAX_SOCKET_WAITING_DATA: 1024 * 1000 * 100, // 100MB
671 const MEMOIZE_TTL = {
672 OVERVIEWS_SAMPLE: 1000 * 3600 * 4, // 4 hours
673 INFO_HASH_EXISTS: 1000 * 3600 * 12, // 12 hours
674 LIVE_ABLE_TO_UPLOAD: 1000 * 60, // 1 minute
675 LIVE_CHECK_SOCKET_HEALTH: 1000 * 60 // 1 minute
678 const MEMOIZE_LENGTH = {
679 INFO_HASH_EXISTS: 200
682 const QUEUE_CONCURRENCY = {
683 ACTOR_PROCESS_IMAGE: 3
692 const ACCEPT_HEADERS = [ 'html', 'application/json' ].concat(ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS)
694 const ASSETS_PATH = {
695 DEFAULT_AUDIO_BACKGROUND: join(root(), 'dist', 'server', 'assets', 'default-audio-background.jpg'),
696 DEFAULT_LIVE_BACKGROUND: join(root(), 'dist', 'server', 'assets', 'default-live-background.jpg')
699 // ---------------------------------------------------------------------------
701 const CUSTOM_HTML_TAG_COMMENTS = {
702 TITLE: '<!-- title tag -->',
703 DESCRIPTION: '<!-- description tag -->',
704 CUSTOM_CSS: '<!-- custom css tag -->',
705 META_TAGS: '<!-- meta tags -->',
706 SERVER_CONFIG: '<!-- server config -->'
709 // ---------------------------------------------------------------------------
715 const MAX_LOGS_OUTPUT_CHARACTERS = 10 * 1000 * 1000
716 const LOG_FILENAME = 'peertube.log'
717 const AUDIT_LOG_FILENAME = 'peertube-audit.log'
719 // ---------------------------------------------------------------------------
721 const TRACKER_RATE_LIMITS = {
722 INTERVAL: 60000 * 5, // 5 minutes
723 ANNOUNCES_PER_IP_PER_INFOHASH: 15, // maximum announces per torrent in the interval
724 ANNOUNCES_PER_IP: 30, // maximum announces for all our torrents in the interval
725 BLOCK_IP_LIFETIME: 60000 * 3 // 3 minutes
728 const P2P_MEDIA_LOADER_PEER_VERSION = 2
730 // ---------------------------------------------------------------------------
732 const PLUGIN_GLOBAL_CSS_FILE_NAME = 'plugins-global.css'
733 const PLUGIN_GLOBAL_CSS_PATH = join(CONFIG.STORAGE.TMP_DIR, PLUGIN_GLOBAL_CSS_FILE_NAME)
735 let PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME = 1000 * 60 * 5 // 5 minutes
737 const DEFAULT_THEME_NAME = 'default'
738 const DEFAULT_USER_THEME_NAME = 'instance-default'
740 // ---------------------------------------------------------------------------
742 const SEARCH_INDEX = {
744 VIDEOS: '/api/v1/search/videos',
745 VIDEO_CHANNELS: '/api/v1/search/video-channels'
749 // ---------------------------------------------------------------------------
751 // Special constants for a test instance
752 if (isTestInstance() === true) {
753 PRIVATE_RSA_KEY_SIZE = 1024
755 ACTOR_FOLLOW_SCORE.BASE = 20
757 REMOTE_SCHEME.HTTP = 'http'
758 REMOTE_SCHEME.WS = 'ws'
760 STATIC_MAX_AGE.SERVER = '0'
762 ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE = 2
763 ACTIVITY_PUB.ACTOR_REFRESH_INTERVAL = 10 * 1000 // 10 seconds
764 ACTIVITY_PUB.VIDEO_REFRESH_INTERVAL = 10 * 1000 // 10 seconds
765 ACTIVITY_PUB.VIDEO_PLAYLIST_REFRESH_INTERVAL = 10 * 1000 // 10 seconds
767 CONSTRAINTS_FIELDS.ACTORS.IMAGE.FILE_SIZE.max = 100 * 1024 // 100KB
768 CONSTRAINTS_FIELDS.VIDEOS.IMAGE.FILE_SIZE.max = 400 * 1024 // 400KB
770 SCHEDULER_INTERVALS_MS.actorFollowScores = 1000
771 SCHEDULER_INTERVALS_MS.removeOldJobs = 10000
772 SCHEDULER_INTERVALS_MS.removeOldHistory = 5000
773 SCHEDULER_INTERVALS_MS.removeOldViews = 5000
774 SCHEDULER_INTERVALS_MS.updateVideos = 5000
775 SCHEDULER_INTERVALS_MS.autoFollowIndexInstances = 5000
776 SCHEDULER_INTERVALS_MS.updateInboxStats = 5000
777 SCHEDULER_INTERVALS_MS.checkPeerTubeVersion = 2000
778 REPEAT_JOBS['videos-views'] = { every: 5000 }
779 REPEAT_JOBS['activitypub-cleaner'] = { every: 5000 }
781 REDUNDANCY.VIDEOS.RANDOMIZED_FACTOR = 1
783 VIEW_LIFETIME.VIDEO = 1000 // 1 second
784 VIEW_LIFETIME.LIVE = 1000 * 5 // 5 second
785 CONTACT_FORM_LIFETIME = 1000 // 1 second
787 JOB_ATTEMPTS['email'] = 1
789 FILES_CACHE.VIDEO_CAPTIONS.MAX_AGE = 3000
790 MEMOIZE_TTL.OVERVIEWS_SAMPLE = 3000
791 MEMOIZE_TTL.LIVE_ABLE_TO_UPLOAD = 3000
792 OVERVIEWS.VIDEOS.SAMPLE_THRESHOLD = 2
794 PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME = 5000
796 VIDEO_LIVE.CLEANUP_DELAY = 5000
797 VIDEO_LIVE.SEGMENT_TIME_SECONDS = 2
798 VIDEO_LIVE.EDGE_LIVE_DELAY_SEGMENTS_NOTIFICATION = 1
801 updateWebserverUrls()
802 updateWebserverConfig()
804 registerConfigChangedHandler(() => {
805 updateWebserverUrls()
806 updateWebserverConfig()
809 // ---------------------------------------------------------------------------
811 const FILES_CONTENT_HASH = {
812 MANIFEST: generateContentHash(),
813 FAVICON: generateContentHash(),
814 LOGO: generateContentHash()
817 // ---------------------------------------------------------------------------
826 RESUMABLE_UPLOAD_DIRECTORY,
827 HLS_REDUNDANCY_DIRECTORY,
828 P2P_MEDIA_LOADER_PEER_VERSION,
840 AP_CLEANER_CONCURRENCY,
841 LAST_MIGRATION_VERSION,
843 CUSTOM_HTML_TAG_COMMENTS,
844 BROADCAST_CONCURRENCY,
851 DEFAULT_USER_THEME_NAME,
853 PLUGIN_GLOBAL_CSS_FILE_NAME,
854 PLUGIN_GLOBAL_CSS_PATH,
855 PRIVATE_RSA_KEY_SIZE,
856 ROUTE_CACHE_LIFETIME,
858 HLS_STREAMING_PLAYLIST_DIRECTORY,
865 VIDEO_IMPORT_TIMEOUT,
866 VIDEO_PLAYLIST_TYPES,
867 MAX_LOGS_OUTPUT_CHARACTERS,
869 ACTIVITY_PUB_ACTOR_TYPES,
880 VIDEO_TRANSCODING_FPS,
886 USER_PASSWORD_RESET_LIFETIME,
887 USER_PASSWORD_CREATE_LIFETIME,
889 USER_EMAIL_VERIFY_LIFETIME,
891 SCHEDULER_INTERVALS_MS,
893 STATIC_DOWNLOAD_PATHS,
895 CRAWL_REQUEST_CONCURRENCY,
896 DEFAULT_AUDIO_RESOLUTION,
897 JOB_COMPLETED_LIFETIME,
901 CONTACT_FORM_LIFETIME,
902 VIDEO_PLAYLIST_PRIVACIES,
903 PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME,
911 // ---------------------------------------------------------------------------
913 function buildVideoMimetypeExt () {
915 // streamable formats that warrant cross-browser compatibility
916 'video/webm': '.webm',
917 // We'll add .ogg if additional extensions are enabled
918 // We could add .ogg here but since it could be an audio file,
919 // it would be confusing for users because PeerTube will refuse their file (based on the mimetype)
920 'video/ogg': [ '.ogv' ],
924 if (CONFIG.TRANSCODING.ENABLED) {
925 if (CONFIG.TRANSCODING.ALLOW_ADDITIONAL_EXTENSIONS) {
926 data['video/ogg'].push('.ogg')
928 Object.assign(data, {
929 'video/x-matroska': '.mkv',
931 // Developed by Apple
932 'video/quicktime': [ '.mov', '.qt', '.mqv' ], // often used as output format by editing software
933 'video/x-m4v': '.m4v',
936 // Developed by the Adobe Flash Platform
937 'video/x-flv': '.flv',
938 'video/x-f4v': '.f4v', // replacement for flv
940 // Developed by Microsoft
941 'video/x-ms-wmv': '.wmv',
942 'video/x-msvideo': '.avi',
946 // common video formats for cell phones
947 'video/3gpp': [ '.3gp', '.3gpp' ],
948 'video/3gpp2': [ '.3g2', '.3gpp2' ],
950 // Developed by FFmpeg/Mplayer
951 'application/x-nut': '.nut',
953 // The standard video format used by many Sony and Panasonic HD camcorders.
954 // It is also used for storing high definition video on Blu-ray discs.
955 'video/mp2t': '.mts',
956 'video/m2ts': '.m2ts',
958 // Old formats reliant on MPEG-1/MPEG-2
960 'video/mpeg2': '.m2v',
961 'video/mpeg': [ '.m1v', '.mpg', '.mpe', '.mpeg', '.vob' ],
965 'application/octet-stream': null,
966 'application/mxf': '.mxf' // often used as exchange format by editing software
970 if (CONFIG.TRANSCODING.ALLOW_AUDIO_FILES) {
971 Object.assign(data, MIMETYPES.AUDIO.MIMETYPE_EXT)
978 function updateWebserverUrls () {
979 WEBSERVER.URL = sanitizeUrl(CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT)
980 WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT, REMOTE_SCHEME.HTTP)
981 WEBSERVER.WS = CONFIG.WEBSERVER.WS
983 WEBSERVER.SCHEME = CONFIG.WEBSERVER.SCHEME
984 WEBSERVER.HOSTNAME = CONFIG.WEBSERVER.HOSTNAME
985 WEBSERVER.PORT = CONFIG.WEBSERVER.PORT
987 WEBSERVER.RTMP_URL = 'rtmp://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.LIVE.RTMP.PORT + '/' + VIDEO_LIVE.RTMP.BASE_PATH
990 function updateWebserverConfig () {
991 MIMETYPES.VIDEO.MIMETYPE_EXT = buildVideoMimetypeExt()
992 MIMETYPES.VIDEO.MIMETYPES_REGEX = buildMimetypesRegex(MIMETYPES.VIDEO.MIMETYPE_EXT)
994 ACTIVITY_PUB.URL_MIME_TYPES.VIDEO = Object.keys(MIMETYPES.VIDEO.MIMETYPE_EXT)
996 MIMETYPES.VIDEO.EXT_MIMETYPE = buildVideoExtMimetype(MIMETYPES.VIDEO.MIMETYPE_EXT)
998 CONSTRAINTS_FIELDS.VIDEOS.EXTNAME = Object.keys(MIMETYPES.VIDEO.EXT_MIMETYPE)
1001 function buildVideoExtMimetype (obj: { [ id: string ]: string | string[] }) {
1002 const result: { [id: string]: string } = {}
1004 for (const mimetype of Object.keys(obj)) {
1005 const value = obj[mimetype]
1006 if (!value) continue
1008 const extensions = Array.isArray(value) ? value : [ value ]
1010 for (const extension of extensions) {
1011 result[extension] = mimetype
1018 function buildMimetypesRegex (obj: { [id: string]: string | string[] }) {
1019 return Object.keys(obj)
1024 function loadLanguages () {
1025 Object.assign(VIDEO_LANGUAGES, buildLanguages())
1028 function buildLanguages () {
1029 const iso639 = require('iso-639-3')
1031 const languages: { [id: string]: string } = {}
1033 const additionalLanguages = {
1034 sgn: true, // Sign languages (macro language)
1035 ase: true, // American sign language
1036 sdl: true, // Arabian sign language
1037 bfi: true, // British sign language
1038 bzs: true, // Brazilian sign language
1039 csl: true, // Chinese sign language
1040 cse: true, // Czech sign language
1041 dsl: true, // Danish sign language
1042 fsl: true, // French sign language
1043 gsg: true, // German sign language
1044 pks: true, // Pakistan sign language
1045 jsl: true, // Japanese sign language
1046 sfs: true, // South African sign language
1047 swl: true, // Swedish sign language
1048 rsl: true, // Russian sign language
1050 kab: true, // Kabyle
1052 epo: true, // Esperanto
1053 tlh: true, // Klingon
1054 jbo: true, // Lojban
1058 // Only add ISO639-1 languages and some sign languages (ISO639-3)
1061 return (l.iso6391 !== undefined && l.type === 'living') ||
1062 additionalLanguages[l.iso6393] === true
1064 .forEach(l => { languages[l.iso6391 || l.iso6393] = l.name })
1066 // Override Occitan label
1067 languages['oc'] = 'Occitan'
1068 languages['el'] = 'Greek'
1073 function generateContentHash () {
1074 return randomBytes(20).toString('hex')