1 import { IConfig } from 'config'
2 import { dirname, join } from 'path'
3 import { JobType, VideoRateType, VideoState, VideosRedundancy } from '../../shared/models'
4 import { ActivityPubActorType } from '../../shared/models/activitypub'
5 import { FollowState } from '../../shared/models/actors'
6 import { VideoAbuseState, VideoImportState, VideoPrivacy, VideoTranscodingFPS } from '../../shared/models/videos'
7 // Do not use barrels, remain constants as independent as possible
8 import { buildPath, isTestInstance, parseDuration, parseBytes, root, sanitizeHost, sanitizeUrl } from '../helpers/core-utils'
9 import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type'
10 import { invert } from 'lodash'
11 import { CronRepeatOptions, EveryRepeatOptions } from 'bull'
12 import * as bytes from 'bytes'
13 import { VideoPlaylistPrivacy } from '../../shared/models/videos/playlist/video-playlist-privacy.model'
14 import { VideoPlaylistType } from '../../shared/models/videos/playlist/video-playlist-type.model'
16 // Use a variable to reload the configuration if we need
17 let config: IConfig = require('config')
19 // ---------------------------------------------------------------------------
21 const LAST_MIGRATION_VERSION = 340
23 // ---------------------------------------------------------------------------
26 const API_VERSION = 'v1'
35 // Sortable columns per schema
36 const SORTABLE_COLUMNS = {
37 USERS: [ 'id', 'username', 'createdAt' ],
38 USER_SUBSCRIPTIONS: [ 'id', 'createdAt' ],
39 ACCOUNTS: [ 'createdAt' ],
40 JOBS: [ 'createdAt' ],
41 VIDEO_ABUSES: [ 'id', 'createdAt', 'state' ],
42 VIDEO_CHANNELS: [ 'id', 'name', 'updatedAt', 'createdAt' ],
43 VIDEO_IMPORTS: [ 'createdAt' ],
44 VIDEO_COMMENT_THREADS: [ 'createdAt' ],
45 BLACKLISTS: [ 'id', 'name', 'duration', 'views', 'likes', 'dislikes', 'uuid', 'createdAt' ],
46 FOLLOWERS: [ 'createdAt' ],
47 FOLLOWING: [ 'createdAt' ],
49 VIDEOS: [ 'name', 'duration', 'createdAt', 'publishedAt', 'views', 'likes', 'trending' ],
51 VIDEOS_SEARCH: [ 'name', 'duration', 'createdAt', 'publishedAt', 'views', 'likes', 'match' ],
52 VIDEO_CHANNELS_SEARCH: [ 'match', 'displayName', 'createdAt' ],
54 ACCOUNTS_BLOCKLIST: [ 'createdAt' ],
55 SERVERS_BLOCKLIST: [ 'createdAt' ],
57 USER_NOTIFICATIONS: [ 'createdAt' ],
59 VIDEO_PLAYLISTS: [ 'createdAt' ]
62 const OAUTH_LIFETIME = {
63 ACCESS_TOKEN: 3600 * 24, // 1 day, for upload
64 REFRESH_TOKEN: 1209600 // 2 weeks
67 const ROUTE_CACHE_LIFETIME = {
71 SECURITYTXT: '2 hours',
72 NODEINFO: '10 minutes',
78 VIDEOS: '1 second' // 1 second, cache concurrent requests after a broadcast for example
83 // ---------------------------------------------------------------------------
85 // Number of points we add/remove after a successful/bad request
86 const ACTOR_FOLLOW_SCORE = {
93 const FOLLOW_STATES: { [ id: string ]: FollowState } = {
98 const REMOTE_SCHEME = {
103 const JOB_ATTEMPTS: { [ id in JobType ]: number } = {
104 'activitypub-http-broadcast': 5,
105 'activitypub-http-unicast': 5,
106 'activitypub-http-fetcher': 5,
107 'activitypub-follow': 5,
108 'video-file-import': 1,
113 'activitypub-refresher': 1
115 const JOB_CONCURRENCY: { [ id in JobType ]: number } = {
116 'activitypub-http-broadcast': 1,
117 'activitypub-http-unicast': 5,
118 'activitypub-http-fetcher': 1,
119 'activitypub-follow': 3,
120 'video-file-import': 1,
125 'activitypub-refresher': 1
127 const JOB_TTL: { [ id in JobType ]: number } = {
128 'activitypub-http-broadcast': 60000 * 10, // 10 minutes
129 'activitypub-http-unicast': 60000 * 10, // 10 minutes
130 'activitypub-http-fetcher': 60000 * 10, // 10 minutes
131 'activitypub-follow': 60000 * 10, // 10 minutes
132 'video-file-import': 1000 * 3600, // 1 hour
133 'video-file': 1000 * 3600 * 48, // 2 days, transcoding could be long
134 'video-import': 1000 * 3600 * 2, // hours
135 'email': 60000 * 10, // 10 minutes
136 'videos-views': undefined, // Unlimited
137 'activitypub-refresher': 60000 * 10 // 10 minutes
139 const REPEAT_JOBS: { [ id: string ]: EveryRepeatOptions | CronRepeatOptions } = {
141 cron: '1 * * * *' // At 1 minute past the hour
145 const BROADCAST_CONCURRENCY = 10 // How many requests in parallel we do in activitypub-http-broadcast job
146 const CRAWL_REQUEST_CONCURRENCY = 1 // How many requests in parallel to fetch remote data (likes, shares...)
147 const JOB_REQUEST_TIMEOUT = 3000 // 3 seconds
148 const JOB_COMPLETED_LIFETIME = 60000 * 60 * 24 * 2 // 2 days
149 const VIDEO_IMPORT_TIMEOUT = 1000 * 3600 // 1 hour
152 let SCHEDULER_INTERVALS_MS = {
153 actorFollowScores: 60000 * 60, // 1 hour
154 removeOldJobs: 60000 * 60, // 1 hour
155 updateVideos: 60000, // 1 minute
156 youtubeDLUpdate: 60000 * 60 * 24 // 1 day
159 // ---------------------------------------------------------------------------
162 CUSTOM_FILE: getLocalConfigFilePath(),
164 PORT: config.get<number>('listen.port'),
165 HOSTNAME: config.get<string>('listen.hostname')
168 DBNAME: 'peertube' + config.get<string>('database.suffix'),
169 HOSTNAME: config.get<string>('database.hostname'),
170 PORT: config.get<number>('database.port'),
171 USERNAME: config.get<string>('database.username'),
172 PASSWORD: config.get<string>('database.password'),
174 MAX: config.get<number>('database.pool.max')
178 HOSTNAME: config.has('redis.hostname') ? config.get<string>('redis.hostname') : null,
179 PORT: config.has('redis.port') ? config.get<number>('redis.port') : null,
180 SOCKET: config.has('redis.socket') ? config.get<string>('redis.socket') : null,
181 AUTH: config.has('redis.auth') ? config.get<string>('redis.auth') : null,
182 DB: config.has('redis.db') ? config.get<number>('redis.db') : null
185 HOSTNAME: config.get<string>('smtp.hostname'),
186 PORT: config.get<number>('smtp.port'),
187 USERNAME: config.get<string>('smtp.username'),
188 PASSWORD: config.get<string>('smtp.password'),
189 TLS: config.get<boolean>('smtp.tls'),
190 DISABLE_STARTTLS: config.get<boolean>('smtp.disable_starttls'),
191 CA_FILE: config.get<string>('smtp.ca_file'),
192 FROM_ADDRESS: config.get<string>('smtp.from_address')
195 TMP_DIR: buildPath(config.get<string>('storage.tmp')),
196 AVATARS_DIR: buildPath(config.get<string>('storage.avatars')),
197 LOG_DIR: buildPath(config.get<string>('storage.logs')),
198 VIDEOS_DIR: buildPath(config.get<string>('storage.videos')),
199 PLAYLISTS_DIR: buildPath(config.get<string>('storage.playlists')),
200 REDUNDANCY_DIR: buildPath(config.get<string>('storage.redundancy')),
201 THUMBNAILS_DIR: buildPath(config.get<string>('storage.thumbnails')),
202 PREVIEWS_DIR: buildPath(config.get<string>('storage.previews')),
203 CAPTIONS_DIR: buildPath(config.get<string>('storage.captions')),
204 TORRENTS_DIR: buildPath(config.get<string>('storage.torrents')),
205 CACHE_DIR: buildPath(config.get<string>('storage.cache'))
208 SCHEME: config.get<boolean>('webserver.https') === true ? 'https' : 'http',
209 WS: config.get<boolean>('webserver.https') === true ? 'wss' : 'ws',
210 HOSTNAME: config.get<string>('webserver.hostname'),
211 PORT: config.get<number>('webserver.port'),
215 TRUST_PROXY: config.get<string[]>('trust_proxy'),
217 LEVEL: config.get<string>('log.level')
221 USERS: config.get<boolean>('search.remote_uri.users'),
222 ANONYMOUS: config.get<boolean>('search.remote_uri.anonymous')
227 INTERVAL_DAYS: config.get<number>('trending.videos.interval_days')
232 CHECK_INTERVAL: parseDuration(config.get<string>('redundancy.videos.check_interval')),
233 STRATEGIES: buildVideosRedundancy(config.get<any[]>('redundancy.videos.strategies'))
237 ENABLED: config.get<boolean>('csp.enabled'),
238 REPORT_ONLY: config.get<boolean>('csp.report_only'),
239 REPORT_URI: config.get<boolean>('csp.report_uri')
242 get EMAIL () { return config.get<string>('admin.email') }
245 get ENABLED () { return config.get<boolean>('contact_form.enabled') }
248 get ENABLED () { return config.get<boolean>('signup.enabled') },
249 get LIMIT () { return config.get<number>('signup.limit') },
250 get REQUIRES_EMAIL_VERIFICATION () { return config.get<boolean>('signup.requires_email_verification') },
253 get WHITELIST () { return config.get<string[]>('signup.filters.cidr.whitelist') },
254 get BLACKLIST () { return config.get<string[]>('signup.filters.cidr.blacklist') }
259 get VIDEO_QUOTA () { return parseBytes(config.get<number>('user.video_quota')) },
260 get VIDEO_QUOTA_DAILY () { return parseBytes(config.get<number>('user.video_quota_daily')) }
263 get ENABLED () { return config.get<boolean>('transcoding.enabled') },
264 get ALLOW_ADDITIONAL_EXTENSIONS () { return config.get<boolean>('transcoding.allow_additional_extensions') },
265 get THREADS () { return config.get<number>('transcoding.threads') },
267 get '240p' () { return config.get<boolean>('transcoding.resolutions.240p') },
268 get '360p' () { return config.get<boolean>('transcoding.resolutions.360p') },
269 get '480p' () { return config.get<boolean>('transcoding.resolutions.480p') },
270 get '720p' () { return config.get<boolean>('transcoding.resolutions.720p') },
271 get '1080p' () { return config.get<boolean>('transcoding.resolutions.1080p') }
274 get ENABLED () { return config.get<boolean>('transcoding.hls.enabled') }
280 get ENABLED () { return config.get<boolean>('import.videos.http.enabled') }
283 get ENABLED () { return config.get<boolean>('import.videos.torrent.enabled') }
289 get SIZE () { return config.get<number>('cache.previews.size') }
292 get SIZE () { return config.get<number>('cache.captions.size') }
296 get NAME () { return config.get<string>('instance.name') },
297 get SHORT_DESCRIPTION () { return config.get<string>('instance.short_description') },
298 get DESCRIPTION () { return config.get<string>('instance.description') },
299 get TERMS () { return config.get<string>('instance.terms') },
300 get IS_NSFW () { return config.get<boolean>('instance.is_nsfw') },
301 get DEFAULT_CLIENT_ROUTE () { return config.get<string>('instance.default_client_route') },
302 get DEFAULT_NSFW_POLICY () { return config.get<NSFWPolicyType>('instance.default_nsfw_policy') },
304 get JAVASCRIPT () { return config.get<string>('instance.customizations.javascript') },
305 get CSS () { return config.get<string>('instance.customizations.css') }
307 get ROBOTS () { return config.get<string>('instance.robots') },
308 get SECURITYTXT () { return config.get<string>('instance.securitytxt') },
309 get SECURITYTXT_CONTACT () { return config.get<string>('admin.email') }
313 get USERNAME () { return config.get<string>('services.twitter.username') },
314 get WHITELISTED () { return config.get<boolean>('services.twitter.whitelisted') }
319 // ---------------------------------------------------------------------------
321 let CONSTRAINTS_FIELDS = {
323 NAME: { min: 1, max: 120 }, // Length
324 DESCRIPTION: { min: 3, max: 1000 }, // Length
325 USERNAME: { min: 1, max: 50 }, // Length
326 PASSWORD: { min: 6, max: 255 }, // Length
327 VIDEO_QUOTA: { min: -1 },
328 VIDEO_QUOTA_DAILY: { min: -1 },
329 BLOCKED_REASON: { min: 3, max: 250 } // Length
332 REASON: { min: 2, max: 3000 }, // Length
333 MODERATION_COMMENT: { min: 2, max: 3000 } // Length
336 REASON: { min: 2, max: 300 } // Length
339 NAME: { min: 1, max: 120 }, // Length
340 DESCRIPTION: { min: 3, max: 1000 }, // Length
341 SUPPORT: { min: 3, max: 1000 }, // Length
342 URL: { min: 3, max: 2000 } // Length
346 EXTNAME: [ '.vtt', '.srt' ],
348 max: 2 * 1024 * 1024 // 2MB
353 URL: { min: 3, max: 2000 }, // Length
354 TORRENT_NAME: { min: 3, max: 255 }, // Length
356 EXTNAME: [ '.torrent' ],
358 max: 1024 * 200 // 200 KB
363 URL: { min: 3, max: 2000 } // Length
366 URL: { min: 3, max: 2000 } // Length
369 NAME: { min: 3, max: 120 }, // Length
370 LANGUAGE: { min: 1, max: 10 }, // Length
371 TRUNCATED_DESCRIPTION: { min: 3, max: 250 }, // Length
372 DESCRIPTION: { min: 3, max: 10000 }, // Length
373 SUPPORT: { min: 3, max: 1000 }, // Length
375 EXTNAME: [ '.jpg', '.jpeg' ],
377 max: 2 * 1024 * 1024 // 2MB
380 EXTNAME: buildVideosExtname(),
381 INFO_HASH: { min: 40, max: 40 }, // Length, info hash is 20 bytes length but we represent it in hexadecimal so 20 * 2
382 DURATION: { min: 0 }, // Number
383 TAGS: { min: 0, max: 5 }, // Number of total tags
384 TAG: { min: 2, max: 30 }, // Length
385 THUMBNAIL: { min: 2, max: 30 },
386 THUMBNAIL_DATA: { min: 0, max: 20000 }, // Bytes
389 DISLIKES: { min: 0 },
390 FILE_SIZE: { min: 10 },
391 URL: { min: 3, max: 2000 } // Length
394 NAME: { min: 1, max: 120 }, // Length
395 DESCRIPTION: { min: 3, max: 1000 }, // Length
396 URL: { min: 3, max: 2000 }, // Length
398 EXTNAME: [ '.jpg', '.jpeg' ],
400 max: 2 * 1024 * 1024 // 2MB
405 PUBLIC_KEY: { min: 10, max: 5000 }, // Length
406 PRIVATE_KEY: { min: 10, max: 5000 }, // Length
407 URL: { min: 3, max: 2000 }, // Length
409 EXTNAME: [ '.png', '.jpeg', '.jpg' ],
411 max: 2 * 1024 * 1024 // 2MB
419 TEXT: { min: 1, max: 3000 }, // Length
420 URL: { min: 3, max: 2000 } // Length
423 URL: { min: 3, max: 2000 } // Length
426 FROM_NAME: { min: 1, max: 120 }, // Length
427 BODY: { min: 3, max: 5000 } // Length
431 const RATES_LIMIT = {
433 WINDOW_MS: 5 * 60 * 1000, // 5 minutes
434 MAX: 15 // 15 attempts
437 WINDOW_MS: 5 * 60 * 1000, // 5 minutes
442 let VIDEO_VIEW_LIFETIME = 60000 * 60 // 1 hour
443 let CONTACT_FORM_LIFETIME = 60000 * 60 // 1 hour
445 const VIDEO_TRANSCODING_FPS: VideoTranscodingFPS = {
449 KEEP_ORIGIN_FPS_RESOLUTION_MIN: 720 // We keep the original FPS on high resolutions (720 minimum)
452 const VIDEO_RATE_TYPES: { [ id: string ]: VideoRateType } = {
457 const FFMPEG_NICE: { [ id: string ]: number } = {
458 THUMBNAIL: 2, // 2 just for don't blocking servers
462 const VIDEO_CATEGORIES = {
473 11: 'News & Politics',
477 15: 'Science & Technology',
483 // See https://creativecommons.org/licenses/?lang=en
484 const VIDEO_LICENCES = {
486 2: 'Attribution - Share Alike',
487 3: 'Attribution - No Derivatives',
488 4: 'Attribution - Non Commercial',
489 5: 'Attribution - Non Commercial - Share Alike',
490 6: 'Attribution - Non Commercial - No Derivatives',
491 7: 'Public Domain Dedication'
494 const VIDEO_LANGUAGES = buildLanguages()
496 const VIDEO_PRIVACIES = {
497 [VideoPrivacy.PUBLIC]: 'Public',
498 [VideoPrivacy.UNLISTED]: 'Unlisted',
499 [VideoPrivacy.PRIVATE]: 'Private'
502 const VIDEO_STATES = {
503 [VideoState.PUBLISHED]: 'Published',
504 [VideoState.TO_TRANSCODE]: 'To transcode',
505 [VideoState.TO_IMPORT]: 'To import'
508 const VIDEO_IMPORT_STATES = {
509 [VideoImportState.FAILED]: 'Failed',
510 [VideoImportState.PENDING]: 'Pending',
511 [VideoImportState.SUCCESS]: 'Success'
514 const VIDEO_ABUSE_STATES = {
515 [VideoAbuseState.PENDING]: 'Pending',
516 [VideoAbuseState.REJECTED]: 'Rejected',
517 [VideoAbuseState.ACCEPTED]: 'Accepted'
520 const VIDEO_PLAYLIST_PRIVACIES = {
521 [VideoPlaylistPrivacy.PUBLIC]: 'Public',
522 [VideoPlaylistPrivacy.UNLISTED]: 'Unlisted',
523 [VideoPlaylistPrivacy.PRIVATE]: 'Private'
526 const VIDEO_PLAYLIST_TYPES = {
527 [VideoPlaylistType.REGULAR]: 'Regular',
528 [VideoPlaylistType.WATCH_LATER]: 'Watch later'
533 MIMETYPE_EXT: buildVideoMimetypeExt(),
534 EXT_MIMETYPE: null as { [ id: string ]: string }
546 'application/x-subrip': '.srt'
551 'application/x-bittorrent': '.torrent'
555 MIMETYPES.VIDEO.EXT_MIMETYPE = invert(MIMETYPES.VIDEO.MIMETYPE_EXT)
557 // ---------------------------------------------------------------------------
566 // ---------------------------------------------------------------------------
568 const SERVER_ACTOR_NAME = 'peertube'
570 const ACTIVITY_PUB = {
571 POTENTIAL_ACCEPT_HEADERS: [
572 'application/activity+json',
573 'application/ld+json',
574 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
576 ACCEPT_HEADER: 'application/activity+json, application/ld+json',
577 PUBLIC: 'https://www.w3.org/ns/activitystreams#Public',
578 COLLECTION_ITEMS_PER_PAGE: 10,
579 FETCH_PAGE_LIMIT: 100,
581 VIDEO: Object.keys(MIMETYPES.VIDEO.MIMETYPE_EXT),
582 TORRENT: [ 'application/x-bittorrent' ],
583 MAGNET: [ 'application/x-bittorrent;x-scheme-handler/magnet' ]
585 MAX_RECURSION_COMMENTS: 100,
586 ACTOR_REFRESH_INTERVAL: 3600 * 24 * 1000, // 1 day
587 VIDEO_REFRESH_INTERVAL: 3600 * 24 * 1000 // 1 day
590 const ACTIVITY_PUB_ACTOR_TYPES: { [ id: string ]: ActivityPubActorType } = {
593 APPLICATION: 'Application'
596 const HTTP_SIGNATURE = {
597 HEADER_NAME: 'signature',
598 ALGORITHM: 'rsa-sha256',
599 HEADERS_TO_SIGN: [ '(request-target)', 'host', 'date', 'digest' ]
602 // ---------------------------------------------------------------------------
604 let PRIVATE_RSA_KEY_SIZE = 2048
606 // Password encryption
607 const BCRYPT_SALT_SIZE = 10
609 const USER_PASSWORD_RESET_LIFETIME = 60000 * 5 // 5 minutes
611 const USER_EMAIL_VERIFY_LIFETIME = 60000 * 60 // 60 minutes
613 const NSFW_POLICY_TYPES: { [ id: string]: NSFWPolicyType } = {
614 DO_NOT_LIST: 'do_not_list',
619 // ---------------------------------------------------------------------------
621 // Express static paths (router)
622 const STATIC_PATHS = {
623 PREVIEWS: '/static/previews/',
624 THUMBNAILS: '/static/thumbnails/',
625 TORRENTS: '/static/torrents/',
626 WEBSEED: '/static/webseed/',
627 REDUNDANCY: '/static/redundancy/',
629 HLS: '/static/playlists/hls'
631 AVATARS: '/static/avatars/',
632 VIDEO_CAPTIONS: '/static/video-captions/'
634 const STATIC_DOWNLOAD_PATHS = {
635 TORRENTS: '/download/torrents/',
636 VIDEOS: '/download/videos/'
640 let STATIC_MAX_AGE = '2h'
642 // Videos thumbnail size
643 const THUMBNAILS_SIZE = {
647 const PREVIEWS_SIZE = {
651 const AVATARS_SIZE = {
661 // Sub folders of cache directory
664 DIRECTORY: join(CONFIG.STORAGE.CACHE_DIR, 'previews'),
665 MAX_AGE: 1000 * 3600 * 3 // 3 hours
668 DIRECTORY: join(CONFIG.STORAGE.CACHE_DIR, 'video-captions'),
669 MAX_AGE: 1000 * 3600 * 3 // 3 hours
673 const HLS_PLAYLIST_DIRECTORY = join(CONFIG.STORAGE.PLAYLISTS_DIR, 'hls')
674 const HLS_REDUNDANCY_DIRECTORY = join(CONFIG.STORAGE.REDUNDANCY_DIR, 'hls')
676 const MEMOIZE_TTL = {
677 OVERVIEWS_SAMPLE: 1000 * 3600 * 4 // 4 hours
686 const ACCEPT_HEADERS = [ 'html', 'application/json' ].concat(ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS)
688 // ---------------------------------------------------------------------------
690 const CUSTOM_HTML_TAG_COMMENTS = {
691 TITLE: '<!-- title tag -->',
692 DESCRIPTION: '<!-- description tag -->',
693 CUSTOM_CSS: '<!-- custom css tag -->',
694 META_TAGS: '<!-- meta tags -->'
697 // ---------------------------------------------------------------------------
703 // ---------------------------------------------------------------------------
705 const TRACKER_RATE_LIMITS = {
706 INTERVAL: 60000 * 5, // 5 minutes
707 ANNOUNCES_PER_IP_PER_INFOHASH: 15, // maximum announces per torrent in the interval
708 ANNOUNCES_PER_IP: 30 // maximum announces for all our torrents in the interval
711 // ---------------------------------------------------------------------------
713 // Special constants for a test instance
714 if (isTestInstance() === true) {
715 PRIVATE_RSA_KEY_SIZE = 1024
717 ACTOR_FOLLOW_SCORE.BASE = 20
719 REMOTE_SCHEME.HTTP = 'http'
720 REMOTE_SCHEME.WS = 'ws'
724 ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE = 2
725 ACTIVITY_PUB.ACTOR_REFRESH_INTERVAL = 10 * 1000 // 10 seconds
726 ACTIVITY_PUB.VIDEO_REFRESH_INTERVAL = 10 * 1000 // 10 seconds
728 CONSTRAINTS_FIELDS.ACTORS.AVATAR.FILE_SIZE.max = 100 * 1024 // 100KB
730 SCHEDULER_INTERVALS_MS.actorFollowScores = 1000
731 SCHEDULER_INTERVALS_MS.removeOldJobs = 10000
732 SCHEDULER_INTERVALS_MS.updateVideos = 5000
733 REPEAT_JOBS['videos-views'] = { every: 5000 }
735 REDUNDANCY.VIDEOS.RANDOMIZED_FACTOR = 1
737 VIDEO_VIEW_LIFETIME = 1000 // 1 second
738 CONTACT_FORM_LIFETIME = 1000 // 1 second
740 JOB_ATTEMPTS['email'] = 1
742 CACHE.VIDEO_CAPTIONS.MAX_AGE = 3000
743 MEMOIZE_TTL.OVERVIEWS_SAMPLE = 1
744 ROUTE_CACHE_LIFETIME.OVERVIEWS.VIDEOS = '0ms'
746 RATES_LIMIT.LOGIN.MAX = 20
749 updateWebserverUrls()
751 // ---------------------------------------------------------------------------
755 HLS_REDUNDANCY_DIRECTORY,
767 LAST_MIGRATION_VERSION,
769 CUSTOM_HTML_TAG_COMMENTS,
770 BROADCAST_CONCURRENCY,
777 PRIVATE_RSA_KEY_SIZE,
778 ROUTE_CACHE_LIFETIME,
780 HLS_PLAYLIST_DIRECTORY,
786 VIDEO_IMPORT_TIMEOUT,
787 VIDEO_PLAYLIST_TYPES,
789 ACTIVITY_PUB_ACTOR_TYPES,
797 VIDEO_TRANSCODING_FPS,
801 USER_PASSWORD_RESET_LIFETIME,
803 USER_EMAIL_VERIFY_LIFETIME,
805 SCHEDULER_INTERVALS_MS,
807 STATIC_DOWNLOAD_PATHS,
810 CRAWL_REQUEST_CONCURRENCY,
811 JOB_COMPLETED_LIFETIME,
815 CONTACT_FORM_LIFETIME,
816 VIDEO_PLAYLIST_PRIVACIES,
820 // ---------------------------------------------------------------------------
822 function getLocalConfigFilePath () {
823 const configSources = config.util.getConfigSources()
824 if (configSources.length === 0) throw new Error('Invalid config source.')
826 let filename = 'local'
827 if (process.env.NODE_ENV) filename += `-${process.env.NODE_ENV}`
828 if (process.env.NODE_APP_INSTANCE) filename += `-${process.env.NODE_APP_INSTANCE}`
830 return join(dirname(configSources[ 0 ].name), filename + '.json')
833 function buildVideoMimetypeExt () {
835 'video/webm': '.webm',
840 if (CONFIG.TRANSCODING.ENABLED && CONFIG.TRANSCODING.ALLOW_ADDITIONAL_EXTENSIONS) {
841 Object.assign(data, {
842 'video/quicktime': '.mov',
843 'video/x-msvideo': '.avi',
844 'video/x-flv': '.flv',
845 'video/x-matroska': '.mkv',
846 'application/octet-stream': '.mkv',
854 function updateWebserverUrls () {
855 CONFIG.WEBSERVER.URL = sanitizeUrl(CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT)
856 CONFIG.WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT, REMOTE_SCHEME.HTTP)
859 function updateWebserverConfig () {
860 CONSTRAINTS_FIELDS.VIDEOS.EXTNAME = buildVideosExtname()
862 MIMETYPES.VIDEO.MIMETYPE_EXT = buildVideoMimetypeExt()
863 MIMETYPES.VIDEO.EXT_MIMETYPE = invert(MIMETYPES.VIDEO.MIMETYPE_EXT)
866 function buildVideosExtname () {
867 return CONFIG.TRANSCODING.ENABLED && CONFIG.TRANSCODING.ALLOW_ADDITIONAL_EXTENSIONS
868 ? [ '.mp4', '.ogv', '.webm', '.mkv', '.mov', '.avi', '.flv' ]
869 : [ '.mp4', '.ogv', '.webm' ]
872 function buildVideosRedundancy (objs: any[]): VideosRedundancy[] {
875 return objs.map(obj => {
876 return Object.assign({}, obj, {
877 minLifetime: parseDuration(obj.min_lifetime),
878 size: bytes.parse(obj.size),
879 minViews: obj.min_views
884 function buildLanguages () {
885 const iso639 = require('iso-639-3')
887 const languages: { [ id: string ]: string } = {}
889 const additionalLanguages = {
890 'sgn': true, // Sign languages (macro language)
891 'ase': true, // American sign language
892 'sdl': true, // Arabian sign language
893 'bfi': true, // British sign language
894 'bzs': true, // Brazilian sign language
895 'csl': true, // Chinese sign language
896 'cse': true, // Czech sign language
897 'dsl': true, // Danish sign language
898 'fsl': true, // French sign language
899 'gsg': true, // German sign language
900 'pks': true, // Pakistan sign language
901 'jsl': true, // Japanese sign language
902 'sfs': true, // South African sign language
903 'swl': true, // Swedish sign language
904 'rsl': true, // Russian sign language: true
906 'epo': true, // Esperanto
907 'tlh': true, // Klingon
908 'jbo': true, // Lojban
909 'avk': true // Kotava
912 // Only add ISO639-1 languages and some sign languages (ISO639-3)
915 return (l.iso6391 !== null && l.type === 'living') ||
916 additionalLanguages[l.iso6393] === true
918 .forEach(l => languages[l.iso6391 || l.iso6393] = l.name)
920 // Override Occitan label
921 languages['oc'] = 'Occitan'
926 export function reloadConfig () {
928 function directory () {
929 if (process.env.NODE_CONFIG_DIR) {
930 return process.env.NODE_CONFIG_DIR
933 return join(root(), 'config')
937 for (const fileName in require.cache) {
938 if (-1 === fileName.indexOf(directory())) {
942 delete require.cache[fileName]
945 delete require.cache[require.resolve('config')]
950 config = require('config')
952 updateWebserverConfig()
953 updateWebserverUrls()