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