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