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 = 655
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' ],
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': 5,
138 'activitypub-http-unicast': 5,
139 'activitypub-http-fetcher': 5,
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
152 // Excluded keys are jobs that can be configured by admins
153 const JOB_CONCURRENCY: { [id in Exclude<JobType, 'video-transcoding' | 'video-import'>]: number } = {
154 'activitypub-http-broadcast': 1,
155 'activitypub-http-unicast': 5,
156 'activitypub-http-fetcher': 3,
157 'activitypub-cleaner': 1,
158 'activitypub-follow': 1,
159 'video-file-import': 1,
163 'activitypub-refresher': 1,
164 'video-redundancy': 1,
165 'video-live-ending': 10
167 const JOB_TTL: { [id in JobType]: number } = {
168 'activitypub-http-broadcast': 60000 * 10, // 10 minutes
169 'activitypub-http-unicast': 60000 * 10, // 10 minutes
170 'activitypub-http-fetcher': 1000 * 3600 * 10, // 10 hours
171 'activitypub-follow': 60000 * 10, // 10 minutes
172 'activitypub-cleaner': 1000 * 3600, // 1 hour
173 'video-file-import': 1000 * 3600, // 1 hour
174 'video-transcoding': 1000 * 3600 * 48, // 2 days, transcoding could be long
175 'video-import': 1000 * 3600 * 2, // 2 hours
176 'email': 60000 * 10, // 10 minutes
177 'actor-keys': 60000 * 20, // 20 minutes
178 'videos-views': undefined, // Unlimited
179 'activitypub-refresher': 60000 * 10, // 10 minutes
180 'video-redundancy': 1000 * 3600 * 3, // 3 hours
181 'video-live-ending': 1000 * 60 * 10 // 10 minutes
183 const REPEAT_JOBS: { [ id: string ]: EveryRepeatOptions | CronRepeatOptions } = {
185 cron: randomInt(1, 20) + ' * * * *' // Between 1-20 minutes past the hour
187 'activitypub-cleaner': {
188 cron: '30 5 * * ' + randomInt(0, 7) // 1 time per week (random day) at 5:30 AM
191 const JOB_PRIORITY = {
195 const BROADCAST_CONCURRENCY = 30 // How many requests in parallel we do in activitypub-http-broadcast job
196 const AP_CLEANER_CONCURRENCY = 10 // How many requests in parallel we do in activitypub-cleaner job
197 const CRAWL_REQUEST_CONCURRENCY = 1 // How many requests in parallel to fetch remote data (likes, shares...)
198 const REQUEST_TIMEOUT = 7000 // 7 seconds
199 const JOB_COMPLETED_LIFETIME = 60000 * 60 * 24 * 2 // 2 days
200 const VIDEO_IMPORT_TIMEOUT = 1000 * 3600 // 1 hour
202 const SCHEDULER_INTERVALS_MS = {
203 actorFollowScores: 60000 * 60, // 1 hour
204 removeOldJobs: 60000 * 60, // 1 hour
205 updateVideos: 60000, // 1 minute
206 youtubeDLUpdate: 60000 * 60 * 24, // 1 day
207 checkPlugins: CONFIG.PLUGINS.INDEX.CHECK_LATEST_VERSIONS_INTERVAL,
208 checkPeerTubeVersion: 60000 * 60 * 24, // 1 day
209 autoFollowIndexInstances: 60000 * 60 * 24, // 1 day
210 removeOldViews: 60000 * 60 * 24, // 1 day
211 removeOldHistory: 60000 * 60 * 24, // 1 day
212 updateInboxStats: 1000 * 60, // 1 minute
213 removeDanglingResumableUploads: 60000 * 60 * 16 // 16 hours
216 // ---------------------------------------------------------------------------
218 const CONSTRAINTS_FIELDS = {
220 NAME: { min: 1, max: 120 }, // Length
221 DESCRIPTION: { min: 3, max: 1000 }, // Length
222 USERNAME: { min: 1, max: 50 }, // Length
223 PASSWORD: { min: 6, max: 255 }, // Length
224 VIDEO_QUOTA: { min: -1 },
225 VIDEO_QUOTA_DAILY: { min: -1 },
226 VIDEO_LANGUAGES: { max: 500 }, // Array length
227 BLOCKED_REASON: { min: 3, max: 250 } // Length
230 REASON: { min: 2, max: 3000 }, // Length
231 MODERATION_COMMENT: { min: 2, max: 3000 } // Length
234 MESSAGE: { min: 2, max: 3000 } // Length
237 REASON: { min: 2, max: 300 } // Length
240 NAME: { min: 1, max: 120 }, // Length
241 DESCRIPTION: { min: 3, max: 1000 }, // Length
242 SUPPORT: { min: 3, max: 1000 }, // Length
243 URL: { min: 3, max: 2000 } // Length
247 EXTNAME: [ '.vtt', '.srt' ],
249 max: 4 * 1024 * 1024 // 4MB
254 URL: { min: 3, max: 2000 }, // Length
255 TORRENT_NAME: { min: 3, max: 255 }, // Length
257 EXTNAME: [ '.torrent' ],
259 max: 1024 * 200 // 200 KB
264 URL: { min: 3, max: 2000 } // Length
267 URL: { min: 3, max: 2000 } // Length
270 NAME: { min: 3, max: 120 }, // Length
271 LANGUAGE: { min: 1, max: 10 }, // Length
272 TRUNCATED_DESCRIPTION: { min: 3, max: 250 }, // Length
273 DESCRIPTION: { min: 3, max: 10000 }, // Length
274 SUPPORT: { min: 3, max: 1000 }, // Length
276 EXTNAME: [ '.png', '.jpg', '.jpeg', '.webp' ],
278 max: 4 * 1024 * 1024 // 4MB
281 EXTNAME: [] as string[],
282 INFO_HASH: { min: 40, max: 40 }, // Length, info hash is 20 bytes length but we represent it in hexadecimal so 20 * 2
283 DURATION: { min: 0 }, // Number
284 TAGS: { min: 0, max: 5 }, // Number of total tags
285 TAG: { min: 2, max: 30 }, // Length
288 DISLIKES: { min: 0 },
289 FILE_SIZE: { min: -1 },
290 PARTIAL_UPLOAD_SIZE: { max: 50 * 1024 * 1024 * 1024 }, // 50GB
291 URL: { min: 3, max: 2000 } // Length
294 NAME: { min: 1, max: 120 }, // Length
295 DESCRIPTION: { min: 3, max: 1000 }, // Length
296 URL: { min: 3, max: 2000 }, // Length
298 EXTNAME: [ '.jpg', '.jpeg' ],
300 max: 4 * 1024 * 1024 // 4MB
305 PUBLIC_KEY: { min: 10, max: 5000 }, // Length
306 PRIVATE_KEY: { min: 10, max: 5000 }, // Length
307 URL: { min: 3, max: 2000 }, // Length
309 EXTNAME: [ '.png', '.jpeg', '.jpg', '.gif', '.webp' ],
311 max: 4 * 1024 * 1024 // 4MB
319 TEXT: { min: 1, max: 10000 }, // Length
320 URL: { min: 3, max: 2000 } // Length
323 URL: { min: 3, max: 2000 } // Length
326 FROM_NAME: { min: 1, max: 120 }, // Length
327 BODY: { min: 3, max: 5000 } // Length
330 NAME: { min: 1, max: 214 }, // Length
331 DESCRIPTION: { min: 1, max: 20000 } // Length
334 URL: { min: 5, max: 2000 } // Length
338 const VIEW_LIFETIME = {
339 VIDEO: 60000 * 60, // 1 hour
340 LIVE: 60000 * 5 // 5 minutes
343 let CONTACT_FORM_LIFETIME = 60000 * 60 // 1 hour
345 const VIDEO_TRANSCODING_FPS: VideoTranscodingFPS = {
347 STANDARD: [ 24, 25, 30 ],
348 HD_STANDARD: [ 50, 60 ],
351 KEEP_ORIGIN_FPS_RESOLUTION_MIN: 720 // We keep the original FPS on high resolutions (720 minimum)
354 const DEFAULT_AUDIO_RESOLUTION = VideoResolution.H_480P
356 const VIDEO_RATE_TYPES: { [ id: string ]: VideoRateType } = {
361 const FFMPEG_NICE: { [ id: string ]: number } = {
362 // parent process defaults to niceness = 0
363 // reminder: lower = higher priority, max value is 19, lowest is -20
364 LIVE: 5, // prioritize over VOD and THUMBNAIL
369 const VIDEO_CATEGORIES = {
380 11: 'News & Politics',
384 15: 'Science & Technology',
390 // See https://creativecommons.org/licenses/?lang=en
391 const VIDEO_LICENCES = {
393 2: 'Attribution - Share Alike',
394 3: 'Attribution - No Derivatives',
395 4: 'Attribution - Non Commercial',
396 5: 'Attribution - Non Commercial - Share Alike',
397 6: 'Attribution - Non Commercial - No Derivatives',
398 7: 'Public Domain Dedication'
401 const VIDEO_LANGUAGES: { [id: string]: string } = {}
403 const VIDEO_PRIVACIES: { [ id in VideoPrivacy ]: string } = {
404 [VideoPrivacy.PUBLIC]: 'Public',
405 [VideoPrivacy.UNLISTED]: 'Unlisted',
406 [VideoPrivacy.PRIVATE]: 'Private',
407 [VideoPrivacy.INTERNAL]: 'Internal'
410 const VIDEO_STATES: { [ id in VideoState ]: string } = {
411 [VideoState.PUBLISHED]: 'Published',
412 [VideoState.TO_TRANSCODE]: 'To transcode',
413 [VideoState.TO_IMPORT]: 'To import',
414 [VideoState.WAITING_FOR_LIVE]: 'Waiting for livestream',
415 [VideoState.LIVE_ENDED]: 'Livestream ended'
418 const VIDEO_IMPORT_STATES: { [ id in VideoImportState ]: string } = {
419 [VideoImportState.FAILED]: 'Failed',
420 [VideoImportState.PENDING]: 'Pending',
421 [VideoImportState.SUCCESS]: 'Success',
422 [VideoImportState.REJECTED]: 'Rejected'
425 const ABUSE_STATES: { [ id in AbuseState ]: string } = {
426 [AbuseState.PENDING]: 'Pending',
427 [AbuseState.REJECTED]: 'Rejected',
428 [AbuseState.ACCEPTED]: 'Accepted'
431 const VIDEO_PLAYLIST_PRIVACIES: { [ id in VideoPlaylistPrivacy ]: string } = {
432 [VideoPlaylistPrivacy.PUBLIC]: 'Public',
433 [VideoPlaylistPrivacy.UNLISTED]: 'Unlisted',
434 [VideoPlaylistPrivacy.PRIVATE]: 'Private'
437 const VIDEO_PLAYLIST_TYPES: { [ id in VideoPlaylistType ]: string } = {
438 [VideoPlaylistType.REGULAR]: 'Regular',
439 [VideoPlaylistType.WATCH_LATER]: 'Watch later'
445 'audio/mpeg': '.mp3',
447 'application/ogg': '.ogg',
449 'audio/x-ms-wma': '.wma',
451 'audio/x-wav': '.wav',
452 'audio/x-flac': '.flac',
453 'audio/flac': '.flac',
457 'audio/x-m4a': '.m4a',
460 EXT_MIMETYPE: null as { [ id: string ]: string }
463 MIMETYPE_EXT: null as { [ id: string ]: string | string[] },
464 MIMETYPES_REGEX: null as string,
465 EXT_MIMETYPE: null as { [ id: string ]: string }
471 'image/webp': '.webp',
475 EXT_MIMETYPE: null as { [ id: string ]: string }
480 'application/x-subrip': '.srt',
486 'application/x-bittorrent': '.torrent'
490 MIMETYPES.AUDIO.EXT_MIMETYPE = invert(MIMETYPES.AUDIO.MIMETYPE_EXT)
491 MIMETYPES.IMAGE.EXT_MIMETYPE = invert(MIMETYPES.IMAGE.MIMETYPE_EXT)
493 // ---------------------------------------------------------------------------
502 const VIDEO_CHANNELS = {
506 // ---------------------------------------------------------------------------
508 const SERVER_ACTOR_NAME = 'peertube'
510 const ACTIVITY_PUB = {
511 POTENTIAL_ACCEPT_HEADERS: [
512 'application/activity+json',
513 'application/ld+json',
514 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
516 ACCEPT_HEADER: 'application/activity+json, application/ld+json',
517 PUBLIC: 'https://www.w3.org/ns/activitystreams#Public',
518 COLLECTION_ITEMS_PER_PAGE: 10,
519 FETCH_PAGE_LIMIT: 2000,
521 VIDEO: [] as string[],
522 TORRENT: [ 'application/x-bittorrent' ],
523 MAGNET: [ 'application/x-bittorrent;x-scheme-handler/magnet' ]
525 MAX_RECURSION_COMMENTS: 100,
526 ACTOR_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2, // 2 days
527 VIDEO_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2, // 2 days
528 VIDEO_PLAYLIST_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2 // 2 days
531 const ACTIVITY_PUB_ACTOR_TYPES: { [ id: string ]: ActivityPubActorType } = {
534 APPLICATION: 'Application',
535 ORGANIZATION: 'Organization',
539 const HTTP_SIGNATURE = {
540 HEADER_NAME: 'signature',
541 ALGORITHM: 'rsa-sha256',
542 HEADERS_TO_SIGN: [ '(request-target)', 'host', 'date', 'digest' ],
544 ALL: [ '(request-target)', 'host', 'date' ],
545 POST: [ '(request-target)', 'host', 'date', 'digest' ]
547 CLOCK_SKEW_SECONDS: 1800
550 // ---------------------------------------------------------------------------
552 let PRIVATE_RSA_KEY_SIZE = 2048
554 // Password encryption
555 const BCRYPT_SALT_SIZE = 10
557 const USER_PASSWORD_RESET_LIFETIME = 60000 * 60 // 60 minutes
558 const USER_PASSWORD_CREATE_LIFETIME = 60000 * 60 * 24 * 7 // 7 days
560 const USER_EMAIL_VERIFY_LIFETIME = 60000 * 60 // 60 minutes
562 const NSFW_POLICY_TYPES: { [ id: string ]: NSFWPolicyType } = {
563 DO_NOT_LIST: 'do_not_list',
568 // ---------------------------------------------------------------------------
570 // Express static paths (router)
571 const STATIC_PATHS = {
572 THUMBNAILS: '/static/thumbnails/',
573 TORRENTS: '/static/torrents/',
574 WEBSEED: '/static/webseed/',
575 REDUNDANCY: '/static/redundancy/',
576 STREAMING_PLAYLISTS: {
577 HLS: '/static/streaming-playlists/hls'
580 const STATIC_DOWNLOAD_PATHS = {
581 TORRENTS: '/download/torrents/',
582 VIDEOS: '/download/videos/',
583 HLS_VIDEOS: '/download/streaming-playlists/hls/videos/'
585 const LAZY_STATIC_PATHS = {
586 BANNERS: '/lazy-static/banners/',
587 AVATARS: '/lazy-static/avatars/',
588 PREVIEWS: '/lazy-static/previews/',
589 VIDEO_CAPTIONS: '/lazy-static/video-captions/',
590 TORRENTS: '/lazy-static/torrents/'
594 const STATIC_MAX_AGE = {
600 // Videos thumbnail size
601 const THUMBNAILS_SIZE = {
606 const PREVIEWS_SIZE = {
611 const ACTOR_IMAGES_SIZE = {
618 height: 317 // 6/1 ratio
627 // Sub folders of cache directory
628 const FILES_CACHE = {
630 DIRECTORY: join(CONFIG.STORAGE.CACHE_DIR, 'previews'),
631 MAX_AGE: 1000 * 3600 * 3 // 3 hours
634 DIRECTORY: join(CONFIG.STORAGE.CACHE_DIR, 'video-captions'),
635 MAX_AGE: 1000 * 3600 * 3 // 3 hours
638 DIRECTORY: join(CONFIG.STORAGE.CACHE_DIR, 'torrents'),
639 MAX_AGE: 1000 * 3600 * 3 // 3 hours
647 ACTOR_IMAGE_STATIC: {
652 const RESUMABLE_UPLOAD_DIRECTORY = join(CONFIG.STORAGE.TMP_DIR, 'resumable-uploads')
653 const HLS_STREAMING_PLAYLIST_DIRECTORY = join(CONFIG.STORAGE.STREAMING_PLAYLISTS_DIR, 'hls')
654 const HLS_REDUNDANCY_DIRECTORY = join(CONFIG.STORAGE.REDUNDANCY_DIR, 'hls')
658 CLEANUP_DELAY: 1000 * 60 * 5, // 5 minutes
659 SEGMENT_TIME_SECONDS: 4, // 4 seconds
660 SEGMENTS_LIST_SIZE: 15, // 15 maximum segments in live playlist
661 REPLAY_DIRECTORY: 'replay',
662 EDGE_LIVE_DELAY_SEGMENTS_NOTIFICATION: 4,
663 MAX_SOCKET_WAITING_DATA: 1024 * 1000 * 100, // 100MB
673 const MEMOIZE_TTL = {
674 OVERVIEWS_SAMPLE: 1000 * 3600 * 4, // 4 hours
675 INFO_HASH_EXISTS: 1000 * 3600 * 12, // 12 hours
676 LIVE_ABLE_TO_UPLOAD: 1000 * 60, // 1 minute
677 LIVE_CHECK_SOCKET_HEALTH: 1000 * 60 // 1 minute
680 const MEMOIZE_LENGTH = {
681 INFO_HASH_EXISTS: 200
684 const QUEUE_CONCURRENCY = {
685 ACTOR_PROCESS_IMAGE: 3
694 const ACCEPT_HEADERS = [ 'html', 'application/json' ].concat(ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS)
696 const ASSETS_PATH = {
697 DEFAULT_AUDIO_BACKGROUND: join(root(), 'dist', 'server', 'assets', 'default-audio-background.jpg'),
698 DEFAULT_LIVE_BACKGROUND: join(root(), 'dist', 'server', 'assets', 'default-live-background.jpg')
701 // ---------------------------------------------------------------------------
703 const CUSTOM_HTML_TAG_COMMENTS = {
704 TITLE: '<!-- title tag -->',
705 DESCRIPTION: '<!-- description tag -->',
706 CUSTOM_CSS: '<!-- custom css tag -->',
707 META_TAGS: '<!-- meta tags -->',
708 SERVER_CONFIG: '<!-- server config -->'
711 // ---------------------------------------------------------------------------
717 const MAX_LOGS_OUTPUT_CHARACTERS = 10 * 1000 * 1000
718 const LOG_FILENAME = 'peertube.log'
719 const AUDIT_LOG_FILENAME = 'peertube-audit.log'
721 // ---------------------------------------------------------------------------
723 const TRACKER_RATE_LIMITS = {
724 INTERVAL: 60000 * 5, // 5 minutes
725 ANNOUNCES_PER_IP_PER_INFOHASH: 15, // maximum announces per torrent in the interval
726 ANNOUNCES_PER_IP: 30, // maximum announces for all our torrents in the interval
727 BLOCK_IP_LIFETIME: 60000 * 3 // 3 minutes
730 const P2P_MEDIA_LOADER_PEER_VERSION = 2
732 // ---------------------------------------------------------------------------
734 const PLUGIN_GLOBAL_CSS_FILE_NAME = 'plugins-global.css'
735 const PLUGIN_GLOBAL_CSS_PATH = join(CONFIG.STORAGE.TMP_DIR, PLUGIN_GLOBAL_CSS_FILE_NAME)
737 let PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME = 1000 * 60 * 5 // 5 minutes
739 const DEFAULT_THEME_NAME = 'default'
740 const DEFAULT_USER_THEME_NAME = 'instance-default'
742 // ---------------------------------------------------------------------------
744 const SEARCH_INDEX = {
746 VIDEOS: '/api/v1/search/videos',
747 VIDEO_CHANNELS: '/api/v1/search/video-channels'
751 // ---------------------------------------------------------------------------
753 // Special constants for a test instance
754 if (isTestInstance() === true) {
755 PRIVATE_RSA_KEY_SIZE = 1024
757 ACTOR_FOLLOW_SCORE.BASE = 20
759 REMOTE_SCHEME.HTTP = 'http'
760 REMOTE_SCHEME.WS = 'ws'
762 STATIC_MAX_AGE.SERVER = '0'
764 ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE = 2
765 ACTIVITY_PUB.ACTOR_REFRESH_INTERVAL = 10 * 1000 // 10 seconds
766 ACTIVITY_PUB.VIDEO_REFRESH_INTERVAL = 10 * 1000 // 10 seconds
767 ACTIVITY_PUB.VIDEO_PLAYLIST_REFRESH_INTERVAL = 10 * 1000 // 10 seconds
769 CONSTRAINTS_FIELDS.ACTORS.IMAGE.FILE_SIZE.max = 100 * 1024 // 100KB
770 CONSTRAINTS_FIELDS.VIDEOS.IMAGE.FILE_SIZE.max = 400 * 1024 // 400KB
772 SCHEDULER_INTERVALS_MS.actorFollowScores = 1000
773 SCHEDULER_INTERVALS_MS.removeOldJobs = 10000
774 SCHEDULER_INTERVALS_MS.removeOldHistory = 5000
775 SCHEDULER_INTERVALS_MS.removeOldViews = 5000
776 SCHEDULER_INTERVALS_MS.updateVideos = 5000
777 SCHEDULER_INTERVALS_MS.autoFollowIndexInstances = 5000
778 SCHEDULER_INTERVALS_MS.updateInboxStats = 5000
779 SCHEDULER_INTERVALS_MS.checkPeerTubeVersion = 2000
780 REPEAT_JOBS['videos-views'] = { every: 5000 }
781 REPEAT_JOBS['activitypub-cleaner'] = { every: 5000 }
783 REDUNDANCY.VIDEOS.RANDOMIZED_FACTOR = 1
785 VIEW_LIFETIME.VIDEO = 1000 // 1 second
786 VIEW_LIFETIME.LIVE = 1000 * 5 // 5 second
787 CONTACT_FORM_LIFETIME = 1000 // 1 second
789 JOB_ATTEMPTS['email'] = 1
791 FILES_CACHE.VIDEO_CAPTIONS.MAX_AGE = 3000
792 MEMOIZE_TTL.OVERVIEWS_SAMPLE = 3000
793 MEMOIZE_TTL.LIVE_ABLE_TO_UPLOAD = 3000
794 OVERVIEWS.VIDEOS.SAMPLE_THRESHOLD = 2
796 PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME = 5000
798 VIDEO_LIVE.CLEANUP_DELAY = 5000
799 VIDEO_LIVE.SEGMENT_TIME_SECONDS = 2
800 VIDEO_LIVE.EDGE_LIVE_DELAY_SEGMENTS_NOTIFICATION = 1
803 updateWebserverUrls()
804 updateWebserverConfig()
806 registerConfigChangedHandler(() => {
807 updateWebserverUrls()
808 updateWebserverConfig()
811 // ---------------------------------------------------------------------------
813 const FILES_CONTENT_HASH = {
814 MANIFEST: generateContentHash(),
815 FAVICON: generateContentHash(),
816 LOGO: generateContentHash()
819 // ---------------------------------------------------------------------------
828 RESUMABLE_UPLOAD_DIRECTORY,
829 HLS_REDUNDANCY_DIRECTORY,
830 P2P_MEDIA_LOADER_PEER_VERSION,
842 AP_CLEANER_CONCURRENCY,
843 LAST_MIGRATION_VERSION,
845 CUSTOM_HTML_TAG_COMMENTS,
846 BROADCAST_CONCURRENCY,
853 DEFAULT_USER_THEME_NAME,
855 PLUGIN_GLOBAL_CSS_FILE_NAME,
856 PLUGIN_GLOBAL_CSS_PATH,
857 PRIVATE_RSA_KEY_SIZE,
858 ROUTE_CACHE_LIFETIME,
860 HLS_STREAMING_PLAYLIST_DIRECTORY,
867 VIDEO_IMPORT_TIMEOUT,
868 VIDEO_PLAYLIST_TYPES,
869 MAX_LOGS_OUTPUT_CHARACTERS,
871 ACTIVITY_PUB_ACTOR_TYPES,
882 VIDEO_TRANSCODING_FPS,
888 USER_PASSWORD_RESET_LIFETIME,
889 USER_PASSWORD_CREATE_LIFETIME,
891 USER_EMAIL_VERIFY_LIFETIME,
893 SCHEDULER_INTERVALS_MS,
895 STATIC_DOWNLOAD_PATHS,
897 CRAWL_REQUEST_CONCURRENCY,
898 DEFAULT_AUDIO_RESOLUTION,
899 JOB_COMPLETED_LIFETIME,
903 CONTACT_FORM_LIFETIME,
904 VIDEO_PLAYLIST_PRIVACIES,
905 PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME,
913 // ---------------------------------------------------------------------------
915 function buildVideoMimetypeExt () {
917 // streamable formats that warrant cross-browser compatibility
918 'video/webm': '.webm',
919 // We'll add .ogg if additional extensions are enabled
920 // We could add .ogg here but since it could be an audio file,
921 // it would be confusing for users because PeerTube will refuse their file (based on the mimetype)
922 'video/ogg': [ '.ogv' ],
926 if (CONFIG.TRANSCODING.ENABLED) {
927 if (CONFIG.TRANSCODING.ALLOW_ADDITIONAL_EXTENSIONS) {
928 data['video/ogg'].push('.ogg')
930 Object.assign(data, {
931 'video/x-matroska': '.mkv',
933 // Developed by Apple
934 'video/quicktime': [ '.mov', '.qt', '.mqv' ], // often used as output format by editing software
935 'video/x-m4v': '.m4v',
938 // Developed by the Adobe Flash Platform
939 'video/x-flv': '.flv',
940 'video/x-f4v': '.f4v', // replacement for flv
942 // Developed by Microsoft
943 'video/x-ms-wmv': '.wmv',
944 'video/x-msvideo': '.avi',
948 // common video formats for cell phones
949 'video/3gpp': [ '.3gp', '.3gpp' ],
950 'video/3gpp2': [ '.3g2', '.3gpp2' ],
952 // Developed by FFmpeg/Mplayer
953 'application/x-nut': '.nut',
955 // The standard video format used by many Sony and Panasonic HD camcorders.
956 // It is also used for storing high definition video on Blu-ray discs.
957 'video/mp2t': '.mts',
958 'video/m2ts': '.m2ts',
960 // Old formats reliant on MPEG-1/MPEG-2
962 'video/mpeg2': '.m2v',
963 'video/mpeg': [ '.m1v', '.mpg', '.mpe', '.mpeg', '.vob' ],
967 'application/octet-stream': null,
968 'application/mxf': '.mxf' // often used as exchange format by editing software
972 if (CONFIG.TRANSCODING.ALLOW_AUDIO_FILES) {
973 Object.assign(data, MIMETYPES.AUDIO.MIMETYPE_EXT)
980 function updateWebserverUrls () {
981 WEBSERVER.URL = sanitizeUrl(CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT)
982 WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT, REMOTE_SCHEME.HTTP)
983 WEBSERVER.WS = CONFIG.WEBSERVER.WS
985 WEBSERVER.SCHEME = CONFIG.WEBSERVER.SCHEME
986 WEBSERVER.HOSTNAME = CONFIG.WEBSERVER.HOSTNAME
987 WEBSERVER.PORT = CONFIG.WEBSERVER.PORT
989 WEBSERVER.RTMP_URL = 'rtmp://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.LIVE.RTMP.PORT + '/' + VIDEO_LIVE.RTMP.BASE_PATH
992 function updateWebserverConfig () {
993 MIMETYPES.VIDEO.MIMETYPE_EXT = buildVideoMimetypeExt()
994 MIMETYPES.VIDEO.MIMETYPES_REGEX = buildMimetypesRegex(MIMETYPES.VIDEO.MIMETYPE_EXT)
996 ACTIVITY_PUB.URL_MIME_TYPES.VIDEO = Object.keys(MIMETYPES.VIDEO.MIMETYPE_EXT)
998 MIMETYPES.VIDEO.EXT_MIMETYPE = buildVideoExtMimetype(MIMETYPES.VIDEO.MIMETYPE_EXT)
1000 CONSTRAINTS_FIELDS.VIDEOS.EXTNAME = Object.keys(MIMETYPES.VIDEO.EXT_MIMETYPE)
1003 function buildVideoExtMimetype (obj: { [ id: string ]: string | string[] }) {
1004 const result: { [id: string]: string } = {}
1006 for (const mimetype of Object.keys(obj)) {
1007 const value = obj[mimetype]
1008 if (!value) continue
1010 const extensions = Array.isArray(value) ? value : [ value ]
1012 for (const extension of extensions) {
1013 result[extension] = mimetype
1020 function buildMimetypesRegex (obj: { [id: string]: string | string[] }) {
1021 return Object.keys(obj)
1026 function loadLanguages () {
1027 Object.assign(VIDEO_LANGUAGES, buildLanguages())
1030 function buildLanguages () {
1031 const iso639 = require('iso-639-3')
1033 const languages: { [id: string]: string } = {}
1035 const additionalLanguages = {
1036 sgn: true, // Sign languages (macro language)
1037 ase: true, // American sign language
1038 sdl: true, // Arabian sign language
1039 bfi: true, // British sign language
1040 bzs: true, // Brazilian sign language
1041 csl: true, // Chinese sign language
1042 cse: true, // Czech sign language
1043 dsl: true, // Danish sign language
1044 fsl: true, // French sign language
1045 gsg: true, // German sign language
1046 pks: true, // Pakistan sign language
1047 jsl: true, // Japanese sign language
1048 sfs: true, // South African sign language
1049 swl: true, // Swedish sign language
1050 rsl: true, // Russian sign language
1052 kab: true, // Kabyle
1054 epo: true, // Esperanto
1055 tlh: true, // Klingon
1056 jbo: true, // Lojban
1060 // Only add ISO639-1 languages and some sign languages (ISO639-3)
1063 return (l.iso6391 !== undefined && l.type === 'living') ||
1064 additionalLanguages[l.iso6393] === true
1066 .forEach(l => { languages[l.iso6391 || l.iso6393] = l.name })
1068 // Override Occitan label
1069 languages['oc'] = 'Occitan'
1070 languages['el'] = 'Greek'
1075 function generateContentHash () {
1076 return randomBytes(20).toString('hex')