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