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