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'
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 = 670
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 INSTANCE_FOLLOWERS: [ 'createdAt', 'state', 'score' ],
73 INSTANCE_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' ],
80 VIDEO_PLAYLISTS_SEARCH: [ 'match', 'displayName', 'createdAt' ],
82 ABUSES: [ 'id', 'createdAt', 'state' ],
84 ACCOUNTS_BLOCKLIST: [ 'createdAt' ],
85 SERVERS_BLOCKLIST: [ 'createdAt' ],
87 USER_NOTIFICATIONS: [ 'createdAt', 'read' ],
89 VIDEO_PLAYLISTS: [ 'name', 'displayName', 'createdAt', 'updatedAt' ],
91 PLUGINS: [ 'name', 'createdAt', 'updatedAt' ],
93 AVAILABLE_PLUGINS: [ 'npmName', 'popularity' ],
95 VIDEO_REDUNDANCIES: [ 'name' ]
98 const OAUTH_LIFETIME = {
99 ACCESS_TOKEN: 3600 * 24, // 1 day, for upload
100 REFRESH_TOKEN: 1209600 // 2 weeks
103 const ROUTE_CACHE_LIFETIME = {
107 SECURITYTXT: '2 hours',
108 NODEINFO: '10 minutes',
109 DNT_POLICY: '1 week',
111 VIDEOS: '1 second' // 1 second, cache concurrent requests after a broadcast for example
116 // ---------------------------------------------------------------------------
118 // Number of points we add/remove after a successful/bad request
119 const ACTOR_FOLLOW_SCORE = {
126 const FOLLOW_STATES: { [ id: string ]: FollowState } = {
131 const REMOTE_SCHEME = {
136 const JOB_ATTEMPTS: { [id in JobType]: number } = {
137 'activitypub-http-broadcast': 1,
138 'activitypub-http-unicast': 1,
139 'activitypub-http-fetcher': 2,
140 'activitypub-follow': 5,
141 'activitypub-cleaner': 1,
142 'video-file-import': 1,
143 'video-transcoding': 1,
148 'activitypub-refresher': 1,
149 'video-redundancy': 1,
150 'video-live-ending': 1,
151 'move-to-object-storage': 3
153 // Excluded keys are jobs that can be configured by admins
154 const JOB_CONCURRENCY: { [id in Exclude<JobType, 'video-transcoding' | 'video-import'>]: number } = {
155 'activitypub-http-broadcast': 1,
156 'activitypub-http-unicast': 10,
157 'activitypub-http-fetcher': 3,
158 'activitypub-cleaner': 1,
159 'activitypub-follow': 1,
160 'video-file-import': 1,
164 'activitypub-refresher': 1,
165 'video-redundancy': 1,
166 'video-live-ending': 10,
167 'move-to-object-storage': 1
169 const JOB_TTL: { [id in JobType]: number } = {
170 'activitypub-http-broadcast': 60000 * 10, // 10 minutes
171 'activitypub-http-unicast': 60000 * 10, // 10 minutes
172 'activitypub-http-fetcher': 1000 * 3600 * 10, // 10 hours
173 'activitypub-follow': 60000 * 10, // 10 minutes
174 'activitypub-cleaner': 1000 * 3600, // 1 hour
175 'video-file-import': 1000 * 3600, // 1 hour
176 'video-transcoding': 1000 * 3600 * 48, // 2 days, transcoding could be long
177 'video-import': 1000 * 3600 * 2, // 2 hours
178 'email': 60000 * 10, // 10 minutes
179 'actor-keys': 60000 * 20, // 20 minutes
180 'videos-views': undefined, // Unlimited
181 'activitypub-refresher': 60000 * 10, // 10 minutes
182 'video-redundancy': 1000 * 3600 * 3, // 3 hours
183 'video-live-ending': 1000 * 60 * 10, // 10 minutes
184 'move-to-object-storage': 1000 * 60 * 60 * 3 // 3 hours
186 const REPEAT_JOBS: { [ id: string ]: EveryRepeatOptions | CronRepeatOptions } = {
188 cron: randomInt(1, 20) + ' * * * *' // Between 1-20 minutes past the hour
190 'activitypub-cleaner': {
191 cron: '30 5 * * ' + randomInt(0, 7) // 1 time per week (random day) at 5:30 AM
194 const JOB_PRIORITY = {
198 const BROADCAST_CONCURRENCY = 30 // How many requests in parallel we do in activitypub-http-broadcast job
199 const AP_CLEANER_CONCURRENCY = 10 // How many requests in parallel we do in activitypub-cleaner job
200 const CRAWL_REQUEST_CONCURRENCY = 1 // How many requests in parallel to fetch remote data (likes, shares...)
201 const REQUEST_TIMEOUT = 7000 // 7 seconds
202 const JOB_COMPLETED_LIFETIME = 60000 * 60 * 24 * 2 // 2 days
203 const VIDEO_IMPORT_TIMEOUT = 1000 * 3600 // 1 hour
205 const SCHEDULER_INTERVALS_MS = {
206 actorFollowScores: 60000 * 60, // 1 hour
207 removeOldJobs: 60000 * 60, // 1 hour
208 updateVideos: 60000, // 1 minute
209 youtubeDLUpdate: 60000 * 60 * 24, // 1 day
210 checkPlugins: CONFIG.PLUGINS.INDEX.CHECK_LATEST_VERSIONS_INTERVAL,
211 checkPeerTubeVersion: 60000 * 60 * 24, // 1 day
212 autoFollowIndexInstances: 60000 * 60 * 24, // 1 day
213 removeOldViews: 60000 * 60 * 24, // 1 day
214 removeOldHistory: 60000 * 60 * 24, // 1 day
215 updateInboxStats: 1000 * 60, // 1 minute
216 removeDanglingResumableUploads: 60000 * 60 * 16 // 16 hours
219 // ---------------------------------------------------------------------------
221 const CONSTRAINTS_FIELDS = {
223 NAME: { min: 1, max: 120 }, // Length
224 DESCRIPTION: { min: 3, max: 1000 }, // Length
225 USERNAME: { min: 1, max: 50 }, // Length
226 PASSWORD: { min: 6, max: 255 }, // Length
227 VIDEO_QUOTA: { min: -1 },
228 VIDEO_QUOTA_DAILY: { min: -1 },
229 VIDEO_LANGUAGES: { max: 500 }, // Array length
230 BLOCKED_REASON: { min: 3, max: 250 } // Length
233 REASON: { min: 2, max: 3000 }, // Length
234 MODERATION_COMMENT: { min: 2, max: 3000 } // Length
237 MESSAGE: { min: 2, max: 3000 } // Length
240 REASON: { min: 2, max: 300 } // Length
243 NAME: { min: 1, max: 120 }, // Length
244 DESCRIPTION: { min: 3, max: 1000 }, // Length
245 SUPPORT: { min: 3, max: 1000 }, // Length
246 URL: { min: 3, max: 2000 } // Length
250 EXTNAME: [ '.vtt', '.srt' ],
252 max: 4 * 1024 * 1024 // 4MB
257 URL: { min: 3, max: 2000 }, // Length
258 TORRENT_NAME: { min: 3, max: 255 }, // Length
260 EXTNAME: [ '.torrent' ],
262 max: 1024 * 200 // 200 KB
267 URL: { min: 3, max: 2000 } // Length
270 URL: { min: 3, max: 2000 } // Length
273 NAME: { min: 3, max: 120 }, // Length
274 LANGUAGE: { min: 1, max: 10 }, // Length
275 TRUNCATED_DESCRIPTION: { min: 3, max: 250 }, // Length
276 DESCRIPTION: { min: 3, max: 10000 }, // Length
277 SUPPORT: { min: 3, max: 1000 }, // Length
279 EXTNAME: [ '.png', '.jpg', '.jpeg', '.webp' ],
281 max: 4 * 1024 * 1024 // 4MB
284 EXTNAME: [] as string[],
285 INFO_HASH: { min: 40, max: 40 }, // Length, info hash is 20 bytes length but we represent it in hexadecimal so 20 * 2
286 DURATION: { min: 0 }, // Number
287 TAGS: { min: 0, max: 5 }, // Number of total tags
288 TAG: { min: 2, max: 30 }, // Length
291 DISLIKES: { min: 0 },
292 FILE_SIZE: { min: -1 },
293 PARTIAL_UPLOAD_SIZE: { max: 50 * 1024 * 1024 * 1024 }, // 50GB
294 URL: { min: 3, max: 2000 } // Length
297 NAME: { min: 1, max: 120 }, // Length
298 DESCRIPTION: { min: 3, max: 1000 }, // Length
299 URL: { min: 3, max: 2000 }, // Length
301 EXTNAME: [ '.jpg', '.jpeg' ],
303 max: 4 * 1024 * 1024 // 4MB
308 PUBLIC_KEY: { min: 10, max: 5000 }, // Length
309 PRIVATE_KEY: { min: 10, max: 5000 }, // Length
310 URL: { min: 3, max: 2000 }, // Length
312 EXTNAME: [ '.png', '.jpeg', '.jpg', '.gif', '.webp' ],
314 max: 4 * 1024 * 1024 // 4MB
322 TEXT: { min: 1, max: 10000 }, // Length
323 URL: { min: 3, max: 2000 } // Length
326 URL: { min: 3, max: 2000 } // Length
329 FROM_NAME: { min: 1, max: 120 }, // Length
330 BODY: { min: 3, max: 5000 } // Length
333 NAME: { min: 1, max: 214 }, // Length
334 DESCRIPTION: { min: 1, max: 20000 } // Length
337 URL: { min: 5, max: 2000 } // Length
341 const VIEW_LIFETIME = {
342 VIDEO: 60000 * 60, // 1 hour
343 LIVE: 60000 * 5 // 5 minutes
346 let CONTACT_FORM_LIFETIME = 60000 * 60 // 1 hour
348 const VIDEO_TRANSCODING_FPS: VideoTranscodingFPS = {
350 STANDARD: [ 24, 25, 30 ],
351 HD_STANDARD: [ 50, 60 ],
354 KEEP_ORIGIN_FPS_RESOLUTION_MIN: 720 // We keep the original FPS on high resolutions (720 minimum)
357 const DEFAULT_AUDIO_RESOLUTION = VideoResolution.H_480P
359 const VIDEO_RATE_TYPES: { [ id: string ]: VideoRateType } = {
364 const FFMPEG_NICE: { [ id: string ]: number } = {
365 // parent process defaults to niceness = 0
366 // reminder: lower = higher priority, max value is 19, lowest is -20
367 LIVE: 5, // prioritize over VOD and THUMBNAIL
372 const VIDEO_CATEGORIES = {
383 11: 'News & Politics',
387 15: 'Science & Technology',
393 // See https://creativecommons.org/licenses/?lang=en
394 const VIDEO_LICENCES = {
396 2: 'Attribution - Share Alike',
397 3: 'Attribution - No Derivatives',
398 4: 'Attribution - Non Commercial',
399 5: 'Attribution - Non Commercial - Share Alike',
400 6: 'Attribution - Non Commercial - No Derivatives',
401 7: 'Public Domain Dedication'
404 const VIDEO_LANGUAGES: { [id: string]: string } = {}
406 const VIDEO_PRIVACIES: { [ id in VideoPrivacy ]: string } = {
407 [VideoPrivacy.PUBLIC]: 'Public',
408 [VideoPrivacy.UNLISTED]: 'Unlisted',
409 [VideoPrivacy.PRIVATE]: 'Private',
410 [VideoPrivacy.INTERNAL]: 'Internal'
413 const VIDEO_STATES: { [ id in VideoState ]: string } = {
414 [VideoState.PUBLISHED]: 'Published',
415 [VideoState.TO_TRANSCODE]: 'To transcode',
416 [VideoState.TO_IMPORT]: 'To import',
417 [VideoState.WAITING_FOR_LIVE]: 'Waiting for livestream',
418 [VideoState.LIVE_ENDED]: 'Livestream ended',
419 [VideoState.TO_MOVE_TO_EXTERNAL_STORAGE]: 'To move to an external storage'
422 const VIDEO_IMPORT_STATES: { [ id in VideoImportState ]: string } = {
423 [VideoImportState.FAILED]: 'Failed',
424 [VideoImportState.PENDING]: 'Pending',
425 [VideoImportState.SUCCESS]: 'Success',
426 [VideoImportState.REJECTED]: 'Rejected'
429 const ABUSE_STATES: { [ id in AbuseState ]: string } = {
430 [AbuseState.PENDING]: 'Pending',
431 [AbuseState.REJECTED]: 'Rejected',
432 [AbuseState.ACCEPTED]: 'Accepted'
435 const VIDEO_PLAYLIST_PRIVACIES: { [ id in VideoPlaylistPrivacy ]: string } = {
436 [VideoPlaylistPrivacy.PUBLIC]: 'Public',
437 [VideoPlaylistPrivacy.UNLISTED]: 'Unlisted',
438 [VideoPlaylistPrivacy.PRIVATE]: 'Private'
441 const VIDEO_PLAYLIST_TYPES: { [ id in VideoPlaylistType ]: string } = {
442 [VideoPlaylistType.REGULAR]: 'Regular',
443 [VideoPlaylistType.WATCH_LATER]: 'Watch later'
449 'audio/mpeg': '.mp3',
451 'application/ogg': '.ogg',
453 'audio/x-ms-wma': '.wma',
455 'audio/x-wav': '.wav',
456 'audio/x-flac': '.flac',
457 'audio/flac': '.flac',
461 'audio/x-m4a': '.m4a',
464 EXT_MIMETYPE: null as { [ id: string ]: string }
467 MIMETYPE_EXT: null as { [ id: string ]: string | string[] },
468 MIMETYPES_REGEX: null as string,
469 EXT_MIMETYPE: null as { [ id: string ]: string }
475 'image/webp': '.webp',
479 EXT_MIMETYPE: null as { [ id: string ]: string }
484 'application/x-subrip': '.srt',
490 'application/x-bittorrent': '.torrent'
494 MIMETYPES.AUDIO.EXT_MIMETYPE = invert(MIMETYPES.AUDIO.MIMETYPE_EXT)
495 MIMETYPES.IMAGE.EXT_MIMETYPE = invert(MIMETYPES.IMAGE.MIMETYPE_EXT)
497 // ---------------------------------------------------------------------------
506 const VIDEO_CHANNELS = {
510 // ---------------------------------------------------------------------------
512 const SERVER_ACTOR_NAME = 'peertube'
514 const ACTIVITY_PUB = {
515 POTENTIAL_ACCEPT_HEADERS: [
516 'application/activity+json',
517 'application/ld+json',
518 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
520 ACCEPT_HEADER: 'application/activity+json, application/ld+json',
521 PUBLIC: 'https://www.w3.org/ns/activitystreams#Public',
522 COLLECTION_ITEMS_PER_PAGE: 10,
523 FETCH_PAGE_LIMIT: 2000,
525 VIDEO: [] as string[],
526 TORRENT: [ 'application/x-bittorrent' ],
527 MAGNET: [ 'application/x-bittorrent;x-scheme-handler/magnet' ]
529 MAX_RECURSION_COMMENTS: 100,
530 ACTOR_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2, // 2 days
531 VIDEO_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2, // 2 days
532 VIDEO_PLAYLIST_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2 // 2 days
535 const ACTIVITY_PUB_ACTOR_TYPES: { [ id: string ]: ActivityPubActorType } = {
538 APPLICATION: 'Application',
539 ORGANIZATION: 'Organization',
543 const HTTP_SIGNATURE = {
544 HEADER_NAME: 'signature',
545 ALGORITHM: 'rsa-sha256',
546 HEADERS_TO_SIGN: [ '(request-target)', 'host', 'date', 'digest' ],
548 ALL: [ '(request-target)', 'host', 'date' ],
549 POST: [ '(request-target)', 'host', 'date', 'digest' ]
551 CLOCK_SKEW_SECONDS: 1800
554 // ---------------------------------------------------------------------------
556 let PRIVATE_RSA_KEY_SIZE = 2048
558 // Password encryption
559 const BCRYPT_SALT_SIZE = 10
561 const USER_PASSWORD_RESET_LIFETIME = 60000 * 60 // 60 minutes
562 const USER_PASSWORD_CREATE_LIFETIME = 60000 * 60 * 24 * 7 // 7 days
564 const USER_EMAIL_VERIFY_LIFETIME = 60000 * 60 // 60 minutes
566 const NSFW_POLICY_TYPES: { [ id: string ]: NSFWPolicyType } = {
567 DO_NOT_LIST: 'do_not_list',
572 // ---------------------------------------------------------------------------
574 // Express static paths (router)
575 const STATIC_PATHS = {
576 THUMBNAILS: '/static/thumbnails/',
577 TORRENTS: '/static/torrents/',
578 WEBSEED: '/static/webseed/',
579 REDUNDANCY: '/static/redundancy/',
580 STREAMING_PLAYLISTS: {
581 HLS: '/static/streaming-playlists/hls'
584 const STATIC_DOWNLOAD_PATHS = {
585 TORRENTS: '/download/torrents/',
586 VIDEOS: '/download/videos/',
587 HLS_VIDEOS: '/download/streaming-playlists/hls/videos/'
589 const LAZY_STATIC_PATHS = {
590 BANNERS: '/lazy-static/banners/',
591 AVATARS: '/lazy-static/avatars/',
592 PREVIEWS: '/lazy-static/previews/',
593 VIDEO_CAPTIONS: '/lazy-static/video-captions/',
594 TORRENTS: '/lazy-static/torrents/'
598 const STATIC_MAX_AGE = {
604 // Videos thumbnail size
605 const THUMBNAILS_SIZE = {
610 const PREVIEWS_SIZE = {
615 const ACTOR_IMAGES_SIZE = {
622 height: 317 // 6/1 ratio
631 // Sub folders of cache directory
632 const FILES_CACHE = {
634 DIRECTORY: join(CONFIG.STORAGE.CACHE_DIR, 'previews'),
635 MAX_AGE: 1000 * 3600 * 3 // 3 hours
638 DIRECTORY: join(CONFIG.STORAGE.CACHE_DIR, 'video-captions'),
639 MAX_AGE: 1000 * 3600 * 3 // 3 hours
642 DIRECTORY: join(CONFIG.STORAGE.CACHE_DIR, 'torrents'),
643 MAX_AGE: 1000 * 3600 * 3 // 3 hours
651 ACTOR_IMAGE_STATIC: {
656 const RESUMABLE_UPLOAD_DIRECTORY = join(CONFIG.STORAGE.TMP_DIR, 'resumable-uploads')
657 const HLS_STREAMING_PLAYLIST_DIRECTORY = join(CONFIG.STORAGE.STREAMING_PLAYLISTS_DIR, 'hls')
658 const HLS_REDUNDANCY_DIRECTORY = join(CONFIG.STORAGE.REDUNDANCY_DIR, 'hls')
662 CLEANUP_DELAY: 1000 * 60 * 5, // 5 minutes
663 SEGMENT_TIME_SECONDS: 4, // 4 seconds
664 SEGMENTS_LIST_SIZE: 15, // 15 maximum segments in live playlist
665 REPLAY_DIRECTORY: 'replay',
666 EDGE_LIVE_DELAY_SEGMENTS_NOTIFICATION: 4,
667 MAX_SOCKET_WAITING_DATA: 1024 * 1000 * 100, // 100MB
677 const MEMOIZE_TTL = {
678 OVERVIEWS_SAMPLE: 1000 * 3600 * 4, // 4 hours
679 INFO_HASH_EXISTS: 1000 * 3600 * 12, // 12 hours
680 LIVE_ABLE_TO_UPLOAD: 1000 * 60, // 1 minute
681 LIVE_CHECK_SOCKET_HEALTH: 1000 * 60 // 1 minute
684 const MEMOIZE_LENGTH = {
685 INFO_HASH_EXISTS: 200
688 const QUEUE_CONCURRENCY = {
689 ACTOR_PROCESS_IMAGE: 3
698 const ACCEPT_HEADERS = [ 'html', 'application/json' ].concat(ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS)
700 const ASSETS_PATH = {
701 DEFAULT_AUDIO_BACKGROUND: join(root(), 'dist', 'server', 'assets', 'default-audio-background.jpg'),
702 DEFAULT_LIVE_BACKGROUND: join(root(), 'dist', 'server', 'assets', 'default-live-background.jpg')
705 // ---------------------------------------------------------------------------
707 const CUSTOM_HTML_TAG_COMMENTS = {
708 TITLE: '<!-- title tag -->',
709 DESCRIPTION: '<!-- description tag -->',
710 CUSTOM_CSS: '<!-- custom css tag -->',
711 META_TAGS: '<!-- meta tags -->',
712 SERVER_CONFIG: '<!-- server config -->'
715 // ---------------------------------------------------------------------------
721 const MAX_LOGS_OUTPUT_CHARACTERS = 10 * 1000 * 1000
722 const LOG_FILENAME = 'peertube.log'
723 const AUDIT_LOG_FILENAME = 'peertube-audit.log'
725 // ---------------------------------------------------------------------------
727 const TRACKER_RATE_LIMITS = {
728 INTERVAL: 60000 * 5, // 5 minutes
729 ANNOUNCES_PER_IP_PER_INFOHASH: 15, // maximum announces per torrent in the interval
730 ANNOUNCES_PER_IP: 30, // maximum announces for all our torrents in the interval
731 BLOCK_IP_LIFETIME: 60000 * 3 // 3 minutes
734 const P2P_MEDIA_LOADER_PEER_VERSION = 2
736 // ---------------------------------------------------------------------------
738 const PLUGIN_GLOBAL_CSS_FILE_NAME = 'plugins-global.css'
739 const PLUGIN_GLOBAL_CSS_PATH = join(CONFIG.STORAGE.TMP_DIR, PLUGIN_GLOBAL_CSS_FILE_NAME)
741 let PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME = 1000 * 60 * 5 // 5 minutes
743 const DEFAULT_THEME_NAME = 'default'
744 const DEFAULT_USER_THEME_NAME = 'instance-default'
746 // ---------------------------------------------------------------------------
748 const SEARCH_INDEX = {
750 VIDEOS: '/api/v1/search/videos',
751 VIDEO_CHANNELS: '/api/v1/search/video-channels'
755 // ---------------------------------------------------------------------------
757 // Special constants for a test instance
758 if (isTestInstance() === true) {
759 PRIVATE_RSA_KEY_SIZE = 1024
761 ACTOR_FOLLOW_SCORE.BASE = 20
763 REMOTE_SCHEME.HTTP = 'http'
764 REMOTE_SCHEME.WS = 'ws'
766 STATIC_MAX_AGE.SERVER = '0'
768 ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE = 2
769 ACTIVITY_PUB.ACTOR_REFRESH_INTERVAL = 10 * 1000 // 10 seconds
770 ACTIVITY_PUB.VIDEO_REFRESH_INTERVAL = 10 * 1000 // 10 seconds
771 ACTIVITY_PUB.VIDEO_PLAYLIST_REFRESH_INTERVAL = 10 * 1000 // 10 seconds
773 CONSTRAINTS_FIELDS.ACTORS.IMAGE.FILE_SIZE.max = 100 * 1024 // 100KB
774 CONSTRAINTS_FIELDS.VIDEOS.IMAGE.FILE_SIZE.max = 400 * 1024 // 400KB
776 SCHEDULER_INTERVALS_MS.actorFollowScores = 1000
777 SCHEDULER_INTERVALS_MS.removeOldJobs = 10000
778 SCHEDULER_INTERVALS_MS.removeOldHistory = 5000
779 SCHEDULER_INTERVALS_MS.removeOldViews = 5000
780 SCHEDULER_INTERVALS_MS.updateVideos = 5000
781 SCHEDULER_INTERVALS_MS.autoFollowIndexInstances = 5000
782 SCHEDULER_INTERVALS_MS.updateInboxStats = 5000
783 SCHEDULER_INTERVALS_MS.checkPeerTubeVersion = 2000
784 REPEAT_JOBS['videos-views'] = { every: 5000 }
785 REPEAT_JOBS['activitypub-cleaner'] = { every: 5000 }
787 REDUNDANCY.VIDEOS.RANDOMIZED_FACTOR = 1
789 VIEW_LIFETIME.VIDEO = 1000 // 1 second
790 VIEW_LIFETIME.LIVE = 1000 * 5 // 5 second
791 CONTACT_FORM_LIFETIME = 1000 // 1 second
793 JOB_ATTEMPTS['email'] = 1
795 FILES_CACHE.VIDEO_CAPTIONS.MAX_AGE = 3000
796 MEMOIZE_TTL.OVERVIEWS_SAMPLE = 3000
797 MEMOIZE_TTL.LIVE_ABLE_TO_UPLOAD = 3000
798 OVERVIEWS.VIDEOS.SAMPLE_THRESHOLD = 2
800 PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME = 5000
802 VIDEO_LIVE.CLEANUP_DELAY = 5000
803 VIDEO_LIVE.SEGMENT_TIME_SECONDS = 2
804 VIDEO_LIVE.EDGE_LIVE_DELAY_SEGMENTS_NOTIFICATION = 1
807 updateWebserverUrls()
808 updateWebserverConfig()
810 registerConfigChangedHandler(() => {
811 updateWebserverUrls()
812 updateWebserverConfig()
815 // ---------------------------------------------------------------------------
817 const FILES_CONTENT_HASH = {
818 MANIFEST: generateContentHash(),
819 FAVICON: generateContentHash(),
820 LOGO: generateContentHash()
823 // ---------------------------------------------------------------------------
832 RESUMABLE_UPLOAD_DIRECTORY,
833 HLS_REDUNDANCY_DIRECTORY,
834 P2P_MEDIA_LOADER_PEER_VERSION,
846 AP_CLEANER_CONCURRENCY,
847 LAST_MIGRATION_VERSION,
849 CUSTOM_HTML_TAG_COMMENTS,
850 BROADCAST_CONCURRENCY,
857 DEFAULT_USER_THEME_NAME,
859 PLUGIN_GLOBAL_CSS_FILE_NAME,
860 PLUGIN_GLOBAL_CSS_PATH,
861 PRIVATE_RSA_KEY_SIZE,
862 ROUTE_CACHE_LIFETIME,
864 HLS_STREAMING_PLAYLIST_DIRECTORY,
871 VIDEO_IMPORT_TIMEOUT,
872 VIDEO_PLAYLIST_TYPES,
873 MAX_LOGS_OUTPUT_CHARACTERS,
875 ACTIVITY_PUB_ACTOR_TYPES,
886 VIDEO_TRANSCODING_FPS,
892 USER_PASSWORD_RESET_LIFETIME,
893 USER_PASSWORD_CREATE_LIFETIME,
895 USER_EMAIL_VERIFY_LIFETIME,
897 SCHEDULER_INTERVALS_MS,
899 STATIC_DOWNLOAD_PATHS,
901 CRAWL_REQUEST_CONCURRENCY,
902 DEFAULT_AUDIO_RESOLUTION,
903 JOB_COMPLETED_LIFETIME,
907 CONTACT_FORM_LIFETIME,
908 VIDEO_PLAYLIST_PRIVACIES,
909 PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME,
917 // ---------------------------------------------------------------------------
919 function buildVideoMimetypeExt () {
921 // streamable formats that warrant cross-browser compatibility
922 'video/webm': '.webm',
923 // We'll add .ogg if additional extensions are enabled
924 // We could add .ogg here but since it could be an audio file,
925 // it would be confusing for users because PeerTube will refuse their file (based on the mimetype)
926 'video/ogg': [ '.ogv' ],
930 if (CONFIG.TRANSCODING.ENABLED) {
931 if (CONFIG.TRANSCODING.ALLOW_ADDITIONAL_EXTENSIONS) {
932 data['video/ogg'].push('.ogg')
934 Object.assign(data, {
935 'video/x-matroska': '.mkv',
937 // Developed by Apple
938 'video/quicktime': [ '.mov', '.qt', '.mqv' ], // often used as output format by editing software
939 'video/x-m4v': '.m4v',
942 // Developed by the Adobe Flash Platform
943 'video/x-flv': '.flv',
944 'video/x-f4v': '.f4v', // replacement for flv
946 // Developed by Microsoft
947 'video/x-ms-wmv': '.wmv',
948 'video/x-msvideo': '.avi',
952 // common video formats for cell phones
953 'video/3gpp': [ '.3gp', '.3gpp' ],
954 'video/3gpp2': [ '.3g2', '.3gpp2' ],
956 // Developed by FFmpeg/Mplayer
957 'application/x-nut': '.nut',
959 // The standard video format used by many Sony and Panasonic HD camcorders.
960 // It is also used for storing high definition video on Blu-ray discs.
961 'video/mp2t': '.mts',
962 'video/m2ts': '.m2ts',
964 // Old formats reliant on MPEG-1/MPEG-2
966 'video/mpeg2': '.m2v',
967 'video/mpeg': [ '.m1v', '.mpg', '.mpe', '.mpeg', '.vob' ],
971 'application/octet-stream': null,
972 'application/mxf': '.mxf' // often used as exchange format by editing software
976 if (CONFIG.TRANSCODING.ALLOW_AUDIO_FILES) {
977 Object.assign(data, MIMETYPES.AUDIO.MIMETYPE_EXT)
984 function updateWebserverUrls () {
985 WEBSERVER.URL = sanitizeUrl(CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT)
986 WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT, REMOTE_SCHEME.HTTP)
987 WEBSERVER.WS = CONFIG.WEBSERVER.WS
989 WEBSERVER.SCHEME = CONFIG.WEBSERVER.SCHEME
990 WEBSERVER.HOSTNAME = CONFIG.WEBSERVER.HOSTNAME
991 WEBSERVER.PORT = CONFIG.WEBSERVER.PORT
993 WEBSERVER.RTMP_URL = 'rtmp://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.LIVE.RTMP.PORT + '/' + VIDEO_LIVE.RTMP.BASE_PATH
996 function updateWebserverConfig () {
997 MIMETYPES.VIDEO.MIMETYPE_EXT = buildVideoMimetypeExt()
998 MIMETYPES.VIDEO.MIMETYPES_REGEX = buildMimetypesRegex(MIMETYPES.VIDEO.MIMETYPE_EXT)
1000 ACTIVITY_PUB.URL_MIME_TYPES.VIDEO = Object.keys(MIMETYPES.VIDEO.MIMETYPE_EXT)
1002 MIMETYPES.VIDEO.EXT_MIMETYPE = buildVideoExtMimetype(MIMETYPES.VIDEO.MIMETYPE_EXT)
1004 CONSTRAINTS_FIELDS.VIDEOS.EXTNAME = Object.keys(MIMETYPES.VIDEO.EXT_MIMETYPE)
1007 function buildVideoExtMimetype (obj: { [ id: string ]: string | string[] }) {
1008 const result: { [id: string]: string } = {}
1010 for (const mimetype of Object.keys(obj)) {
1011 const value = obj[mimetype]
1012 if (!value) continue
1014 const extensions = Array.isArray(value) ? value : [ value ]
1016 for (const extension of extensions) {
1017 result[extension] = mimetype
1024 function buildMimetypesRegex (obj: { [id: string]: string | string[] }) {
1025 return Object.keys(obj)
1030 function loadLanguages () {
1031 Object.assign(VIDEO_LANGUAGES, buildLanguages())
1034 function buildLanguages () {
1035 const iso639 = require('iso-639-3')
1037 const languages: { [id: string]: string } = {}
1039 const additionalLanguages = {
1040 sgn: true, // Sign languages (macro language)
1041 ase: true, // American sign language
1042 sdl: true, // Arabian sign language
1043 bfi: true, // British sign language
1044 bzs: true, // Brazilian sign language
1045 csl: true, // Chinese sign language
1046 cse: true, // Czech sign language
1047 dsl: true, // Danish sign language
1048 fsl: true, // French sign language
1049 gsg: true, // German sign language
1050 pks: true, // Pakistan sign language
1051 jsl: true, // Japanese sign language
1052 sfs: true, // South African sign language
1053 swl: true, // Swedish sign language
1054 rsl: true, // Russian sign language
1056 kab: true, // Kabyle
1060 epo: true, // Esperanto
1061 tlh: true, // Klingon
1062 jbo: true, // Lojban
1066 // Only add ISO639-1 languages and some sign languages (ISO639-3)
1069 return (l.iso6391 !== undefined && l.type === 'living') ||
1070 additionalLanguages[l.iso6393] === true
1072 .forEach(l => { languages[l.iso6391 || l.iso6393] = l.name })
1074 // Override Occitan label
1075 languages['oc'] = 'Occitan'
1076 languages['el'] = 'Greek'
1081 function generateContentHash () {
1082 return randomBytes(20).toString('hex')