]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/initializers/constants.ts
Merge branch 'release/4.2.0' into develop
[github/Chocobozzz/PeerTube.git] / server / initializers / constants.ts
CommitLineData
0223291c 1import { CronRepeatOptions, EveryRepeatOptions } from 'bull'
adbf1ed8 2import { randomBytes } from 'crypto'
0223291c 3import { invert } from 'lodash'
6dd9de95 4import { join } from 'path'
c55e3d72 5import { randomInt, root } from '@shared/core-utils'
d95d1559
C
6import {
7 AbuseState,
0223291c 8 JobType,
d95d1559
C
9 VideoImportState,
10 VideoPrivacy,
d95d1559
C
11 VideoRateType,
12 VideoResolution,
0223291c
C
13 VideoState,
14 VideoTranscodingFPS
d95d1559 15} from '../../shared/models'
0223291c 16import { ActivityPubActorType } from '../../shared/models/activitypub'
d0800f76 17import { ActorImageType, FollowState } from '../../shared/models/actors'
0883b324 18import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type'
418d092a 19import { VideoPlaylistPrivacy } from '../../shared/models/videos/playlist/video-playlist-privacy.model'
df0b219d 20import { VideoPlaylistType } from '../../shared/models/videos/playlist/video-playlist-type.model'
0223291c 21// Do not use barrels, remain constants as independent as possible
f1569117 22import { isTestInstance, parseDurationToMs, sanitizeHost, sanitizeUrl } from '../helpers/core-utils'
6dd9de95 23import { CONFIG, registerConfigChangedHandler } from './config'
ee9e7b61 24
9f6bae3a
C
25// ---------------------------------------------------------------------------
26
2e401e85 27const LAST_MIGRATION_VERSION = 715
5804c0db
C
28
29// ---------------------------------------------------------------------------
30
f0f5567b 31const API_VERSION = 'v1'
db4b15f2 32const PEERTUBE_VERSION: string = require(join(root(), 'package.json')).version
9f10b292 33
1194e8b4 34const PAGINATION = {
e0b56b74
C
35 GLOBAL: {
36 COUNT: {
37 DEFAULT: 15,
38 MAX: 100
39 }
40 },
41 OUTBOX: {
42 COUNT: {
43 MAX: 50
44 }
1194e8b4
C
45 }
46}
9f6bae3a 47
6dd9de95
C
48const WEBSERVER = {
49 URL: '',
50 HOST: '',
51 SCHEME: '',
52 WS: '',
53 HOSTNAME: '',
c6c0fa6c 54 PORT: 0,
df1db951
C
55 RTMP_URL: '',
56 RTMPS_URL: ''
6dd9de95
C
57}
58
9f6bae3a
C
59// Sortable columns per schema
60const SORTABLE_COLUMNS = {
87a0cac6 61 ADMIN_USERS: [ 'id', 'username', 'videoQuotaUsed', 'createdAt', 'lastLoginDate', 'role' ],
06a05d5f 62 USER_SUBSCRIPTIONS: [ 'id', 'createdAt' ],
265ba139 63 ACCOUNTS: [ 'createdAt' ],
94a5ff8a 64 JOBS: [ 'createdAt' ],
72c7248b 65 VIDEO_CHANNELS: [ 'id', 'name', 'updatedAt', 'createdAt' ],
ed31c059 66 VIDEO_IMPORTS: [ 'createdAt' ],
0f8d00e3 67
c1125bca 68 VIDEO_COMMENT_THREADS: [ 'createdAt', 'totalReplies' ],
0f8d00e3
C
69 VIDEO_COMMENTS: [ 'createdAt' ],
70
c100a614 71 VIDEO_RATES: [ 'createdAt' ],
7a7724e6 72 BLACKLISTS: [ 'id', 'name', 'duration', 'views', 'likes', 'dislikes', 'uuid', 'createdAt' ],
4beda9e1 73
9593a78a
C
74 INSTANCE_FOLLOWERS: [ 'createdAt', 'state', 'score' ],
75 INSTANCE_FOLLOWING: [ 'createdAt', 'redundancyAllowed', 'state' ],
4beda9e1
C
76 ACCOUNT_FOLLOWERS: [ 'createdAt' ],
77 CHANNEL_FOLLOWERS: [ 'createdAt' ],
57c36b27 78
3d4e112d 79 VIDEOS: [ 'name', 'duration', 'createdAt', 'publishedAt', 'originallyPublishedAt', 'views', 'likes', 'trending', 'hot', 'best' ],
9a629c6e 80
5fb2e288 81 // Don't forget to update peertube-search-index with the same values
2fd59d7d 82 VIDEOS_SEARCH: [ 'name', 'duration', 'createdAt', 'publishedAt', 'originallyPublishedAt', 'views', 'likes', 'match' ],
7ad9b984 83 VIDEO_CHANNELS_SEARCH: [ 'match', 'displayName', 'createdAt' ],
37a44fc9 84 VIDEO_PLAYLISTS_SEARCH: [ 'match', 'displayName', 'createdAt' ],
7ad9b984 85
d95d1559
C
86 ABUSES: [ 'id', 'createdAt', 'state' ],
87
7ad9b984 88 ACCOUNTS_BLOCKLIST: [ 'createdAt' ],
cef534ed
C
89 SERVERS_BLOCKLIST: [ 'createdAt' ],
90
654a188f 91 USER_NOTIFICATIONS: [ 'createdAt', 'read' ],
418d092a 92
49cff3a4 93 VIDEO_PLAYLISTS: [ 'name', 'displayName', 'createdAt', 'updatedAt' ],
ad91e700 94
6702a1b2
C
95 PLUGINS: [ 'name', 'createdAt', 'updatedAt' ],
96
b764380a
C
97 AVAILABLE_PLUGINS: [ 'npmName', 'popularity' ],
98
99 VIDEO_REDUNDANCIES: [ 'name' ]
9f6bae3a 100}
9f10b292 101
2f372a86 102const OAUTH_LIFETIME = {
ff193d5e 103 ACCESS_TOKEN: 3600 * 24, // 1 day, for upload
2f372a86
C
104 REFRESH_TOKEN: 1209600 // 2 weeks
105}
106
fd4484f1 107const ROUTE_CACHE_LIFETIME = {
3f6d68d9
RK
108 FEEDS: '15 minutes',
109 ROBOTS: '2 hours',
2feebf3e 110 SITEMAP: '1 day',
5447516b 111 SECURITYTXT: '2 hours',
3f6d68d9 112 NODEINFO: '10 minutes',
aad0ec24 113 DNT_POLICY: '1 week',
fd4484f1 114 ACTIVITY_PUB: {
3f6d68d9 115 VIDEOS: '1 second' // 1 second, cache concurrent requests after a broadcast for example
4b5384f6
C
116 },
117 STATS: '4 hours'
fd4484f1
C
118}
119
9f6bae3a 120// ---------------------------------------------------------------------------
26d7d31b 121
60650c77
C
122// Number of points we add/remove after a successful/bad request
123const ACTOR_FOLLOW_SCORE = {
225a89c2
C
124 PENALTY: -10,
125 BONUS: 10,
60650c77
C
126 BASE: 1000,
127 MAX: 10000
225a89c2
C
128}
129
130const FOLLOW_STATES: { [ id: string ]: FollowState } = {
131 PENDING: 'pending',
132 ACCEPTED: 'accepted'
133}
134
135const REMOTE_SCHEME = {
136 HTTP: 'https',
137 WS: 'wss'
138}
139
b764380a 140const JOB_ATTEMPTS: { [id in JobType]: number } = {
9db437c8 141 'activitypub-http-broadcast': 1,
f27b7a75 142 'activitypub-http-broadcast-parallel': 1,
9db437c8
C
143 'activitypub-http-unicast': 1,
144 'activitypub-http-fetcher': 2,
5350fd8e 145 'activitypub-follow': 5,
74d249bc 146 'activitypub-cleaner': 1,
0138af92 147 'video-file-import': 1,
a0327eed 148 'video-transcoding': 1,
fbad87b0 149 'video-import': 1,
6b616860 150 'email': 5,
8795d6f2 151 'actor-keys': 3,
51353d9a 152 'videos-views-stats': 1,
b764380a 153 'activitypub-refresher': 1,
a5cf76af 154 'video-redundancy': 1,
0305db28 155 'video-live-ending': 1,
92e66e04 156 'video-studio-edition': 1,
f012319a 157 'manage-video-torrent': 1,
0305db28 158 'move-to-object-storage': 3
225a89c2 159}
74d249bc
C
160// Excluded keys are jobs that can be configured by admins
161const JOB_CONCURRENCY: { [id in Exclude<JobType, 'video-transcoding' | 'video-import'>]: number } = {
94a5ff8a 162 'activitypub-http-broadcast': 1,
f27b7a75 163 'activitypub-http-broadcast-parallel': 30,
9db437c8 164 'activitypub-http-unicast': 10,
60520c7c 165 'activitypub-http-fetcher': 3,
74d249bc 166 'activitypub-cleaner': 1,
ab4d4db4 167 'activitypub-follow': 1,
0138af92 168 'video-file-import': 1,
6b616860 169 'email': 5,
8795d6f2 170 'actor-keys': 1,
51353d9a 171 'videos-views-stats': 1,
b764380a 172 'activitypub-refresher': 1,
a5cf76af 173 'video-redundancy': 1,
0305db28 174 'video-live-ending': 10,
92e66e04 175 'video-studio-edition': 1,
f012319a 176 'manage-video-torrent': 1,
0305db28 177 'move-to-object-storage': 1
225a89c2 178}
b764380a 179const JOB_TTL: { [id in JobType]: number } = {
2b86fe72 180 'activitypub-http-broadcast': 60000 * 10, // 10 minutes
f27b7a75 181 'activitypub-http-broadcast-parallel': 60000 * 10, // 10 minutes
2b86fe72 182 'activitypub-http-unicast': 60000 * 10, // 10 minutes
d694b193 183 'activitypub-http-fetcher': 1000 * 3600 * 10, // 10 hours
2b86fe72 184 'activitypub-follow': 60000 * 10, // 10 minutes
74d249bc 185 'activitypub-cleaner': 1000 * 3600, // 1 hour
2b86fe72 186 'video-file-import': 1000 * 3600, // 1 hour
a0327eed 187 'video-transcoding': 1000 * 3600 * 48, // 2 days, transcoding could be long
92e66e04 188 'video-studio-edition': 1000 * 3600 * 10, // 10 hours
3eba7ab8 189 'video-import': CONFIG.IMPORT.VIDEOS.TIMEOUT,
6b616860 190 'email': 60000 * 10, // 10 minutes
8795d6f2 191 'actor-keys': 60000 * 20, // 20 minutes
51353d9a 192 'videos-views-stats': undefined, // Unlimited
b764380a 193 'activitypub-refresher': 60000 * 10, // 10 minutes
a5cf76af 194 'video-redundancy': 1000 * 3600 * 3, // 3 hours
0305db28 195 'video-live-ending': 1000 * 60 * 10, // 10 minutes
f012319a 196 'manage-video-torrent': 1000 * 3600 * 3, // 3 hours
0305db28 197 'move-to-object-storage': 1000 * 60 * 60 * 3 // 3 hours
2b86fe72 198}
51353d9a
C
199const REPEAT_JOBS: { [ id in JobType ]?: EveryRepeatOptions | CronRepeatOptions } = {
200 'videos-views-stats': {
0223291c 201 cron: randomInt(1, 20) + ' * * * *' // Between 1-20 minutes past the hour
74d249bc
C
202 },
203 'activitypub-cleaner': {
204 cron: '30 5 * * ' + randomInt(0, 7) // 1 time per week (random day) at 5:30 AM
6b616860
C
205 }
206}
77d7e851 207const JOB_PRIORITY = {
a6e37eeb 208 TRANSCODING: 100
77d7e851 209}
6b616860 210
67bd004d 211const BROADCAST_CONCURRENCY = 30 // How many requests in parallel we do in activitypub-http-broadcast job
240085d0 212const CRAWL_REQUEST_CONCURRENCY = 1 // How many requests in parallel to fetch remote data (likes, shares...)
f1569117
C
213
214const AP_CLEANER = {
215 CONCURRENCY: 10, // How many requests in parallel we do in activitypub-cleaner job
7a4fd56c 216 UNAVAILABLE_TRESHOLD: 3, // How many attempts we do before removing an unavailable remote resource
f1569117
C
217 PERIOD: parseDurationToMs('1 week') // /!\ Has to be sync with REPEAT_JOBS
218}
219
4c99953a
C
220const REQUEST_TIMEOUTS = {
221 DEFAULT: 7000, // 7 seconds
222 FILE: 30000, // 30 seconds
223 REDUNDANCY: JOB_TTL['video-redundancy']
224}
225
71e3dfda 226const JOB_COMPLETED_LIFETIME = 60000 * 60 * 24 * 2 // 2 days
7630e1c8 227const VIDEO_IMPORT_TIMEOUT = Math.floor(JOB_TTL['video-import'] * 0.9)
225a89c2 228
8f0bc73d 229const SCHEDULER_INTERVALS_MS = {
61953742
C
230 ACTOR_FOLLOW_SCORES: 60000 * 60, // 1 hour
231 REMOVE_OLD_JOBS: 60000 * 60, // 1 hour
232 UPDATE_VIDEOS: 60000, // 1 minute
233 YOUTUBE_DL_UPDATE: 60000 * 60 * 24, // 1 day
b2111066 234 GEO_IP_UPDATE: 60000 * 60 * 24, // 1 day
51353d9a 235 VIDEO_VIEWS_BUFFER_UPDATE: CONFIG.VIEWS.VIDEOS.LOCAL_BUFFER_UPDATE_INTERVAL,
61953742
C
236 CHECK_PLUGINS: CONFIG.PLUGINS.INDEX.CHECK_LATEST_VERSIONS_INTERVAL,
237 CHECK_PEERTUBE_VERSION: 60000 * 60 * 24, // 1 day
238 AUTO_FOLLOW_INDEX_INSTANCES: 60000 * 60 * 24, // 1 day
239 REMOVE_OLD_VIEWS: 60000 * 60 * 24, // 1 day
240 REMOVE_OLD_HISTORY: 60000 * 60 * 24, // 1 day
241 UPDATE_INBOX_STATS: 1000 * 60, // 1 minute
6d472b40 242 REMOVE_DANGLING_RESUMABLE_UPLOADS: 60000 * 60 // 1 hour
2baea0c7 243}
60650c77 244
225a89c2
C
245// ---------------------------------------------------------------------------
246
503c6f44 247const CONSTRAINTS_FIELDS = {
e4c55619 248 USERS: {
9f7a1953 249 NAME: { min: 1, max: 120 }, // Length
d23e6a1c 250 DESCRIPTION: { min: 3, max: 1000 }, // Length
d0ce42c1 251 USERNAME: { min: 1, max: 50 }, // Length
b0f9f39e 252 PASSWORD: { min: 6, max: 255 }, // Length
eacb25c4 253 VIDEO_QUOTA: { min: -1 },
bee0abff 254 VIDEO_QUOTA_DAILY: { min: -1 },
3caf77d3 255 VIDEO_LANGUAGES: { max: 500 }, // Array length
eacb25c4 256 BLOCKED_REASON: { min: 3, max: 250 } // Length
e4c55619 257 },
d95d1559 258 ABUSES: {
1506307f
C
259 REASON: { min: 2, max: 3000 }, // Length
260 MODERATION_COMMENT: { min: 2, max: 3000 } // Length
55fa55a9 261 },
edbc9325
C
262 ABUSE_MESSAGES: {
263 MESSAGE: { min: 2, max: 3000 } // Length
264 },
26b7305a
C
265 VIDEO_BLACKLIST: {
266 REASON: { min: 2, max: 300 } // Length
267 },
72c7248b 268 VIDEO_CHANNELS: {
9f7a1953 269 NAME: { min: 1, max: 120 }, // Length
d23e6a1c
BY
270 DESCRIPTION: { min: 3, max: 1000 }, // Length
271 SUPPORT: { min: 3, max: 1000 }, // Length
e34c85e5 272 URL: { min: 3, max: 2000 } // Length
72c7248b 273 },
40e87e9e
C
274 VIDEO_CAPTIONS: {
275 CAPTION_FILE: {
f4001cf4 276 EXTNAME: [ '.vtt', '.srt' ],
40e87e9e 277 FILE_SIZE: {
ce7c099f 278 max: 20 * 1024 * 1024 // 20MB
40e87e9e
C
279 }
280 }
281 },
fbad87b0 282 VIDEO_IMPORTS: {
ce33919c
C
283 URL: { min: 3, max: 2000 }, // Length
284 TORRENT_NAME: { min: 3, max: 255 }, // Length
990b6a0b
C
285 TORRENT_FILE: {
286 EXTNAME: [ '.torrent' ],
287 FILE_SIZE: {
288 max: 1024 * 200 // 200 KB
289 }
290 }
fbad87b0 291 },
c48e82b5
C
292 VIDEOS_REDUNDANCY: {
293 URL: { min: 3, max: 2000 } // Length
294 },
5c6d985f
C
295 VIDEO_RATES: {
296 URL: { min: 3, max: 2000 } // Length
297 },
e4c55619 298 VIDEOS: {
a265f7f3 299 NAME: { min: 3, max: 120 }, // Length
9d3ef9fe 300 LANGUAGE: { min: 1, max: 10 }, // Length
9567011b 301 TRUNCATED_DESCRIPTION: { min: 3, max: 250 }, // Length
2422c46b 302 DESCRIPTION: { min: 3, max: 10000 }, // Length
d23e6a1c 303 SUPPORT: { min: 3, max: 1000 }, // Length
ac81d1a0 304 IMAGE: {
e08ff02a 305 EXTNAME: [ '.png', '.jpg', '.jpeg', '.webp' ],
ac81d1a0 306 FILE_SIZE: {
a13df19d 307 max: 4 * 1024 * 1024 // 4MB
ac81d1a0
C
308 }
309 },
536598cf 310 EXTNAME: [] as string[],
0e1dc3e7 311 INFO_HASH: { min: 40, max: 40 }, // Length, info hash is 20 bytes length but we represent it in hexadecimal so 20 * 2
fbad87b0 312 DURATION: { min: 0 }, // Number
a265f7f3
C
313 TAGS: { min: 0, max: 5 }, // Number of total tags
314 TAG: { min: 2, max: 30 }, // Length
e4c87ec2
C
315 VIEWS: { min: 0 },
316 LIKES: { min: 0 },
93e1258c 317 DISLIKES: { min: 0 },
c6c0fa6c 318 FILE_SIZE: { min: -1 },
f6d6e7f8 319 PARTIAL_UPLOAD_SIZE: { max: 50 * 1024 * 1024 * 1024 }, // 50GB
e34c85e5
C
320 URL: { min: 3, max: 2000 } // Length
321 },
418d092a
C
322 VIDEO_PLAYLISTS: {
323 NAME: { min: 1, max: 120 }, // Length
324 DESCRIPTION: { min: 3, max: 1000 }, // Length
325 URL: { min: 3, max: 2000 }, // Length
326 IMAGE: {
327 EXTNAME: [ '.jpg', '.jpeg' ],
328 FILE_SIZE: {
a13df19d 329 max: 4 * 1024 * 1024 // 4MB
418d092a
C
330 }
331 }
332 },
01de67b9 333 ACTORS: {
e34c85e5
C
334 PUBLIC_KEY: { min: 10, max: 5000 }, // Length
335 PRIVATE_KEY: { min: 10, max: 5000 }, // Length
c5911fd3 336 URL: { min: 3, max: 2000 }, // Length
2cb03dc1 337 IMAGE: {
e08ff02a 338 EXTNAME: [ '.png', '.jpeg', '.jpg', '.gif', '.webp' ],
01de67b9 339 FILE_SIZE: {
a13df19d 340 max: 4 * 1024 * 1024 // 4MB
01de67b9 341 }
c5911fd3 342 }
e4c87ec2
C
343 },
344 VIDEO_EVENTS: {
345 COUNT: { min: 0 }
6d852470 346 },
bf1f6508 347 VIDEO_COMMENTS: {
298b3fd3 348 TEXT: { min: 1, max: 10000 }, // Length
6d852470 349 URL: { min: 3, max: 2000 } // Length
4ba3b8ea
C
350 },
351 VIDEO_SHARE: {
352 URL: { min: 3, max: 2000 } // Length
a4101923
C
353 },
354 CONTACT_FORM: {
355 FROM_NAME: { min: 1, max: 120 }, // Length
356 BODY: { min: 3, max: 5000 } // Length
345da516
C
357 },
358 PLUGINS: {
359 NAME: { min: 1, max: 214 }, // Length
360 DESCRIPTION: { min: 1, max: 20000 } // Length
2735a154
C
361 },
362 COMMONS: {
363 URL: { min: 5, max: 2000 } // Length
c729caf6 364 },
92e66e04 365 VIDEO_STUDIO: {
c729caf6
C
366 TASKS: { min: 1, max: 10 }, // Number of tasks
367 CUT_TIME: { min: 0 } // Value
e4c55619
C
368 }
369}
370
c655c9ef 371const VIEW_LIFETIME = {
51353d9a 372 VIEW: CONFIG.VIEWS.VIDEOS.IP_VIEW_EXPIRATION,
f53e1fcd 373 VIEWER_COUNTER: 60000 * 2, // 2 minutes
b2111066 374 VIEWER_STATS: 60000 * 60 // 1 hour
e4bf7856
C
375}
376
42e6a7a7 377const MAX_LOCAL_VIEWER_WATCH_SECTIONS = 100
b2111066 378
a4101923
C
379let CONTACT_FORM_LIFETIME = 60000 * 60 // 1 hour
380
edb4ffc7 381const VIDEO_TRANSCODING_FPS: VideoTranscodingFPS = {
f7bb2bb5 382 MIN: 1,
a1587156
C
383 STANDARD: [ 24, 25, 30 ],
384 HD_STANDARD: [ 50, 60 ],
c729caf6 385 AUDIO_MERGE: 25,
3a6f351b
C
386 AVERAGE: 30,
387 MAX: 60,
388 KEEP_ORIGIN_FPS_RESOLUTION_MIN: 720 // We keep the original FPS on high resolutions (720 minimum)
a7977280 389}
b5c0e955 390
536598cf
C
391const DEFAULT_AUDIO_RESOLUTION = VideoResolution.H_480P
392
ee9e7b61 393const VIDEO_RATE_TYPES: { [ id: string ]: VideoRateType } = {
d38b8281
C
394 LIKE: 'like',
395 DISLIKE: 'dislike'
396}
397
80bc88c1 398const FFMPEG_NICE: { [ id: string ]: number } = {
7abb6060
RK
399 // parent process defaults to niceness = 0
400 // reminder: lower = higher priority, max value is 19, lowest is -20
a4a8cd39
C
401 LIVE: 5, // prioritize over VOD and THUMBNAIL
402 THUMBNAIL: 10,
7abb6060 403 VOD: 15
80bc88c1
J
404}
405
6e07c3de
C
406const VIDEO_CATEGORIES = {
407 1: 'Music',
408 2: 'Films',
409 3: 'Vehicles',
410 4: 'Art',
411 5: 'Sports',
412 6: 'Travels',
413 7: 'Gaming',
414 8: 'People',
415 9: 'Comedy',
416 10: 'Entertainment',
6f2ae7a1 417 11: 'News & Politics',
40298b02 418 12: 'How To',
6e07c3de
C
419 13: 'Education',
420 14: 'Activism',
421 15: 'Science & Technology',
422 16: 'Animals',
423 17: 'Kids',
424 18: 'Food'
425}
426
6f0c39e2
C
427// See https://creativecommons.org/licenses/?lang=en
428const VIDEO_LICENCES = {
429 1: 'Attribution',
430 2: 'Attribution - Share Alike',
431 3: 'Attribution - No Derivatives',
432 4: 'Attribution - Non Commercial',
433 5: 'Attribution - Non Commercial - Share Alike',
434 6: 'Attribution - Non Commercial - No Derivatives',
435 7: 'Public Domain Dedication'
436}
437
a1587156 438const VIDEO_LANGUAGES: { [id: string]: string } = {}
3092476e 439
c6c0fa6c 440const VIDEO_PRIVACIES: { [ id in VideoPrivacy ]: string } = {
a1587156
C
441 [VideoPrivacy.PUBLIC]: 'Public',
442 [VideoPrivacy.UNLISTED]: 'Unlisted',
443 [VideoPrivacy.PRIVATE]: 'Private',
444 [VideoPrivacy.INTERNAL]: 'Internal'
fd45e8f4
C
445}
446
c6c0fa6c 447const VIDEO_STATES: { [ id in VideoState ]: string } = {
a1587156
C
448 [VideoState.PUBLISHED]: 'Published',
449 [VideoState.TO_TRANSCODE]: 'To transcode',
c6c0fa6c
C
450 [VideoState.TO_IMPORT]: 'To import',
451 [VideoState.WAITING_FOR_LIVE]: 'Waiting for livestream',
0305db28 452 [VideoState.LIVE_ENDED]: 'Livestream ended',
4e29f4fe 453 [VideoState.TO_MOVE_TO_EXTERNAL_STORAGE]: 'To move to an external storage',
dbd9fb44 454 [VideoState.TRANSCODING_FAILED]: 'Transcoding failed',
c729caf6
C
455 [VideoState.TO_MOVE_TO_EXTERNAL_STORAGE_FAILED]: 'External storage move failed',
456 [VideoState.TO_EDIT]: 'To edit*'
fbad87b0
C
457}
458
c6c0fa6c 459const VIDEO_IMPORT_STATES: { [ id in VideoImportState ]: string } = {
a1587156
C
460 [VideoImportState.FAILED]: 'Failed',
461 [VideoImportState.PENDING]: 'Pending',
2158ac90 462 [VideoImportState.SUCCESS]: 'Success',
419b520c
C
463 [VideoImportState.REJECTED]: 'Rejected',
464 [VideoImportState.CANCELLED]: 'Cancelled',
465 [VideoImportState.PROCESSING]: 'Processing'
2186386c
C
466}
467
c6c0fa6c 468const ABUSE_STATES: { [ id in AbuseState ]: string } = {
d95d1559
C
469 [AbuseState.PENDING]: 'Pending',
470 [AbuseState.REJECTED]: 'Rejected',
471 [AbuseState.ACCEPTED]: 'Accepted'
268eebed
C
472}
473
c6c0fa6c 474const VIDEO_PLAYLIST_PRIVACIES: { [ id in VideoPlaylistPrivacy ]: string } = {
a1587156
C
475 [VideoPlaylistPrivacy.PUBLIC]: 'Public',
476 [VideoPlaylistPrivacy.UNLISTED]: 'Unlisted',
477 [VideoPlaylistPrivacy.PRIVATE]: 'Private'
418d092a
C
478}
479
c6c0fa6c 480const VIDEO_PLAYLIST_TYPES: { [ id in VideoPlaylistType ]: string } = {
a1587156
C
481 [VideoPlaylistType.REGULAR]: 'Regular',
482 [VideoPlaylistType.WATCH_LATER]: 'Watch later'
df0b219d
C
483}
484
14e2014a 485const MIMETYPES = {
536598cf
C
486 AUDIO: {
487 MIMETYPE_EXT: {
488 'audio/mpeg': '.mp3',
489 'audio/mp3': '.mp3',
4b7a20d8 490
536598cf
C
491 'application/ogg': '.ogg',
492 'audio/ogg': '.ogg',
4b7a20d8 493
99d362de
C
494 'audio/x-ms-wma': '.wma',
495 'audio/wav': '.wav',
e622db05 496 'audio/x-wav': '.wav',
4b7a20d8 497
99d362de 498 'audio/x-flac': '.flac',
b056afe0 499 'audio/flac': '.flac',
4b7a20d8
C
500
501 'audio/vnd.dlna.adts': '.aac',
e622db05 502 'audio/aac': '.aac',
4b7a20d8 503
9556ce48 504 'audio/m4a': '.m4a',
e072fb1e 505 'audio/mp4': '.m4a',
9556ce48 506 'audio/x-m4a': '.m4a',
4b7a20d8
C
507
508 'audio/vnd.dolby.dd-raw': '.ac3',
b056afe0 509 'audio/ac3': '.ac3'
536598cf
C
510 },
511 EXT_MIMETYPE: null as { [ id: string ]: string }
512 },
14e2014a 513 VIDEO: {
30bc55c8
C
514 MIMETYPE_EXT: null as { [ id: string ]: string | string[] },
515 MIMETYPES_REGEX: null as string,
14e2014a
C
516 EXT_MIMETYPE: null as { [ id: string ]: string }
517 },
518 IMAGE: {
519 MIMETYPE_EXT: {
520 'image/png': '.png',
2cb03dc1
C
521 'image/gif': '.gif',
522 'image/webp': '.webp',
14e2014a
C
523 'image/jpg': '.jpg',
524 'image/jpeg': '.jpg'
c6de3a85
C
525 },
526 EXT_MIMETYPE: null as { [ id: string ]: string }
14e2014a
C
527 },
528 VIDEO_CAPTIONS: {
529 MIMETYPE_EXT: {
530 'text/vtt': '.vtt',
2f26030d
C
531 'application/x-subrip': '.srt',
532 'text/plain': '.srt'
14e2014a
C
533 }
534 },
535 TORRENT: {
536 MIMETYPE_EXT: {
537 'application/x-bittorrent': '.torrent'
538 }
539 }
990b6a0b 540}
536598cf 541MIMETYPES.AUDIO.EXT_MIMETYPE = invert(MIMETYPES.AUDIO.MIMETYPE_EXT)
c6de3a85 542MIMETYPES.IMAGE.EXT_MIMETYPE = invert(MIMETYPES.IMAGE.MIMETYPE_EXT)
990b6a0b 543
62549e6c
C
544const BINARY_CONTENT_TYPES = new Set([
545 'binary/octet-stream',
546 'application/octet-stream',
547 'application/x-binary'
548])
549
9f6bae3a
C
550// ---------------------------------------------------------------------------
551
2d3741d6
C
552const OVERVIEWS = {
553 VIDEOS: {
1a471091 554 SAMPLE_THRESHOLD: 6,
764a9657 555 SAMPLES_COUNT: 20
2d3741d6
C
556 }
557}
558
559// ---------------------------------------------------------------------------
560
50d6de9c 561const SERVER_ACTOR_NAME = 'peertube'
350e31d6 562
e4f97bab 563const ACTIVITY_PUB = {
1b5b10d1
C
564 POTENTIAL_ACCEPT_HEADERS: [
565 'application/activity+json',
9a8cbd82
C
566 'application/ld+json',
567 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
165cdc75 568 ],
1b5b10d1 569 ACCEPT_HEADER: 'application/activity+json, application/ld+json',
9a27cdc2 570 PUBLIC: 'https://www.w3.org/ns/activitystreams#Public',
0d0e8dd0 571 COLLECTION_ITEMS_PER_PAGE: 10,
4d9ae8f7 572 FETCH_PAGE_LIMIT: 2000,
20494f12 573 URL_MIME_TYPES: {
536598cf 574 VIDEO: [] as string[],
20494f12
C
575 TORRENT: [ 'application/x-bittorrent' ],
576 MAGNET: [ 'application/x-bittorrent;x-scheme-handler/magnet' ]
a5625b41 577 },
2ccaeeb3 578 MAX_RECURSION_COMMENTS: 100,
0e0c745b 579 ACTOR_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2, // 2 days
9f79ade6
C
580 VIDEO_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2, // 2 days
581 VIDEO_PLAYLIST_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2 // 2 days
e4f97bab
C
582}
583
50d6de9c
C
584const ACTIVITY_PUB_ACTOR_TYPES: { [ id: string ]: ActivityPubActorType } = {
585 GROUP: 'Group',
586 PERSON: 'Person',
47581df0
C
587 APPLICATION: 'Application',
588 ORGANIZATION: 'Organization',
589 SERVICE: 'Service'
50d6de9c
C
590}
591
41f2ebae
C
592const HTTP_SIGNATURE = {
593 HEADER_NAME: 'signature',
594 ALGORITHM: 'rsa-sha256',
543affef 595 HEADERS_TO_SIGN: [ '(request-target)', 'host', 'date', 'digest' ],
f67d7574 596 CLOCK_SKEW_SECONDS: 1800
41f2ebae
C
597}
598
9f6bae3a
C
599// ---------------------------------------------------------------------------
600
04b8c3fb 601let PRIVATE_RSA_KEY_SIZE = 2048
bdfbd4f1 602
9f6bae3a
C
603// Password encryption
604const BCRYPT_SALT_SIZE = 10
a877d5ac 605
f88ee4a9 606const USER_PASSWORD_RESET_LIFETIME = 60000 * 60 // 60 minutes
45f1bd72 607const USER_PASSWORD_CREATE_LIFETIME = 60000 * 60 * 24 * 7 // 7 days
ecb4e35f 608
d9eaee39
JM
609const USER_EMAIL_VERIFY_LIFETIME = 60000 * 60 // 60 minutes
610
6dd9de95 611const NSFW_POLICY_TYPES: { [ id: string ]: NSFWPolicyType } = {
0883b324
C
612 DO_NOT_LIST: 'do_not_list',
613 BLUR: 'blur',
614 DISPLAY: 'display'
615}
616
bdfbd4f1
C
617// ---------------------------------------------------------------------------
618
052937db
C
619// Express static paths (router)
620const STATIC_PATHS = {
f285faa0 621 THUMBNAILS: '/static/thumbnails/',
c5911fd3 622 WEBSEED: '/static/webseed/',
b9fffa29 623 REDUNDANCY: '/static/redundancy/',
9c6ca37f
C
624 STREAMING_PLAYLISTS: {
625 HLS: '/static/streaming-playlists/hls'
90a8bd30 626 }
052937db 627}
02756fbd
C
628const STATIC_DOWNLOAD_PATHS = {
629 TORRENTS: '/download/torrents/',
d7a25329
C
630 VIDEOS: '/download/videos/',
631 HLS_VIDEOS: '/download/streaming-playlists/hls/videos/'
02756fbd 632}
557b13ae 633const LAZY_STATIC_PATHS = {
f4796856 634 BANNERS: '/lazy-static/banners/',
557b13ae 635 AVATARS: '/lazy-static/avatars/',
20dcfd74 636 PREVIEWS: '/lazy-static/previews/',
90a8bd30
C
637 VIDEO_CAPTIONS: '/lazy-static/video-captions/',
638 TORRENTS: '/lazy-static/torrents/'
557b13ae 639}
052937db 640
dc009132 641// Cache control
a1587156 642const STATIC_MAX_AGE = {
cd4cb177 643 SERVER: '2h',
90a8bd30 644 LAZY_SERVER: '2d',
cd4cb177
C
645 CLIENT: '30d'
646}
dc009132 647
cbe2f7c3 648// Videos thumbnail size
d8755eed 649const THUMBNAILS_SIZE = {
4363ce0e
C
650 width: 280,
651 height: 157,
ca6d3622 652 minWidth: 150
d8755eed
C
653}
654const PREVIEWS_SIZE = {
b345a804 655 width: 850,
ca6d3622
C
656 height: 480,
657 minWidth: 400
164174a6 658}
d0800f76 659const ACTOR_IMAGES_SIZE: { [key in ActorImageType]: { width: number, height: number }[]} = {
660 [ActorImageType.AVATAR]: [
661 {
662 width: 120,
663 height: 120
664 },
665 {
666 width: 48,
667 height: 48
668 }
669 ],
670 [ActorImageType.BANNER]: [
671 {
672 width: 1920,
673 height: 317 // 6/1 ratio
674 }
675 ]
e8e12200 676}
164174a6
C
677
678const EMBED_SIZE = {
679 width: 560,
680 height: 315
d8755eed 681}
cbe2f7c3 682
980246ea 683// Sub folders of cache directory
d74d29ad 684const FILES_CACHE = {
f4001cf4
C
685 PREVIEWS: {
686 DIRECTORY: join(CONFIG.STORAGE.CACHE_DIR, 'previews'),
687 MAX_AGE: 1000 * 3600 * 3 // 3 hours
688 },
689 VIDEO_CAPTIONS: {
690 DIRECTORY: join(CONFIG.STORAGE.CACHE_DIR, 'video-captions'),
691 MAX_AGE: 1000 * 3600 * 3 // 3 hours
90a8bd30
C
692 },
693 TORRENTS: {
694 DIRECTORY: join(CONFIG.STORAGE.CACHE_DIR, 'torrents'),
695 MAX_AGE: 1000 * 3600 * 3 // 3 hours
f981dae8
C
696 }
697}
698
557b13ae 699const LRU_CACHE = {
d74d29ad 700 USER_TOKENS: {
557b13ae
C
701 MAX_SIZE: 1000
702 },
f4796856 703 ACTOR_IMAGE_STATIC: {
557b13ae 704 MAX_SIZE: 500
d74d29ad
C
705 }
706}
707
f6d6e7f8 708const RESUMABLE_UPLOAD_DIRECTORY = join(CONFIG.STORAGE.TMP_DIR, 'resumable-uploads')
9c6ca37f 709const HLS_STREAMING_PLAYLIST_DIRECTORY = join(CONFIG.STORAGE.STREAMING_PLAYLISTS_DIR, 'hls')
09209296
C
710const HLS_REDUNDANCY_DIRECTORY = join(CONFIG.STORAGE.REDUNDANCY_DIR, 'hls')
711
276250f0
RK
712const RESUMABLE_UPLOAD_SESSION_LIFETIME = SCHEDULER_INTERVALS_MS.REMOVE_DANGLING_RESUMABLE_UPLOADS
713
c6c0fa6c
C
714const VIDEO_LIVE = {
715 EXTENSION: '.ts',
fb719404 716 CLEANUP_DELAY: 1000 * 60 * 5, // 5 minutes
f443a746
C
717 SEGMENT_TIME_SECONDS: {
718 DEFAULT_LATENCY: 4, // 4 seconds
719 SMALL_LATENCY: 2 // 2 seconds
720 },
fb719404 721 SEGMENTS_LIST_SIZE: 15, // 15 maximum segments in live playlist
937581b8 722 REPLAY_DIRECTORY: 'replay',
e14de000 723 EDGE_LIVE_DELAY_SEGMENTS_NOTIFICATION: 4,
00b87c57 724 MAX_SOCKET_WAITING_DATA: 1024 * 1000 * 100, // 100MB
c6c0fa6c
C
725 RTMP: {
726 CHUNK_SIZE: 60000,
727 GOP_CACHE: true,
728 PING: 60,
729 PING_TIMEOUT: 30,
730 BASE_PATH: 'live'
731 }
732}
733
7348b1fd 734const MEMOIZE_TTL = {
35f28e94 735 OVERVIEWS_SAMPLE: 1000 * 3600 * 4, // 4 hours
fb719404 736 INFO_HASH_EXISTS: 1000 * 3600 * 12, // 12 hours
aa2ce188 737 VIDEO_DURATION: 1000 * 10, // 10 seconds
00b87c57 738 LIVE_ABLE_TO_UPLOAD: 1000 * 60, // 1 minute
cc45cc9a 739 LIVE_CHECK_SOCKET_HEALTH: 1000 * 60 // 1 minute
35f28e94
C
740}
741
742const MEMOIZE_LENGTH = {
aa2ce188
C
743 INFO_HASH_EXISTS: 200,
744 VIDEO_DURATION: 200
7348b1fd
C
745}
746
557b13ae 747const QUEUE_CONCURRENCY = {
f4796856 748 ACTOR_PROCESS_IMAGE: 3
557b13ae
C
749}
750
c48e82b5
C
751const REDUNDANCY = {
752 VIDEOS: {
c48e82b5
C
753 RANDOMIZED_FACTOR: 5
754 }
755}
756
e12a0092 757const ACCEPT_HEADERS = [ 'html', 'application/json' ].concat(ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS)
4f491371 758
536598cf 759const ASSETS_PATH = {
c6c0fa6c
C
760 DEFAULT_AUDIO_BACKGROUND: join(root(), 'dist', 'server', 'assets', 'default-audio-background.jpg'),
761 DEFAULT_LIVE_BACKGROUND: join(root(), 'dist', 'server', 'assets', 'default-live-background.jpg')
536598cf
C
762}
763
bdfbd4f1
C
764// ---------------------------------------------------------------------------
765
e032aec9
C
766const CUSTOM_HTML_TAG_COMMENTS = {
767 TITLE: '<!-- title tag -->',
768 DESCRIPTION: '<!-- description tag -->',
769 CUSTOM_CSS: '<!-- custom css tag -->',
aea0b0e7
C
770 META_TAGS: '<!-- meta tags -->',
771 SERVER_CONFIG: '<!-- server config -->'
e032aec9 772}
709756b8 773
fd8710b8 774const MAX_LOGS_OUTPUT_CHARACTERS = 10 * 1000 * 1000
566c125d
C
775const LOG_FILENAME = 'peertube.log'
776const AUDIT_LOG_FILENAME = 'peertube-audit.log'
fd8710b8 777
4195cd2b
C
778// ---------------------------------------------------------------------------
779
9b67da3d
C
780const TRACKER_RATE_LIMITS = {
781 INTERVAL: 60000 * 5, // 5 minutes
8244c85a 782 ANNOUNCES_PER_IP_PER_INFOHASH: 15, // maximum announces per torrent in the interval
db48de85 783 ANNOUNCES_PER_IP: 30, // maximum announces for all our torrents in the interval
ba881f0e 784 BLOCK_IP_LIFETIME: 60000 * 3 // 3 minutes
9b67da3d
C
785}
786
ae9bbed4
C
787const P2P_MEDIA_LOADER_PEER_VERSION = 2
788
9b67da3d
C
789// ---------------------------------------------------------------------------
790
345da516
C
791const PLUGIN_GLOBAL_CSS_FILE_NAME = 'plugins-global.css'
792const PLUGIN_GLOBAL_CSS_PATH = join(CONFIG.STORAGE.TMP_DIR, PLUGIN_GLOBAL_CSS_FILE_NAME)
793
9107d791
C
794let PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME = 1000 * 60 * 5 // 5 minutes
795
ffb321be
C
796const DEFAULT_THEME_NAME = 'default'
797const DEFAULT_USER_THEME_NAME = 'instance-default'
7cd4d2ba 798
345da516
C
799// ---------------------------------------------------------------------------
800
5fb2e288
C
801const SEARCH_INDEX = {
802 ROUTES: {
803 VIDEOS: '/api/v1/search/videos',
804 VIDEO_CHANNELS: '/api/v1/search/video-channels'
805 }
806}
807
808// ---------------------------------------------------------------------------
809
b2111066 810const STATS_TIMESERIE = {
f40712ab 811 MAX_DAYS: 365 * 10 // Around 10 years
b2111066
C
812}
813
814// ---------------------------------------------------------------------------
815
9f10b292 816// Special constants for a test instance
aa2ce188 817if (isTestInstance() === true && process.env.PRODUCTION_CONSTANTS !== 'true') {
04b8c3fb
C
818 PRIVATE_RSA_KEY_SIZE = 1024
819
60650c77 820 ACTOR_FOLLOW_SCORE.BASE = 20
3cd0734f 821
f285faa0
C
822 REMOTE_SCHEME.HTTP = 'http'
823 REMOTE_SCHEME.WS = 'ws'
3cd0734f 824
cd4cb177 825 STATIC_MAX_AGE.SERVER = '0'
3cd0734f 826
c46edbc2 827 ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE = 2
529f0372
C
828 ACTIVITY_PUB.ACTOR_REFRESH_INTERVAL = 10 * 1000 // 10 seconds
829 ACTIVITY_PUB.VIDEO_REFRESH_INTERVAL = 10 * 1000 // 10 seconds
830 ACTIVITY_PUB.VIDEO_PLAYLIST_REFRESH_INTERVAL = 10 * 1000 // 10 seconds
3cd0734f 831
2cb03dc1 832 CONSTRAINTS_FIELDS.ACTORS.IMAGE.FILE_SIZE.max = 100 * 1024 // 100KB
e9cb361c 833 CONSTRAINTS_FIELDS.VIDEOS.IMAGE.FILE_SIZE.max = 400 * 1024 // 400KB
3cd0734f 834
61953742
C
835 SCHEDULER_INTERVALS_MS.ACTOR_FOLLOW_SCORES = 1000
836 SCHEDULER_INTERVALS_MS.REMOVE_OLD_JOBS = 10000
837 SCHEDULER_INTERVALS_MS.REMOVE_OLD_HISTORY = 5000
838 SCHEDULER_INTERVALS_MS.REMOVE_OLD_VIEWS = 5000
839 SCHEDULER_INTERVALS_MS.UPDATE_VIDEOS = 5000
840 SCHEDULER_INTERVALS_MS.AUTO_FOLLOW_INDEX_INSTANCES = 5000
841 SCHEDULER_INTERVALS_MS.UPDATE_INBOX_STATS = 5000
842 SCHEDULER_INTERVALS_MS.CHECK_PEERTUBE_VERSION = 2000
f1569117 843
51353d9a 844 REPEAT_JOBS['videos-views-stats'] = { every: 5000 }
f1569117 845
74d249bc 846 REPEAT_JOBS['activitypub-cleaner'] = { every: 5000 }
f1569117 847 AP_CLEANER.PERIOD = 5000
2baea0c7 848
c48e82b5
C
849 REDUNDANCY.VIDEOS.RANDOMIZED_FACTOR = 1
850
dfbcefc2 851 VIEW_LIFETIME.VIEWER_COUNTER = 1000 * 5 // 5 second
b2111066 852 VIEW_LIFETIME.VIEWER_STATS = 1000 * 5 // 5 second
a4101923 853 CONTACT_FORM_LIFETIME = 1000 // 1 second
3cd0734f 854
a1587156 855 JOB_ATTEMPTS['email'] = 1
f4001cf4 856
d74d29ad 857 FILES_CACHE.VIDEO_CAPTIONS.MAX_AGE = 3000
764a9657 858 MEMOIZE_TTL.OVERVIEWS_SAMPLE = 3000
97969c4e 859 MEMOIZE_TTL.LIVE_ABLE_TO_UPLOAD = 3000
764a9657 860 OVERVIEWS.VIDEOS.SAMPLE_THRESHOLD = 2
9107d791
C
861
862 PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME = 5000
31c82cd9 863
53023be3 864 VIDEO_LIVE.CLEANUP_DELAY = getIntEnv('PEERTUBE_TEST_CONSTANTS.VIDEO_LIVE.CLEANUP_DELAY') ?? 5000
f443a746
C
865 VIDEO_LIVE.SEGMENT_TIME_SECONDS.DEFAULT_LATENCY = 2
866 VIDEO_LIVE.SEGMENT_TIME_SECONDS.SMALL_LATENCY = 1
501af82d 867 VIDEO_LIVE.EDGE_LIVE_DELAY_SEGMENTS_NOTIFICATION = 1
9f10b292
C
868}
869
14e2014a 870updateWebserverUrls()
536598cf 871updateWebserverConfig()
225a89c2 872
6dd9de95
C
873registerConfigChangedHandler(() => {
874 updateWebserverUrls()
875 updateWebserverConfig()
876})
877
9f10b292
C
878// ---------------------------------------------------------------------------
879
caf2aaf4
K
880const FILES_CONTENT_HASH = {
881 MANIFEST: generateContentHash(),
882 FAVICON: generateContentHash(),
883 LOGO: generateContentHash()
884}
885
886// ---------------------------------------------------------------------------
887
c729caf6
C
888const VIDEO_FILTERS = {
889 WATERMARK: {
890 SIZE_RATIO: 1 / 10,
891 HORIZONTAL_MARGIN_RATIO: 1 / 20,
892 VERTICAL_MARGIN_RATIO: 1 / 20
893 }
894}
895
896// ---------------------------------------------------------------------------
897
65fcc311 898export {
6dd9de95 899 WEBSERVER,
9f6bae3a 900 API_VERSION,
c6c0fa6c 901 VIDEO_LIVE,
66170ca8 902 PEERTUBE_VERSION,
557b13ae 903 LAZY_STATIC_PATHS,
5fb2e288 904 SEARCH_INDEX,
f6d6e7f8 905 RESUMABLE_UPLOAD_DIRECTORY,
276250f0 906 RESUMABLE_UPLOAD_SESSION_LIFETIME,
09209296 907 HLS_REDUNDANCY_DIRECTORY,
ae9bbed4 908 P2P_MEDIA_LOADER_PEER_VERSION,
2cb03dc1 909 ACTOR_IMAGES_SIZE,
4f491371 910 ACCEPT_HEADERS,
9f6bae3a 911 BCRYPT_SALT_SIZE,
9b67da3d 912 TRACKER_RATE_LIMITS,
d74d29ad 913 FILES_CACHE,
566c125d 914 LOG_FILENAME,
9f6bae3a 915 CONSTRAINTS_FIELDS,
164174a6 916 EMBED_SIZE,
c48e82b5 917 REDUNDANCY,
94a5ff8a
C
918 JOB_CONCURRENCY,
919 JOB_ATTEMPTS,
f1569117 920 AP_CLEANER,
b769007f 921 LAST_MIGRATION_VERSION,
9f6bae3a 922 OAUTH_LIFETIME,
e032aec9 923 CUSTOM_HTML_TAG_COMMENTS,
b2111066 924 STATS_TIMESERIE,
f55e5a7b 925 BROADCAST_CONCURRENCY,
566c125d 926 AUDIT_LOG_FILENAME,
1194e8b4 927 PAGINATION,
60650c77 928 ACTOR_FOLLOW_SCORE,
f285faa0
C
929 PREVIEWS_SIZE,
930 REMOTE_SCHEME,
7a7724e6 931 FOLLOW_STATES,
ffb321be 932 DEFAULT_USER_THEME_NAME,
50d6de9c 933 SERVER_ACTOR_NAME,
345da516
C
934 PLUGIN_GLOBAL_CSS_FILE_NAME,
935 PLUGIN_GLOBAL_CSS_PATH,
e4f97bab 936 PRIVATE_RSA_KEY_SIZE,
c729caf6 937 VIDEO_FILTERS,
fd4484f1 938 ROUTE_CACHE_LIFETIME,
9f6bae3a 939 SORTABLE_COLUMNS,
9c6ca37f 940 HLS_STREAMING_PLAYLIST_DIRECTORY,
2b86fe72 941 JOB_TTL,
ffb321be 942 DEFAULT_THEME_NAME,
0883b324 943 NSFW_POLICY_TYPES,
dc009132 944 STATIC_MAX_AGE,
a6375e69 945 STATIC_PATHS,
cf9166cf 946 VIDEO_IMPORT_TIMEOUT,
df0b219d 947 VIDEO_PLAYLIST_TYPES,
fd8710b8 948 MAX_LOGS_OUTPUT_CHARACTERS,
e4f97bab 949 ACTIVITY_PUB,
50d6de9c 950 ACTIVITY_PUB_ACTOR_TYPES,
9f6bae3a 951 THUMBNAILS_SIZE,
6e07c3de 952 VIDEO_CATEGORIES,
35f28e94 953 MEMOIZE_LENGTH,
3092476e 954 VIDEO_LANGUAGES,
fd45e8f4 955 VIDEO_PRIVACIES,
6f0c39e2 956 VIDEO_LICENCES,
2186386c 957 VIDEO_STATES,
557b13ae 958 QUEUE_CONCURRENCY,
0d0e8dd0 959 VIDEO_RATE_TYPES,
77d7e851 960 JOB_PRIORITY,
a7977280 961 VIDEO_TRANSCODING_FPS,
80bc88c1 962 FFMPEG_NICE,
d95d1559 963 ABUSE_STATES,
557b13ae 964 LRU_CACHE,
4c99953a 965 REQUEST_TIMEOUTS,
b2111066 966 MAX_LOCAL_VIEWER_WATCH_SECTIONS,
ecb4e35f 967 USER_PASSWORD_RESET_LIFETIME,
45f1bd72 968 USER_PASSWORD_CREATE_LIFETIME,
7348b1fd 969 MEMOIZE_TTL,
d9eaee39 970 USER_EMAIL_VERIFY_LIFETIME,
2d3741d6 971 OVERVIEWS,
2baea0c7 972 SCHEDULER_INTERVALS_MS,
6b616860 973 REPEAT_JOBS,
02756fbd 974 STATIC_DOWNLOAD_PATHS,
14e2014a 975 MIMETYPES,
f6eebcb3 976 CRAWL_REQUEST_CONCURRENCY,
536598cf 977 DEFAULT_AUDIO_RESOLUTION,
62549e6c 978 BINARY_CONTENT_TYPES,
b5c0e955 979 JOB_COMPLETED_LIFETIME,
41f2ebae 980 HTTP_SIGNATURE,
fbad87b0 981 VIDEO_IMPORT_STATES,
e4bf7856 982 VIEW_LIFETIME,
a4101923 983 CONTACT_FORM_LIFETIME,
418d092a 984 VIDEO_PLAYLIST_PRIVACIES,
9107d791 985 PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME,
536598cf 986 ASSETS_PATH,
caf2aaf4 987 FILES_CONTENT_HASH,
74dc3bca 988 loadLanguages,
caf2aaf4
K
989 buildLanguages,
990 generateContentHash
9f10b292 991}
fd206f0b
C
992
993// ---------------------------------------------------------------------------
994
14e2014a
C
995function buildVideoMimetypeExt () {
996 const data = {
fccbbc1a 997 // streamable formats that warrant cross-browser compatibility
14e2014a 998 'video/webm': '.webm',
30bc55c8
C
999 // We'll add .ogg if additional extensions are enabled
1000 // We could add .ogg here but since it could be an audio file,
1001 // it would be confusing for users because PeerTube will refuse their file (based on the mimetype)
1002 'video/ogg': [ '.ogv' ],
14e2014a
C
1003 'video/mp4': '.mp4'
1004 }
1005
536598cf
C
1006 if (CONFIG.TRANSCODING.ENABLED) {
1007 if (CONFIG.TRANSCODING.ALLOW_ADDITIONAL_EXTENSIONS) {
30bc55c8
C
1008 data['video/ogg'].push('.ogg')
1009
536598cf 1010 Object.assign(data, {
536598cf 1011 'video/x-matroska': '.mkv',
fccbbc1a
RK
1012
1013 // Developed by Apple
b056afe0 1014 'video/quicktime': [ '.mov', '.qt', '.mqv' ], // often used as output format by editing software
c37a52b0 1015 'video/x-m4v': '.m4v',
fccbbc1a
RK
1016 'video/m4v': '.m4v',
1017
1018 // Developed by the Adobe Flash Platform
1019 'video/x-flv': '.flv',
1020 'video/x-f4v': '.f4v', // replacement for flv
1021
1022 // Developed by Microsoft
1023 'video/x-ms-wmv': '.wmv',
1024 'video/x-msvideo': '.avi',
1025 'video/avi': '.avi',
1026
1027 // Developed by 3GPP
1028 // common video formats for cell phones
b056afe0
RK
1029 'video/3gpp': [ '.3gp', '.3gpp' ],
1030 'video/3gpp2': [ '.3g2', '.3gpp2' ],
fccbbc1a
RK
1031
1032 // Developed by FFmpeg/Mplayer
1033 'application/x-nut': '.nut',
1034
1035 // The standard video format used by many Sony and Panasonic HD camcorders.
1036 // It is also used for storing high definition video on Blu-ray discs.
1037 'video/mp2t': '.mts',
4b7a20d8
C
1038 'video/vnd.dlna.mpeg-tts': '.mts',
1039
fccbbc1a
RK
1040 'video/m2ts': '.m2ts',
1041
1042 // Old formats reliant on MPEG-1/MPEG-2
1043 'video/mpv': '.mpv',
1044 'video/mpeg2': '.m2v',
b056afe0
RK
1045 'video/mpeg': [ '.m1v', '.mpg', '.mpe', '.mpeg', '.vob' ],
1046 'video/dvd': '.vob',
fccbbc1a 1047
26469f9e
C
1048 // Could be anything
1049 'application/octet-stream': null,
fccbbc1a 1050 'application/mxf': '.mxf' // often used as exchange format by editing software
536598cf
C
1051 })
1052 }
1053
1054 if (CONFIG.TRANSCODING.ALLOW_AUDIO_FILES) {
1055 Object.assign(data, MIMETYPES.AUDIO.MIMETYPE_EXT)
1056 }
14e2014a
C
1057 }
1058
1059 return data
1060}
1061
1062function updateWebserverUrls () {
6dd9de95
C
1063 WEBSERVER.URL = sanitizeUrl(CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT)
1064 WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT, REMOTE_SCHEME.HTTP)
6dd9de95 1065 WEBSERVER.WS = CONFIG.WEBSERVER.WS
c6c0fa6c
C
1066
1067 WEBSERVER.SCHEME = CONFIG.WEBSERVER.SCHEME
6dd9de95
C
1068 WEBSERVER.HOSTNAME = CONFIG.WEBSERVER.HOSTNAME
1069 WEBSERVER.PORT = CONFIG.WEBSERVER.PORT
c6c0fa6c 1070
cfbe6be5
C
1071 const rtmpHostname = CONFIG.LIVE.RTMP.PUBLIC_HOSTNAME || CONFIG.WEBSERVER.HOSTNAME
1072 const rtmpsHostname = CONFIG.LIVE.RTMPS.PUBLIC_HOSTNAME || CONFIG.WEBSERVER.HOSTNAME
1073
1074 WEBSERVER.RTMP_URL = 'rtmp://' + rtmpHostname + ':' + CONFIG.LIVE.RTMP.PORT + '/' + VIDEO_LIVE.RTMP.BASE_PATH
1075 WEBSERVER.RTMPS_URL = 'rtmps://' + rtmpsHostname + ':' + CONFIG.LIVE.RTMPS.PORT + '/' + VIDEO_LIVE.RTMP.BASE_PATH
fd206f0b
C
1076}
1077
14e2014a 1078function updateWebserverConfig () {
14e2014a 1079 MIMETYPES.VIDEO.MIMETYPE_EXT = buildVideoMimetypeExt()
30bc55c8
C
1080 MIMETYPES.VIDEO.MIMETYPES_REGEX = buildMimetypesRegex(MIMETYPES.VIDEO.MIMETYPE_EXT)
1081
536598cf
C
1082 ACTIVITY_PUB.URL_MIME_TYPES.VIDEO = Object.keys(MIMETYPES.VIDEO.MIMETYPE_EXT)
1083
30bc55c8
C
1084 MIMETYPES.VIDEO.EXT_MIMETYPE = buildVideoExtMimetype(MIMETYPES.VIDEO.MIMETYPE_EXT)
1085
1086 CONSTRAINTS_FIELDS.VIDEOS.EXTNAME = Object.keys(MIMETYPES.VIDEO.EXT_MIMETYPE)
1087}
1088
1089function buildVideoExtMimetype (obj: { [ id: string ]: string | string[] }) {
1090 const result: { [id: string]: string } = {}
1091
1092 for (const mimetype of Object.keys(obj)) {
1093 const value = obj[mimetype]
1094 if (!value) continue
1095
1096 const extensions = Array.isArray(value) ? value : [ value ]
1097
1098 for (const extension of extensions) {
1099 result[extension] = mimetype
1100 }
1101 }
1102
1103 return result
14e2014a
C
1104}
1105
30bc55c8
C
1106function buildMimetypesRegex (obj: { [id: string]: string | string[] }) {
1107 return Object.keys(obj)
1108 .map(m => `(${m})`)
1109 .join('|')
14e2014a
C
1110}
1111
74dc3bca 1112function loadLanguages () {
8f0bc73d 1113 Object.assign(VIDEO_LANGUAGES, buildLanguages())
74dc3bca
C
1114}
1115
9d3ef9fe
C
1116function buildLanguages () {
1117 const iso639 = require('iso-639-3')
1118
a1587156 1119 const languages: { [id: string]: string } = {}
9d3ef9fe 1120
1d94c154 1121 const additionalLanguages = {
a1587156
C
1122 sgn: true, // Sign languages (macro language)
1123 ase: true, // American sign language
1124 sdl: true, // Arabian sign language
1125 bfi: true, // British sign language
1126 bzs: true, // Brazilian sign language
1127 csl: true, // Chinese sign language
1128 cse: true, // Czech sign language
1129 dsl: true, // Danish sign language
1130 fsl: true, // French sign language
1131 gsg: true, // German sign language
1132 pks: true, // Pakistan sign language
1133 jsl: true, // Japanese sign language
1134 sfs: true, // South African sign language
1135 swl: true, // Swedish sign language
07c01b31
C
1136 rsl: true, // Russian sign language
1137
1138 kab: true, // Kabyle
a1587156 1139
23fdb0ff
C
1140 lat: true, // Latin
1141
a1587156
C
1142 epo: true, // Esperanto
1143 tlh: true, // Klingon
1144 jbo: true, // Lojban
81547acb
FC
1145 avk: true, // Kotava
1146
1147 zxx: true // No linguistic content (ISO-639-2)
1d94c154 1148 }
9d3ef9fe
C
1149
1150 // Only add ISO639-1 languages and some sign languages (ISO639-3)
1151 iso639
1152 .filter(l => {
4fdeef81 1153 return (l.iso6391 !== undefined && l.type === 'living') ||
a1587156 1154 additionalLanguages[l.iso6393] === true
9d3ef9fe 1155 })
a1587156 1156 .forEach(l => { languages[l.iso6391 || l.iso6393] = l.name })
9d3ef9fe 1157
db6d617d 1158 // Override Occitan label
a1587156
C
1159 languages['oc'] = 'Occitan'
1160 languages['el'] = 'Greek'
db6d617d 1161
8f7d35fd
C
1162 // Chinese languages
1163 languages['zh-Hans'] = 'Simplified Chinese'
1164 languages['zh-Hant'] = 'Traditional Chinese'
1165
9d3ef9fe
C
1166 return languages
1167}
caf2aaf4
K
1168
1169function generateContentHash () {
1170 return randomBytes(20).toString('hex')
1171}
53023be3
C
1172
1173function getIntEnv (path: string) {
1174 if (process.env[path]) return parseInt(process.env[path])
1175
1176 return undefined
1177}