]>
Commit | Line | Data |
---|---|---|
1 | import { randomInt } from '../../shared/core-utils/miscs/miscs' | |
2 | import { CronRepeatOptions, EveryRepeatOptions } from 'bull' | |
3 | import { randomBytes } from 'crypto' | |
4 | import { invert } from 'lodash' | |
5 | import { join } from 'path' | |
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 { 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, root, sanitizeHost, sanitizeUrl } from '../helpers/core-utils' | |
23 | import { CONFIG, registerConfigChangedHandler } from './config' | |
24 | ||
25 | // --------------------------------------------------------------------------- | |
26 | ||
27 | const LAST_MIGRATION_VERSION = 560 | |
28 | ||
29 | // --------------------------------------------------------------------------- | |
30 | ||
31 | const API_VERSION = 'v1' | |
32 | const PEERTUBE_VERSION = 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 | } | |
57 | ||
58 | // Sortable columns per schema | |
59 | const SORTABLE_COLUMNS = { | |
60 | USERS: [ 'id', 'username', 'videoQuotaUsed', 'createdAt', 'lastLoginDate', 'role' ], | |
61 | USER_SUBSCRIPTIONS: [ 'id', 'createdAt' ], | |
62 | ACCOUNTS: [ 'createdAt' ], | |
63 | JOBS: [ 'createdAt' ], | |
64 | VIDEO_CHANNELS: [ 'id', 'name', 'updatedAt', 'createdAt' ], | |
65 | VIDEO_IMPORTS: [ 'createdAt' ], | |
66 | ||
67 | VIDEO_COMMENT_THREADS: [ 'createdAt', 'totalReplies' ], | |
68 | VIDEO_COMMENTS: [ 'createdAt' ], | |
69 | ||
70 | VIDEO_RATES: [ 'createdAt' ], | |
71 | BLACKLISTS: [ 'id', 'name', 'duration', 'views', 'likes', 'dislikes', 'uuid', 'createdAt' ], | |
72 | FOLLOWERS: [ 'createdAt', 'state', 'score' ], | |
73 | FOLLOWING: [ 'createdAt', 'redundancyAllowed', 'state' ], | |
74 | ||
75 | VIDEOS: [ 'name', 'duration', 'createdAt', 'publishedAt', 'originallyPublishedAt', 'views', 'likes', 'trending' ], | |
76 | ||
77 | // Don't forget to update peertube-search-index with the same values | |
78 | VIDEOS_SEARCH: [ 'name', 'duration', 'createdAt', 'publishedAt', 'originallyPublishedAt', 'views', 'likes', 'match' ], | |
79 | VIDEO_CHANNELS_SEARCH: [ 'match', 'displayName', 'createdAt' ], | |
80 | ||
81 | ABUSES: [ 'id', 'createdAt', 'state' ], | |
82 | ||
83 | ACCOUNTS_BLOCKLIST: [ 'createdAt' ], | |
84 | SERVERS_BLOCKLIST: [ 'createdAt' ], | |
85 | ||
86 | USER_NOTIFICATIONS: [ 'createdAt', 'read' ], | |
87 | ||
88 | VIDEO_PLAYLISTS: [ 'displayName', 'createdAt', 'updatedAt' ], | |
89 | ||
90 | PLUGINS: [ 'name', 'createdAt', 'updatedAt' ], | |
91 | ||
92 | AVAILABLE_PLUGINS: [ 'npmName', 'popularity' ], | |
93 | ||
94 | VIDEO_REDUNDANCIES: [ 'name' ] | |
95 | } | |
96 | ||
97 | const OAUTH_LIFETIME = { | |
98 | ACCESS_TOKEN: 3600 * 24, // 1 day, for upload | |
99 | REFRESH_TOKEN: 1209600 // 2 weeks | |
100 | } | |
101 | ||
102 | const ROUTE_CACHE_LIFETIME = { | |
103 | FEEDS: '15 minutes', | |
104 | ROBOTS: '2 hours', | |
105 | SITEMAP: '1 day', | |
106 | SECURITYTXT: '2 hours', | |
107 | NODEINFO: '10 minutes', | |
108 | DNT_POLICY: '1 week', | |
109 | ACTIVITY_PUB: { | |
110 | VIDEOS: '1 second' // 1 second, cache concurrent requests after a broadcast for example | |
111 | }, | |
112 | STATS: '4 hours' | |
113 | } | |
114 | ||
115 | // --------------------------------------------------------------------------- | |
116 | ||
117 | // Number of points we add/remove after a successful/bad request | |
118 | const ACTOR_FOLLOW_SCORE = { | |
119 | PENALTY: -10, | |
120 | BONUS: 10, | |
121 | BASE: 1000, | |
122 | MAX: 10000 | |
123 | } | |
124 | ||
125 | const FOLLOW_STATES: { [ id: string ]: FollowState } = { | |
126 | PENDING: 'pending', | |
127 | ACCEPTED: 'accepted' | |
128 | } | |
129 | ||
130 | const REMOTE_SCHEME = { | |
131 | HTTP: 'https', | |
132 | WS: 'wss' | |
133 | } | |
134 | ||
135 | const JOB_ATTEMPTS: { [id in JobType]: number } = { | |
136 | 'activitypub-http-broadcast': 5, | |
137 | 'activitypub-http-unicast': 5, | |
138 | 'activitypub-http-fetcher': 5, | |
139 | 'activitypub-follow': 5, | |
140 | 'video-file-import': 1, | |
141 | 'video-transcoding': 1, | |
142 | 'video-import': 1, | |
143 | 'email': 5, | |
144 | 'videos-views': 1, | |
145 | 'activitypub-refresher': 1, | |
146 | 'video-redundancy': 1, | |
147 | 'video-live-ending': 1 | |
148 | } | |
149 | const JOB_CONCURRENCY: { [id in JobType]: number } = { | |
150 | 'activitypub-http-broadcast': 1, | |
151 | 'activitypub-http-unicast': 5, | |
152 | 'activitypub-http-fetcher': 1, | |
153 | 'activitypub-follow': 1, | |
154 | 'video-file-import': 1, | |
155 | 'video-transcoding': 1, | |
156 | 'video-import': 1, | |
157 | 'email': 5, | |
158 | 'videos-views': 1, | |
159 | 'activitypub-refresher': 1, | |
160 | 'video-redundancy': 1, | |
161 | 'video-live-ending': 10 | |
162 | } | |
163 | const JOB_TTL: { [id in JobType]: number } = { | |
164 | 'activitypub-http-broadcast': 60000 * 10, // 10 minutes | |
165 | 'activitypub-http-unicast': 60000 * 10, // 10 minutes | |
166 | 'activitypub-http-fetcher': 1000 * 3600 * 10, // 10 hours | |
167 | 'activitypub-follow': 60000 * 10, // 10 minutes | |
168 | 'video-file-import': 1000 * 3600, // 1 hour | |
169 | 'video-transcoding': 1000 * 3600 * 48, // 2 days, transcoding could be long | |
170 | 'video-import': 1000 * 3600 * 2, // 2 hours | |
171 | 'email': 60000 * 10, // 10 minutes | |
172 | 'videos-views': undefined, // Unlimited | |
173 | 'activitypub-refresher': 60000 * 10, // 10 minutes | |
174 | 'video-redundancy': 1000 * 3600 * 3, // 3 hours | |
175 | 'video-live-ending': 1000 * 60 * 10 // 10 minutes | |
176 | } | |
177 | const REPEAT_JOBS: { [ id: string ]: EveryRepeatOptions | CronRepeatOptions } = { | |
178 | 'videos-views': { | |
179 | cron: randomInt(1, 20) + ' * * * *' // Between 1-20 minutes past the hour | |
180 | } | |
181 | } | |
182 | ||
183 | const BROADCAST_CONCURRENCY = 10 // How many requests in parallel we do in activitypub-http-broadcast job | |
184 | const CRAWL_REQUEST_CONCURRENCY = 1 // How many requests in parallel to fetch remote data (likes, shares...) | |
185 | const JOB_REQUEST_TIMEOUT = 3000 // 3 seconds | |
186 | const JOB_COMPLETED_LIFETIME = 60000 * 60 * 24 * 2 // 2 days | |
187 | const VIDEO_IMPORT_TIMEOUT = 1000 * 3600 // 1 hour | |
188 | ||
189 | const SCHEDULER_INTERVALS_MS = { | |
190 | actorFollowScores: 60000 * 60, // 1 hour | |
191 | removeOldJobs: 60000 * 60, // 1 hour | |
192 | updateVideos: 60000, // 1 minute | |
193 | youtubeDLUpdate: 60000 * 60 * 24, // 1 day | |
194 | checkPlugins: CONFIG.PLUGINS.INDEX.CHECK_LATEST_VERSIONS_INTERVAL, | |
195 | autoFollowIndexInstances: 60000 * 60 * 24, // 1 day | |
196 | removeOldViews: 60000 * 60 * 24, // 1 day | |
197 | removeOldHistory: 60000 * 60 * 24 // 1 day | |
198 | } | |
199 | ||
200 | // --------------------------------------------------------------------------- | |
201 | ||
202 | const CONSTRAINTS_FIELDS = { | |
203 | USERS: { | |
204 | NAME: { min: 1, max: 120 }, // Length | |
205 | DESCRIPTION: { min: 3, max: 1000 }, // Length | |
206 | USERNAME: { min: 1, max: 50 }, // Length | |
207 | PASSWORD: { min: 6, max: 255 }, // Length | |
208 | VIDEO_QUOTA: { min: -1 }, | |
209 | VIDEO_QUOTA_DAILY: { min: -1 }, | |
210 | VIDEO_LANGUAGES: { max: 500 }, // Array length | |
211 | BLOCKED_REASON: { min: 3, max: 250 } // Length | |
212 | }, | |
213 | ABUSES: { | |
214 | REASON: { min: 2, max: 3000 }, // Length | |
215 | MODERATION_COMMENT: { min: 2, max: 3000 } // Length | |
216 | }, | |
217 | ABUSE_MESSAGES: { | |
218 | MESSAGE: { min: 2, max: 3000 } // Length | |
219 | }, | |
220 | VIDEO_BLACKLIST: { | |
221 | REASON: { min: 2, max: 300 } // Length | |
222 | }, | |
223 | VIDEO_CHANNELS: { | |
224 | NAME: { min: 1, max: 120 }, // Length | |
225 | DESCRIPTION: { min: 3, max: 1000 }, // Length | |
226 | SUPPORT: { min: 3, max: 1000 }, // Length | |
227 | URL: { min: 3, max: 2000 } // Length | |
228 | }, | |
229 | VIDEO_CAPTIONS: { | |
230 | CAPTION_FILE: { | |
231 | EXTNAME: [ '.vtt', '.srt' ], | |
232 | FILE_SIZE: { | |
233 | max: 2 * 1024 * 1024 // 2MB | |
234 | } | |
235 | } | |
236 | }, | |
237 | VIDEO_IMPORTS: { | |
238 | URL: { min: 3, max: 2000 }, // Length | |
239 | TORRENT_NAME: { min: 3, max: 255 }, // Length | |
240 | TORRENT_FILE: { | |
241 | EXTNAME: [ '.torrent' ], | |
242 | FILE_SIZE: { | |
243 | max: 1024 * 200 // 200 KB | |
244 | } | |
245 | } | |
246 | }, | |
247 | VIDEOS_REDUNDANCY: { | |
248 | URL: { min: 3, max: 2000 } // Length | |
249 | }, | |
250 | VIDEO_RATES: { | |
251 | URL: { min: 3, max: 2000 } // Length | |
252 | }, | |
253 | VIDEOS: { | |
254 | NAME: { min: 3, max: 120 }, // Length | |
255 | LANGUAGE: { min: 1, max: 10 }, // Length | |
256 | TRUNCATED_DESCRIPTION: { min: 3, max: 250 }, // Length | |
257 | DESCRIPTION: { min: 3, max: 10000 }, // Length | |
258 | SUPPORT: { min: 3, max: 1000 }, // Length | |
259 | IMAGE: { | |
260 | EXTNAME: [ '.jpg', '.jpeg' ], | |
261 | FILE_SIZE: { | |
262 | max: 2 * 1024 * 1024 // 2MB | |
263 | } | |
264 | }, | |
265 | EXTNAME: [] as string[], | |
266 | INFO_HASH: { min: 40, max: 40 }, // Length, info hash is 20 bytes length but we represent it in hexadecimal so 20 * 2 | |
267 | DURATION: { min: 0 }, // Number | |
268 | TAGS: { min: 0, max: 5 }, // Number of total tags | |
269 | TAG: { min: 2, max: 30 }, // Length | |
270 | THUMBNAIL: { min: 2, max: 30 }, | |
271 | THUMBNAIL_DATA: { min: 0, max: 20000 }, // Bytes | |
272 | VIEWS: { min: 0 }, | |
273 | LIKES: { min: 0 }, | |
274 | DISLIKES: { min: 0 }, | |
275 | FILE_SIZE: { min: -1 }, | |
276 | URL: { min: 3, max: 2000 } // Length | |
277 | }, | |
278 | VIDEO_PLAYLISTS: { | |
279 | NAME: { min: 1, max: 120 }, // Length | |
280 | DESCRIPTION: { min: 3, max: 1000 }, // Length | |
281 | URL: { min: 3, max: 2000 }, // Length | |
282 | IMAGE: { | |
283 | EXTNAME: [ '.jpg', '.jpeg' ], | |
284 | FILE_SIZE: { | |
285 | max: 2 * 1024 * 1024 // 2MB | |
286 | } | |
287 | } | |
288 | }, | |
289 | ACTORS: { | |
290 | PUBLIC_KEY: { min: 10, max: 5000 }, // Length | |
291 | PRIVATE_KEY: { min: 10, max: 5000 }, // Length | |
292 | URL: { min: 3, max: 2000 }, // Length | |
293 | AVATAR: { | |
294 | EXTNAME: [ '.png', '.jpeg', '.jpg', '.gif' ], | |
295 | FILE_SIZE: { | |
296 | max: 2 * 1024 * 1024 // 2MB | |
297 | } | |
298 | } | |
299 | }, | |
300 | VIDEO_EVENTS: { | |
301 | COUNT: { min: 0 } | |
302 | }, | |
303 | VIDEO_COMMENTS: { | |
304 | TEXT: { min: 1, max: 10000 }, // Length | |
305 | URL: { min: 3, max: 2000 } // Length | |
306 | }, | |
307 | VIDEO_SHARE: { | |
308 | URL: { min: 3, max: 2000 } // Length | |
309 | }, | |
310 | CONTACT_FORM: { | |
311 | FROM_NAME: { min: 1, max: 120 }, // Length | |
312 | BODY: { min: 3, max: 5000 } // Length | |
313 | }, | |
314 | PLUGINS: { | |
315 | NAME: { min: 1, max: 214 }, // Length | |
316 | DESCRIPTION: { min: 1, max: 20000 } // Length | |
317 | }, | |
318 | COMMONS: { | |
319 | URL: { min: 5, max: 2000 } // Length | |
320 | } | |
321 | } | |
322 | ||
323 | const VIEW_LIFETIME = { | |
324 | VIDEO: 60000 * 60, // 1 hour | |
325 | LIVE: 60000 * 5 // 5 minutes | |
326 | } | |
327 | ||
328 | let CONTACT_FORM_LIFETIME = 60000 * 60 // 1 hour | |
329 | ||
330 | const VIDEO_TRANSCODING_FPS: VideoTranscodingFPS = { | |
331 | MIN: 10, | |
332 | STANDARD: [ 24, 25, 30 ], | |
333 | HD_STANDARD: [ 50, 60 ], | |
334 | AVERAGE: 30, | |
335 | MAX: 60, | |
336 | KEEP_ORIGIN_FPS_RESOLUTION_MIN: 720 // We keep the original FPS on high resolutions (720 minimum) | |
337 | } | |
338 | ||
339 | const VIDEO_TRANSCODING_ENCODERS = { | |
340 | VIDEO: [ 'libx264' ], | |
341 | ||
342 | // Try the first one, if not available try the second one etc | |
343 | AUDIO: [ | |
344 | // we favor VBR, if a good AAC encoder is available | |
345 | 'libfdk_aac', | |
346 | 'aac' | |
347 | ] | |
348 | } | |
349 | ||
350 | const DEFAULT_AUDIO_RESOLUTION = VideoResolution.H_480P | |
351 | ||
352 | const VIDEO_RATE_TYPES: { [ id: string ]: VideoRateType } = { | |
353 | LIKE: 'like', | |
354 | DISLIKE: 'dislike' | |
355 | } | |
356 | ||
357 | const FFMPEG_NICE: { [ id: string ]: number } = { | |
358 | THUMBNAIL: 2, // 2 just for don't blocking servers | |
359 | TRANSCODING: 15 | |
360 | } | |
361 | ||
362 | const VIDEO_CATEGORIES = { | |
363 | 1: 'Music', | |
364 | 2: 'Films', | |
365 | 3: 'Vehicles', | |
366 | 4: 'Art', | |
367 | 5: 'Sports', | |
368 | 6: 'Travels', | |
369 | 7: 'Gaming', | |
370 | 8: 'People', | |
371 | 9: 'Comedy', | |
372 | 10: 'Entertainment', | |
373 | 11: 'News & Politics', | |
374 | 12: 'How To', | |
375 | 13: 'Education', | |
376 | 14: 'Activism', | |
377 | 15: 'Science & Technology', | |
378 | 16: 'Animals', | |
379 | 17: 'Kids', | |
380 | 18: 'Food' | |
381 | } | |
382 | ||
383 | // See https://creativecommons.org/licenses/?lang=en | |
384 | const VIDEO_LICENCES = { | |
385 | 1: 'Attribution', | |
386 | 2: 'Attribution - Share Alike', | |
387 | 3: 'Attribution - No Derivatives', | |
388 | 4: 'Attribution - Non Commercial', | |
389 | 5: 'Attribution - Non Commercial - Share Alike', | |
390 | 6: 'Attribution - Non Commercial - No Derivatives', | |
391 | 7: 'Public Domain Dedication' | |
392 | } | |
393 | ||
394 | const VIDEO_LANGUAGES: { [id: string]: string } = {} | |
395 | ||
396 | const VIDEO_PRIVACIES: { [ id in VideoPrivacy ]: string } = { | |
397 | [VideoPrivacy.PUBLIC]: 'Public', | |
398 | [VideoPrivacy.UNLISTED]: 'Unlisted', | |
399 | [VideoPrivacy.PRIVATE]: 'Private', | |
400 | [VideoPrivacy.INTERNAL]: 'Internal' | |
401 | } | |
402 | ||
403 | const VIDEO_STATES: { [ id in VideoState ]: string } = { | |
404 | [VideoState.PUBLISHED]: 'Published', | |
405 | [VideoState.TO_TRANSCODE]: 'To transcode', | |
406 | [VideoState.TO_IMPORT]: 'To import', | |
407 | [VideoState.WAITING_FOR_LIVE]: 'Waiting for livestream', | |
408 | [VideoState.LIVE_ENDED]: 'Livestream ended' | |
409 | } | |
410 | ||
411 | const VIDEO_IMPORT_STATES: { [ id in VideoImportState ]: string } = { | |
412 | [VideoImportState.FAILED]: 'Failed', | |
413 | [VideoImportState.PENDING]: 'Pending', | |
414 | [VideoImportState.SUCCESS]: 'Success', | |
415 | [VideoImportState.REJECTED]: 'Rejected' | |
416 | } | |
417 | ||
418 | const ABUSE_STATES: { [ id in AbuseState ]: string } = { | |
419 | [AbuseState.PENDING]: 'Pending', | |
420 | [AbuseState.REJECTED]: 'Rejected', | |
421 | [AbuseState.ACCEPTED]: 'Accepted' | |
422 | } | |
423 | ||
424 | const VIDEO_PLAYLIST_PRIVACIES: { [ id in VideoPlaylistPrivacy ]: string } = { | |
425 | [VideoPlaylistPrivacy.PUBLIC]: 'Public', | |
426 | [VideoPlaylistPrivacy.UNLISTED]: 'Unlisted', | |
427 | [VideoPlaylistPrivacy.PRIVATE]: 'Private' | |
428 | } | |
429 | ||
430 | const VIDEO_PLAYLIST_TYPES: { [ id in VideoPlaylistType ]: string } = { | |
431 | [VideoPlaylistType.REGULAR]: 'Regular', | |
432 | [VideoPlaylistType.WATCH_LATER]: 'Watch later' | |
433 | } | |
434 | ||
435 | const MIMETYPES = { | |
436 | AUDIO: { | |
437 | MIMETYPE_EXT: { | |
438 | 'audio/mpeg': '.mp3', | |
439 | 'audio/mp3': '.mp3', | |
440 | 'application/ogg': '.ogg', | |
441 | 'audio/ogg': '.ogg', | |
442 | 'audio/x-ms-wma': '.wma', | |
443 | 'audio/wav': '.wav', | |
444 | 'audio/x-flac': '.flac', | |
445 | 'audio/flac': '.flac', | |
446 | '‎audio/aac': '.aac', | |
447 | 'audio/ac3': '.ac3' | |
448 | }, | |
449 | EXT_MIMETYPE: null as { [ id: string ]: string } | |
450 | }, | |
451 | VIDEO: { | |
452 | MIMETYPE_EXT: null as { [ id: string ]: string | string[] }, | |
453 | MIMETYPES_REGEX: null as string, | |
454 | EXT_MIMETYPE: null as { [ id: string ]: string } | |
455 | }, | |
456 | IMAGE: { | |
457 | MIMETYPE_EXT: { | |
458 | 'image/png': '.png', | |
459 | 'image/jpg': '.jpg', | |
460 | 'image/jpeg': '.jpg' | |
461 | }, | |
462 | EXT_MIMETYPE: null as { [ id: string ]: string } | |
463 | }, | |
464 | VIDEO_CAPTIONS: { | |
465 | MIMETYPE_EXT: { | |
466 | 'text/vtt': '.vtt', | |
467 | 'application/x-subrip': '.srt', | |
468 | 'text/plain': '.srt' | |
469 | } | |
470 | }, | |
471 | TORRENT: { | |
472 | MIMETYPE_EXT: { | |
473 | 'application/x-bittorrent': '.torrent' | |
474 | } | |
475 | } | |
476 | } | |
477 | MIMETYPES.AUDIO.EXT_MIMETYPE = invert(MIMETYPES.AUDIO.MIMETYPE_EXT) | |
478 | MIMETYPES.IMAGE.EXT_MIMETYPE = invert(MIMETYPES.IMAGE.MIMETYPE_EXT) | |
479 | ||
480 | // --------------------------------------------------------------------------- | |
481 | ||
482 | const OVERVIEWS = { | |
483 | VIDEOS: { | |
484 | SAMPLE_THRESHOLD: 6, | |
485 | SAMPLES_COUNT: 20 | |
486 | } | |
487 | } | |
488 | ||
489 | const VIDEO_CHANNELS = { | |
490 | MAX_PER_USER: 20 | |
491 | } | |
492 | ||
493 | // --------------------------------------------------------------------------- | |
494 | ||
495 | const SERVER_ACTOR_NAME = 'peertube' | |
496 | ||
497 | const ACTIVITY_PUB = { | |
498 | POTENTIAL_ACCEPT_HEADERS: [ | |
499 | 'application/activity+json', | |
500 | 'application/ld+json', | |
501 | 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' | |
502 | ], | |
503 | ACCEPT_HEADER: 'application/activity+json, application/ld+json', | |
504 | PUBLIC: 'https://www.w3.org/ns/activitystreams#Public', | |
505 | COLLECTION_ITEMS_PER_PAGE: 10, | |
506 | FETCH_PAGE_LIMIT: 2000, | |
507 | URL_MIME_TYPES: { | |
508 | VIDEO: [] as string[], | |
509 | TORRENT: [ 'application/x-bittorrent' ], | |
510 | MAGNET: [ 'application/x-bittorrent;x-scheme-handler/magnet' ] | |
511 | }, | |
512 | MAX_RECURSION_COMMENTS: 100, | |
513 | ACTOR_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2, // 2 days | |
514 | VIDEO_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2, // 2 days | |
515 | VIDEO_PLAYLIST_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2 // 2 days | |
516 | } | |
517 | ||
518 | const ACTIVITY_PUB_ACTOR_TYPES: { [ id: string ]: ActivityPubActorType } = { | |
519 | GROUP: 'Group', | |
520 | PERSON: 'Person', | |
521 | APPLICATION: 'Application', | |
522 | ORGANIZATION: 'Organization', | |
523 | SERVICE: 'Service' | |
524 | } | |
525 | ||
526 | const HTTP_SIGNATURE = { | |
527 | HEADER_NAME: 'signature', | |
528 | ALGORITHM: 'rsa-sha256', | |
529 | HEADERS_TO_SIGN: [ '(request-target)', 'host', 'date', 'digest' ], | |
530 | REQUIRED_HEADERS: { | |
531 | ALL: [ '(request-target)', 'host', 'date' ], | |
532 | POST: [ '(request-target)', 'host', 'date', 'digest' ] | |
533 | }, | |
534 | CLOCK_SKEW_SECONDS: 1800 | |
535 | } | |
536 | ||
537 | // --------------------------------------------------------------------------- | |
538 | ||
539 | let PRIVATE_RSA_KEY_SIZE = 2048 | |
540 | ||
541 | // Password encryption | |
542 | const BCRYPT_SALT_SIZE = 10 | |
543 | ||
544 | const USER_PASSWORD_RESET_LIFETIME = 60000 * 60 // 60 minutes | |
545 | const USER_PASSWORD_CREATE_LIFETIME = 60000 * 60 * 24 * 7 // 7 days | |
546 | ||
547 | const USER_EMAIL_VERIFY_LIFETIME = 60000 * 60 // 60 minutes | |
548 | ||
549 | const NSFW_POLICY_TYPES: { [ id: string ]: NSFWPolicyType } = { | |
550 | DO_NOT_LIST: 'do_not_list', | |
551 | BLUR: 'blur', | |
552 | DISPLAY: 'display' | |
553 | } | |
554 | ||
555 | // --------------------------------------------------------------------------- | |
556 | ||
557 | // Express static paths (router) | |
558 | const STATIC_PATHS = { | |
559 | PREVIEWS: '/static/previews/', | |
560 | THUMBNAILS: '/static/thumbnails/', | |
561 | TORRENTS: '/static/torrents/', | |
562 | WEBSEED: '/static/webseed/', | |
563 | REDUNDANCY: '/static/redundancy/', | |
564 | STREAMING_PLAYLISTS: { | |
565 | HLS: '/static/streaming-playlists/hls' | |
566 | }, | |
567 | AVATARS: '/static/avatars/', | |
568 | VIDEO_CAPTIONS: '/static/video-captions/' | |
569 | } | |
570 | const STATIC_DOWNLOAD_PATHS = { | |
571 | TORRENTS: '/download/torrents/', | |
572 | VIDEOS: '/download/videos/', | |
573 | HLS_VIDEOS: '/download/streaming-playlists/hls/videos/' | |
574 | } | |
575 | const LAZY_STATIC_PATHS = { | |
576 | AVATARS: '/lazy-static/avatars/', | |
577 | PREVIEWS: '/lazy-static/previews/', | |
578 | VIDEO_CAPTIONS: '/lazy-static/video-captions/' | |
579 | } | |
580 | ||
581 | // Cache control | |
582 | const STATIC_MAX_AGE = { | |
583 | SERVER: '2h', | |
584 | CLIENT: '30d' | |
585 | } | |
586 | ||
587 | // Videos thumbnail size | |
588 | const THUMBNAILS_SIZE = { | |
589 | width: 223, | |
590 | height: 122, | |
591 | minWidth: 150 | |
592 | } | |
593 | const PREVIEWS_SIZE = { | |
594 | width: 850, | |
595 | height: 480, | |
596 | minWidth: 400 | |
597 | } | |
598 | const AVATARS_SIZE = { | |
599 | width: 120, | |
600 | height: 120 | |
601 | } | |
602 | ||
603 | const EMBED_SIZE = { | |
604 | width: 560, | |
605 | height: 315 | |
606 | } | |
607 | ||
608 | // Sub folders of cache directory | |
609 | const FILES_CACHE = { | |
610 | PREVIEWS: { | |
611 | DIRECTORY: join(CONFIG.STORAGE.CACHE_DIR, 'previews'), | |
612 | MAX_AGE: 1000 * 3600 * 3 // 3 hours | |
613 | }, | |
614 | VIDEO_CAPTIONS: { | |
615 | DIRECTORY: join(CONFIG.STORAGE.CACHE_DIR, 'video-captions'), | |
616 | MAX_AGE: 1000 * 3600 * 3 // 3 hours | |
617 | } | |
618 | } | |
619 | ||
620 | const LRU_CACHE = { | |
621 | USER_TOKENS: { | |
622 | MAX_SIZE: 1000 | |
623 | }, | |
624 | AVATAR_STATIC: { | |
625 | MAX_SIZE: 500 | |
626 | } | |
627 | } | |
628 | ||
629 | const HLS_STREAMING_PLAYLIST_DIRECTORY = join(CONFIG.STORAGE.STREAMING_PLAYLISTS_DIR, 'hls') | |
630 | const HLS_REDUNDANCY_DIRECTORY = join(CONFIG.STORAGE.REDUNDANCY_DIR, 'hls') | |
631 | ||
632 | const VIDEO_LIVE = { | |
633 | EXTENSION: '.ts', | |
634 | CLEANUP_DELAY: 1000 * 60 * 5, // 5 minutes | |
635 | SEGMENT_TIME_SECONDS: 4, // 4 seconds | |
636 | SEGMENTS_LIST_SIZE: 15, // 15 maximum segments in live playlist | |
637 | EDGE_LIVE_DELAY_SEGMENTS_NOTIFICATION: 4, | |
638 | RTMP: { | |
639 | CHUNK_SIZE: 60000, | |
640 | GOP_CACHE: true, | |
641 | PING: 60, | |
642 | PING_TIMEOUT: 30, | |
643 | BASE_PATH: 'live' | |
644 | } | |
645 | } | |
646 | ||
647 | const MEMOIZE_TTL = { | |
648 | OVERVIEWS_SAMPLE: 1000 * 3600 * 4, // 4 hours | |
649 | INFO_HASH_EXISTS: 1000 * 3600 * 12, // 12 hours | |
650 | LIVE_ABLE_TO_UPLOAD: 1000 * 60 // 1 minute | |
651 | } | |
652 | ||
653 | const MEMOIZE_LENGTH = { | |
654 | INFO_HASH_EXISTS: 200 | |
655 | } | |
656 | ||
657 | const QUEUE_CONCURRENCY = { | |
658 | AVATAR_PROCESS_IMAGE: 3 | |
659 | } | |
660 | ||
661 | const REDUNDANCY = { | |
662 | VIDEOS: { | |
663 | RANDOMIZED_FACTOR: 5 | |
664 | } | |
665 | } | |
666 | ||
667 | const ACCEPT_HEADERS = [ 'html', 'application/json' ].concat(ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS) | |
668 | ||
669 | const ASSETS_PATH = { | |
670 | DEFAULT_AUDIO_BACKGROUND: join(root(), 'dist', 'server', 'assets', 'default-audio-background.jpg'), | |
671 | DEFAULT_LIVE_BACKGROUND: join(root(), 'dist', 'server', 'assets', 'default-live-background.jpg') | |
672 | } | |
673 | ||
674 | // --------------------------------------------------------------------------- | |
675 | ||
676 | const CUSTOM_HTML_TAG_COMMENTS = { | |
677 | TITLE: '<!-- title tag -->', | |
678 | DESCRIPTION: '<!-- description tag -->', | |
679 | CUSTOM_CSS: '<!-- custom css tag -->', | |
680 | META_TAGS: '<!-- meta tags -->' | |
681 | } | |
682 | ||
683 | // --------------------------------------------------------------------------- | |
684 | ||
685 | const FEEDS = { | |
686 | COUNT: 20 | |
687 | } | |
688 | ||
689 | const MAX_LOGS_OUTPUT_CHARACTERS = 10 * 1000 * 1000 | |
690 | const LOG_FILENAME = 'peertube.log' | |
691 | const AUDIT_LOG_FILENAME = 'peertube-audit.log' | |
692 | ||
693 | // --------------------------------------------------------------------------- | |
694 | ||
695 | const TRACKER_RATE_LIMITS = { | |
696 | INTERVAL: 60000 * 5, // 5 minutes | |
697 | ANNOUNCES_PER_IP_PER_INFOHASH: 15, // maximum announces per torrent in the interval | |
698 | ANNOUNCES_PER_IP: 30, // maximum announces for all our torrents in the interval | |
699 | BLOCK_IP_LIFETIME: 60000 * 3 // 3 minutes | |
700 | } | |
701 | ||
702 | const P2P_MEDIA_LOADER_PEER_VERSION = 2 | |
703 | ||
704 | // --------------------------------------------------------------------------- | |
705 | ||
706 | const PLUGIN_GLOBAL_CSS_FILE_NAME = 'plugins-global.css' | |
707 | const PLUGIN_GLOBAL_CSS_PATH = join(CONFIG.STORAGE.TMP_DIR, PLUGIN_GLOBAL_CSS_FILE_NAME) | |
708 | ||
709 | let PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME = 1000 * 60 * 5 // 5 minutes | |
710 | ||
711 | const DEFAULT_THEME_NAME = 'default' | |
712 | const DEFAULT_USER_THEME_NAME = 'instance-default' | |
713 | ||
714 | // --------------------------------------------------------------------------- | |
715 | ||
716 | const SEARCH_INDEX = { | |
717 | ROUTES: { | |
718 | VIDEOS: '/api/v1/search/videos', | |
719 | VIDEO_CHANNELS: '/api/v1/search/video-channels' | |
720 | } | |
721 | } | |
722 | ||
723 | // --------------------------------------------------------------------------- | |
724 | ||
725 | // Special constants for a test instance | |
726 | if (isTestInstance() === true) { | |
727 | PRIVATE_RSA_KEY_SIZE = 1024 | |
728 | ||
729 | ACTOR_FOLLOW_SCORE.BASE = 20 | |
730 | ||
731 | REMOTE_SCHEME.HTTP = 'http' | |
732 | REMOTE_SCHEME.WS = 'ws' | |
733 | ||
734 | STATIC_MAX_AGE.SERVER = '0' | |
735 | ||
736 | ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE = 2 | |
737 | ACTIVITY_PUB.ACTOR_REFRESH_INTERVAL = 10 * 1000 // 10 seconds | |
738 | ACTIVITY_PUB.VIDEO_REFRESH_INTERVAL = 10 * 1000 // 10 seconds | |
739 | ACTIVITY_PUB.VIDEO_PLAYLIST_REFRESH_INTERVAL = 10 * 1000 // 10 seconds | |
740 | ||
741 | CONSTRAINTS_FIELDS.ACTORS.AVATAR.FILE_SIZE.max = 100 * 1024 // 100KB | |
742 | ||
743 | SCHEDULER_INTERVALS_MS.actorFollowScores = 1000 | |
744 | SCHEDULER_INTERVALS_MS.removeOldJobs = 10000 | |
745 | SCHEDULER_INTERVALS_MS.removeOldHistory = 5000 | |
746 | SCHEDULER_INTERVALS_MS.removeOldViews = 5000 | |
747 | SCHEDULER_INTERVALS_MS.updateVideos = 5000 | |
748 | SCHEDULER_INTERVALS_MS.autoFollowIndexInstances = 5000 | |
749 | REPEAT_JOBS['videos-views'] = { every: 5000 } | |
750 | ||
751 | REDUNDANCY.VIDEOS.RANDOMIZED_FACTOR = 1 | |
752 | ||
753 | VIEW_LIFETIME.VIDEO = 1000 // 1 second | |
754 | VIEW_LIFETIME.LIVE = 1000 * 5 // 5 second | |
755 | CONTACT_FORM_LIFETIME = 1000 // 1 second | |
756 | ||
757 | JOB_ATTEMPTS['email'] = 1 | |
758 | ||
759 | FILES_CACHE.VIDEO_CAPTIONS.MAX_AGE = 3000 | |
760 | MEMOIZE_TTL.OVERVIEWS_SAMPLE = 3000 | |
761 | MEMOIZE_TTL.LIVE_ABLE_TO_UPLOAD = 3000 | |
762 | OVERVIEWS.VIDEOS.SAMPLE_THRESHOLD = 2 | |
763 | ||
764 | PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME = 5000 | |
765 | ||
766 | VIDEO_LIVE.CLEANUP_DELAY = 5000 | |
767 | VIDEO_LIVE.SEGMENT_TIME_SECONDS = 2 | |
768 | VIDEO_LIVE.EDGE_LIVE_DELAY_SEGMENTS_NOTIFICATION = 1 | |
769 | } | |
770 | ||
771 | updateWebserverUrls() | |
772 | updateWebserverConfig() | |
773 | ||
774 | registerConfigChangedHandler(() => { | |
775 | updateWebserverUrls() | |
776 | updateWebserverConfig() | |
777 | }) | |
778 | ||
779 | // --------------------------------------------------------------------------- | |
780 | ||
781 | const FILES_CONTENT_HASH = { | |
782 | MANIFEST: generateContentHash(), | |
783 | FAVICON: generateContentHash(), | |
784 | LOGO: generateContentHash() | |
785 | } | |
786 | ||
787 | // --------------------------------------------------------------------------- | |
788 | ||
789 | export { | |
790 | WEBSERVER, | |
791 | API_VERSION, | |
792 | VIDEO_LIVE, | |
793 | PEERTUBE_VERSION, | |
794 | LAZY_STATIC_PATHS, | |
795 | SEARCH_INDEX, | |
796 | HLS_REDUNDANCY_DIRECTORY, | |
797 | P2P_MEDIA_LOADER_PEER_VERSION, | |
798 | AVATARS_SIZE, | |
799 | ACCEPT_HEADERS, | |
800 | BCRYPT_SALT_SIZE, | |
801 | TRACKER_RATE_LIMITS, | |
802 | FILES_CACHE, | |
803 | LOG_FILENAME, | |
804 | CONSTRAINTS_FIELDS, | |
805 | EMBED_SIZE, | |
806 | REDUNDANCY, | |
807 | JOB_CONCURRENCY, | |
808 | JOB_ATTEMPTS, | |
809 | LAST_MIGRATION_VERSION, | |
810 | OAUTH_LIFETIME, | |
811 | CUSTOM_HTML_TAG_COMMENTS, | |
812 | BROADCAST_CONCURRENCY, | |
813 | AUDIT_LOG_FILENAME, | |
814 | PAGINATION, | |
815 | ACTOR_FOLLOW_SCORE, | |
816 | PREVIEWS_SIZE, | |
817 | REMOTE_SCHEME, | |
818 | VIDEO_TRANSCODING_ENCODERS, | |
819 | FOLLOW_STATES, | |
820 | DEFAULT_USER_THEME_NAME, | |
821 | SERVER_ACTOR_NAME, | |
822 | PLUGIN_GLOBAL_CSS_FILE_NAME, | |
823 | PLUGIN_GLOBAL_CSS_PATH, | |
824 | PRIVATE_RSA_KEY_SIZE, | |
825 | ROUTE_CACHE_LIFETIME, | |
826 | SORTABLE_COLUMNS, | |
827 | HLS_STREAMING_PLAYLIST_DIRECTORY, | |
828 | FEEDS, | |
829 | JOB_TTL, | |
830 | DEFAULT_THEME_NAME, | |
831 | NSFW_POLICY_TYPES, | |
832 | STATIC_MAX_AGE, | |
833 | STATIC_PATHS, | |
834 | VIDEO_IMPORT_TIMEOUT, | |
835 | VIDEO_PLAYLIST_TYPES, | |
836 | MAX_LOGS_OUTPUT_CHARACTERS, | |
837 | ACTIVITY_PUB, | |
838 | ACTIVITY_PUB_ACTOR_TYPES, | |
839 | THUMBNAILS_SIZE, | |
840 | VIDEO_CATEGORIES, | |
841 | MEMOIZE_LENGTH, | |
842 | VIDEO_LANGUAGES, | |
843 | VIDEO_PRIVACIES, | |
844 | VIDEO_LICENCES, | |
845 | VIDEO_STATES, | |
846 | QUEUE_CONCURRENCY, | |
847 | VIDEO_RATE_TYPES, | |
848 | VIDEO_TRANSCODING_FPS, | |
849 | FFMPEG_NICE, | |
850 | ABUSE_STATES, | |
851 | VIDEO_CHANNELS, | |
852 | LRU_CACHE, | |
853 | JOB_REQUEST_TIMEOUT, | |
854 | USER_PASSWORD_RESET_LIFETIME, | |
855 | USER_PASSWORD_CREATE_LIFETIME, | |
856 | MEMOIZE_TTL, | |
857 | USER_EMAIL_VERIFY_LIFETIME, | |
858 | OVERVIEWS, | |
859 | SCHEDULER_INTERVALS_MS, | |
860 | REPEAT_JOBS, | |
861 | STATIC_DOWNLOAD_PATHS, | |
862 | MIMETYPES, | |
863 | CRAWL_REQUEST_CONCURRENCY, | |
864 | DEFAULT_AUDIO_RESOLUTION, | |
865 | JOB_COMPLETED_LIFETIME, | |
866 | HTTP_SIGNATURE, | |
867 | VIDEO_IMPORT_STATES, | |
868 | VIEW_LIFETIME, | |
869 | CONTACT_FORM_LIFETIME, | |
870 | VIDEO_PLAYLIST_PRIVACIES, | |
871 | PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME, | |
872 | ASSETS_PATH, | |
873 | FILES_CONTENT_HASH, | |
874 | loadLanguages, | |
875 | buildLanguages, | |
876 | generateContentHash | |
877 | } | |
878 | ||
879 | // --------------------------------------------------------------------------- | |
880 | ||
881 | function buildVideoMimetypeExt () { | |
882 | const data = { | |
883 | // streamable formats that warrant cross-browser compatibility | |
884 | 'video/webm': '.webm', | |
885 | // We'll add .ogg if additional extensions are enabled | |
886 | // We could add .ogg here but since it could be an audio file, | |
887 | // it would be confusing for users because PeerTube will refuse their file (based on the mimetype) | |
888 | 'video/ogg': [ '.ogv' ], | |
889 | 'video/mp4': '.mp4' | |
890 | } | |
891 | ||
892 | if (CONFIG.TRANSCODING.ENABLED) { | |
893 | if (CONFIG.TRANSCODING.ALLOW_ADDITIONAL_EXTENSIONS) { | |
894 | data['video/ogg'].push('.ogg') | |
895 | ||
896 | Object.assign(data, { | |
897 | 'video/x-matroska': '.mkv', | |
898 | ||
899 | // Developed by Apple | |
900 | 'video/quicktime': [ '.mov', '.qt', '.mqv' ], // often used as output format by editing software | |
901 | 'video/x-m4v': '.m4v', | |
902 | 'video/m4v': '.m4v', | |
903 | ||
904 | // Developed by the Adobe Flash Platform | |
905 | 'video/x-flv': '.flv', | |
906 | 'video/x-f4v': '.f4v', // replacement for flv | |
907 | ||
908 | // Developed by Microsoft | |
909 | 'video/x-ms-wmv': '.wmv', | |
910 | 'video/x-msvideo': '.avi', | |
911 | 'video/avi': '.avi', | |
912 | ||
913 | // Developed by 3GPP | |
914 | // common video formats for cell phones | |
915 | 'video/3gpp': [ '.3gp', '.3gpp' ], | |
916 | 'video/3gpp2': [ '.3g2', '.3gpp2' ], | |
917 | ||
918 | // Developed by FFmpeg/Mplayer | |
919 | 'application/x-nut': '.nut', | |
920 | ||
921 | // The standard video format used by many Sony and Panasonic HD camcorders. | |
922 | // It is also used for storing high definition video on Blu-ray discs. | |
923 | 'video/mp2t': '.mts', | |
924 | 'video/m2ts': '.m2ts', | |
925 | ||
926 | // Old formats reliant on MPEG-1/MPEG-2 | |
927 | 'video/mpv': '.mpv', | |
928 | 'video/mpeg2': '.m2v', | |
929 | 'video/mpeg': [ '.m1v', '.mpg', '.mpe', '.mpeg', '.vob' ], | |
930 | 'video/dvd': '.vob', | |
931 | ||
932 | // Could be anything | |
933 | 'application/octet-stream': null, | |
934 | 'application/mxf': '.mxf' // often used as exchange format by editing software | |
935 | }) | |
936 | } | |
937 | ||
938 | if (CONFIG.TRANSCODING.ALLOW_AUDIO_FILES) { | |
939 | Object.assign(data, MIMETYPES.AUDIO.MIMETYPE_EXT) | |
940 | } | |
941 | } | |
942 | ||
943 | return data | |
944 | } | |
945 | ||
946 | function updateWebserverUrls () { | |
947 | WEBSERVER.URL = sanitizeUrl(CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT) | |
948 | WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT, REMOTE_SCHEME.HTTP) | |
949 | WEBSERVER.WS = CONFIG.WEBSERVER.WS | |
950 | ||
951 | WEBSERVER.SCHEME = CONFIG.WEBSERVER.SCHEME | |
952 | WEBSERVER.HOSTNAME = CONFIG.WEBSERVER.HOSTNAME | |
953 | WEBSERVER.PORT = CONFIG.WEBSERVER.PORT | |
954 | ||
955 | WEBSERVER.RTMP_URL = 'rtmp://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.LIVE.RTMP.PORT + '/' + VIDEO_LIVE.RTMP.BASE_PATH | |
956 | } | |
957 | ||
958 | function updateWebserverConfig () { | |
959 | MIMETYPES.VIDEO.MIMETYPE_EXT = buildVideoMimetypeExt() | |
960 | MIMETYPES.VIDEO.MIMETYPES_REGEX = buildMimetypesRegex(MIMETYPES.VIDEO.MIMETYPE_EXT) | |
961 | ||
962 | ACTIVITY_PUB.URL_MIME_TYPES.VIDEO = Object.keys(MIMETYPES.VIDEO.MIMETYPE_EXT) | |
963 | ||
964 | MIMETYPES.VIDEO.EXT_MIMETYPE = buildVideoExtMimetype(MIMETYPES.VIDEO.MIMETYPE_EXT) | |
965 | ||
966 | CONSTRAINTS_FIELDS.VIDEOS.EXTNAME = Object.keys(MIMETYPES.VIDEO.EXT_MIMETYPE) | |
967 | } | |
968 | ||
969 | function buildVideoExtMimetype (obj: { [ id: string ]: string | string[] }) { | |
970 | const result: { [id: string]: string } = {} | |
971 | ||
972 | for (const mimetype of Object.keys(obj)) { | |
973 | const value = obj[mimetype] | |
974 | if (!value) continue | |
975 | ||
976 | const extensions = Array.isArray(value) ? value : [ value ] | |
977 | ||
978 | for (const extension of extensions) { | |
979 | result[extension] = mimetype | |
980 | } | |
981 | } | |
982 | ||
983 | return result | |
984 | } | |
985 | ||
986 | function buildMimetypesRegex (obj: { [id: string]: string | string[] }) { | |
987 | return Object.keys(obj) | |
988 | .map(m => `(${m})`) | |
989 | .join('|') | |
990 | } | |
991 | ||
992 | function loadLanguages () { | |
993 | Object.assign(VIDEO_LANGUAGES, buildLanguages()) | |
994 | } | |
995 | ||
996 | function buildLanguages () { | |
997 | const iso639 = require('iso-639-3') | |
998 | ||
999 | const languages: { [id: string]: string } = {} | |
1000 | ||
1001 | const additionalLanguages = { | |
1002 | sgn: true, // Sign languages (macro language) | |
1003 | ase: true, // American sign language | |
1004 | sdl: true, // Arabian sign language | |
1005 | bfi: true, // British sign language | |
1006 | bzs: true, // Brazilian sign language | |
1007 | csl: true, // Chinese sign language | |
1008 | cse: true, // Czech sign language | |
1009 | dsl: true, // Danish sign language | |
1010 | fsl: true, // French sign language | |
1011 | gsg: true, // German sign language | |
1012 | pks: true, // Pakistan sign language | |
1013 | jsl: true, // Japanese sign language | |
1014 | sfs: true, // South African sign language | |
1015 | swl: true, // Swedish sign language | |
1016 | rsl: true, // Russian sign language | |
1017 | ||
1018 | kab: true, // Kabyle | |
1019 | ||
1020 | epo: true, // Esperanto | |
1021 | tlh: true, // Klingon | |
1022 | jbo: true, // Lojban | |
1023 | avk: true // Kotava | |
1024 | } | |
1025 | ||
1026 | // Only add ISO639-1 languages and some sign languages (ISO639-3) | |
1027 | iso639 | |
1028 | .filter(l => { | |
1029 | return (l.iso6391 !== undefined && l.type === 'living') || | |
1030 | additionalLanguages[l.iso6393] === true | |
1031 | }) | |
1032 | .forEach(l => { languages[l.iso6391 || l.iso6393] = l.name }) | |
1033 | ||
1034 | // Override Occitan label | |
1035 | languages['oc'] = 'Occitan' | |
1036 | languages['el'] = 'Greek' | |
1037 | ||
1038 | return languages | |
1039 | } | |
1040 | ||
1041 | function generateContentHash () { | |
1042 | return randomBytes(20).toString('hex') | |
1043 | } |