]>
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 = 650 | |
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 | VIDEO_PLAYLISTS_SEARCH: [ 'match', 'displayName', 'createdAt' ], | |
81 | ||
82 | ABUSES: [ 'id', 'createdAt', 'state' ], | |
83 | ||
84 | ACCOUNTS_BLOCKLIST: [ 'createdAt' ], | |
85 | SERVERS_BLOCKLIST: [ 'createdAt' ], | |
86 | ||
87 | USER_NOTIFICATIONS: [ 'createdAt', 'read' ], | |
88 | ||
89 | VIDEO_PLAYLISTS: [ 'name', 'displayName', 'createdAt', 'updatedAt' ], | |
90 | ||
91 | PLUGINS: [ 'name', 'createdAt', 'updatedAt' ], | |
92 | ||
93 | AVAILABLE_PLUGINS: [ 'npmName', 'popularity' ], | |
94 | ||
95 | VIDEO_REDUNDANCIES: [ 'name' ] | |
96 | } | |
97 | ||
98 | const OAUTH_LIFETIME = { | |
99 | ACCESS_TOKEN: 3600 * 24, // 1 day, for upload | |
100 | REFRESH_TOKEN: 1209600 // 2 weeks | |
101 | } | |
102 | ||
103 | const ROUTE_CACHE_LIFETIME = { | |
104 | FEEDS: '15 minutes', | |
105 | ROBOTS: '2 hours', | |
106 | SITEMAP: '1 day', | |
107 | SECURITYTXT: '2 hours', | |
108 | NODEINFO: '10 minutes', | |
109 | DNT_POLICY: '1 week', | |
110 | ACTIVITY_PUB: { | |
111 | VIDEOS: '1 second' // 1 second, cache concurrent requests after a broadcast for example | |
112 | }, | |
113 | STATS: '4 hours' | |
114 | } | |
115 | ||
116 | // --------------------------------------------------------------------------- | |
117 | ||
118 | // Number of points we add/remove after a successful/bad request | |
119 | const ACTOR_FOLLOW_SCORE = { | |
120 | PENALTY: -10, | |
121 | BONUS: 10, | |
122 | BASE: 1000, | |
123 | MAX: 10000 | |
124 | } | |
125 | ||
126 | const FOLLOW_STATES: { [ id: string ]: FollowState } = { | |
127 | PENDING: 'pending', | |
128 | ACCEPTED: 'accepted' | |
129 | } | |
130 | ||
131 | const REMOTE_SCHEME = { | |
132 | HTTP: 'https', | |
133 | WS: 'wss' | |
134 | } | |
135 | ||
136 | const JOB_ATTEMPTS: { [id in JobType]: number } = { | |
137 | 'activitypub-http-broadcast': 5, | |
138 | 'activitypub-http-unicast': 5, | |
139 | 'activitypub-http-fetcher': 5, | |
140 | 'activitypub-follow': 5, | |
141 | 'activitypub-cleaner': 1, | |
142 | 'video-file-import': 1, | |
143 | 'video-transcoding': 1, | |
144 | 'video-import': 1, | |
145 | 'email': 5, | |
146 | 'actor-keys': 3, | |
147 | 'videos-views': 1, | |
148 | 'activitypub-refresher': 1, | |
149 | 'video-redundancy': 1, | |
150 | 'video-live-ending': 1 | |
151 | } | |
152 | // Excluded keys are jobs that can be configured by admins | |
153 | const JOB_CONCURRENCY: { [id in Exclude<JobType, 'video-transcoding' | 'video-import'>]: number } = { | |
154 | 'activitypub-http-broadcast': 1, | |
155 | 'activitypub-http-unicast': 5, | |
156 | 'activitypub-http-fetcher': 3, | |
157 | 'activitypub-cleaner': 1, | |
158 | 'activitypub-follow': 1, | |
159 | 'video-file-import': 1, | |
160 | 'email': 5, | |
161 | 'actor-keys': 1, | |
162 | 'videos-views': 1, | |
163 | 'activitypub-refresher': 1, | |
164 | 'video-redundancy': 1, | |
165 | 'video-live-ending': 10 | |
166 | } | |
167 | const JOB_TTL: { [id in JobType]: number } = { | |
168 | 'activitypub-http-broadcast': 60000 * 10, // 10 minutes | |
169 | 'activitypub-http-unicast': 60000 * 10, // 10 minutes | |
170 | 'activitypub-http-fetcher': 1000 * 3600 * 10, // 10 hours | |
171 | 'activitypub-follow': 60000 * 10, // 10 minutes | |
172 | 'activitypub-cleaner': 1000 * 3600, // 1 hour | |
173 | 'video-file-import': 1000 * 3600, // 1 hour | |
174 | 'video-transcoding': 1000 * 3600 * 48, // 2 days, transcoding could be long | |
175 | 'video-import': 1000 * 3600 * 2, // 2 hours | |
176 | 'email': 60000 * 10, // 10 minutes | |
177 | 'actor-keys': 60000 * 20, // 20 minutes | |
178 | 'videos-views': undefined, // Unlimited | |
179 | 'activitypub-refresher': 60000 * 10, // 10 minutes | |
180 | 'video-redundancy': 1000 * 3600 * 3, // 3 hours | |
181 | 'video-live-ending': 1000 * 60 * 10 // 10 minutes | |
182 | } | |
183 | const REPEAT_JOBS: { [ id: string ]: EveryRepeatOptions | CronRepeatOptions } = { | |
184 | 'videos-views': { | |
185 | cron: randomInt(1, 20) + ' * * * *' // Between 1-20 minutes past the hour | |
186 | }, | |
187 | 'activitypub-cleaner': { | |
188 | cron: '30 5 * * ' + randomInt(0, 7) // 1 time per week (random day) at 5:30 AM | |
189 | } | |
190 | } | |
191 | const JOB_PRIORITY = { | |
192 | TRANSCODING: 100 | |
193 | } | |
194 | ||
195 | const BROADCAST_CONCURRENCY = 30 // How many requests in parallel we do in activitypub-http-broadcast job | |
196 | const AP_CLEANER_CONCURRENCY = 10 // How many requests in parallel we do in activitypub-cleaner job | |
197 | const CRAWL_REQUEST_CONCURRENCY = 1 // How many requests in parallel to fetch remote data (likes, shares...) | |
198 | const REQUEST_TIMEOUT = 7000 // 7 seconds | |
199 | const JOB_COMPLETED_LIFETIME = 60000 * 60 * 24 * 2 // 2 days | |
200 | const VIDEO_IMPORT_TIMEOUT = 1000 * 3600 // 1 hour | |
201 | ||
202 | const SCHEDULER_INTERVALS_MS = { | |
203 | actorFollowScores: 60000 * 60, // 1 hour | |
204 | removeOldJobs: 60000 * 60, // 1 hour | |
205 | updateVideos: 60000, // 1 minute | |
206 | youtubeDLUpdate: 60000 * 60 * 24, // 1 day | |
207 | checkPlugins: CONFIG.PLUGINS.INDEX.CHECK_LATEST_VERSIONS_INTERVAL, | |
208 | checkPeerTubeVersion: 60000 * 60 * 24, // 1 day | |
209 | autoFollowIndexInstances: 60000 * 60 * 24, // 1 day | |
210 | removeOldViews: 60000 * 60 * 24, // 1 day | |
211 | removeOldHistory: 60000 * 60 * 24, // 1 day | |
212 | updateInboxStats: 1000 * 60, // 1 minute | |
213 | removeDanglingResumableUploads: 60000 * 60 * 16 // 16 hours | |
214 | } | |
215 | ||
216 | // --------------------------------------------------------------------------- | |
217 | ||
218 | const CONSTRAINTS_FIELDS = { | |
219 | USERS: { | |
220 | NAME: { min: 1, max: 120 }, // Length | |
221 | DESCRIPTION: { min: 3, max: 1000 }, // Length | |
222 | USERNAME: { min: 1, max: 50 }, // Length | |
223 | PASSWORD: { min: 6, max: 255 }, // Length | |
224 | VIDEO_QUOTA: { min: -1 }, | |
225 | VIDEO_QUOTA_DAILY: { min: -1 }, | |
226 | VIDEO_LANGUAGES: { max: 500 }, // Array length | |
227 | BLOCKED_REASON: { min: 3, max: 250 } // Length | |
228 | }, | |
229 | ABUSES: { | |
230 | REASON: { min: 2, max: 3000 }, // Length | |
231 | MODERATION_COMMENT: { min: 2, max: 3000 } // Length | |
232 | }, | |
233 | ABUSE_MESSAGES: { | |
234 | MESSAGE: { min: 2, max: 3000 } // Length | |
235 | }, | |
236 | VIDEO_BLACKLIST: { | |
237 | REASON: { min: 2, max: 300 } // Length | |
238 | }, | |
239 | VIDEO_CHANNELS: { | |
240 | NAME: { min: 1, max: 120 }, // Length | |
241 | DESCRIPTION: { min: 3, max: 1000 }, // Length | |
242 | SUPPORT: { min: 3, max: 1000 }, // Length | |
243 | URL: { min: 3, max: 2000 } // Length | |
244 | }, | |
245 | VIDEO_CAPTIONS: { | |
246 | CAPTION_FILE: { | |
247 | EXTNAME: [ '.vtt', '.srt' ], | |
248 | FILE_SIZE: { | |
249 | max: 4 * 1024 * 1024 // 4MB | |
250 | } | |
251 | } | |
252 | }, | |
253 | VIDEO_IMPORTS: { | |
254 | URL: { min: 3, max: 2000 }, // Length | |
255 | TORRENT_NAME: { min: 3, max: 255 }, // Length | |
256 | TORRENT_FILE: { | |
257 | EXTNAME: [ '.torrent' ], | |
258 | FILE_SIZE: { | |
259 | max: 1024 * 200 // 200 KB | |
260 | } | |
261 | } | |
262 | }, | |
263 | VIDEOS_REDUNDANCY: { | |
264 | URL: { min: 3, max: 2000 } // Length | |
265 | }, | |
266 | VIDEO_RATES: { | |
267 | URL: { min: 3, max: 2000 } // Length | |
268 | }, | |
269 | VIDEOS: { | |
270 | NAME: { min: 3, max: 120 }, // Length | |
271 | LANGUAGE: { min: 1, max: 10 }, // Length | |
272 | TRUNCATED_DESCRIPTION: { min: 3, max: 250 }, // Length | |
273 | DESCRIPTION: { min: 3, max: 10000 }, // Length | |
274 | SUPPORT: { min: 3, max: 1000 }, // Length | |
275 | IMAGE: { | |
276 | EXTNAME: [ '.png', '.jpg', '.jpeg', '.webp' ], | |
277 | FILE_SIZE: { | |
278 | max: 4 * 1024 * 1024 // 4MB | |
279 | } | |
280 | }, | |
281 | EXTNAME: [] as string[], | |
282 | INFO_HASH: { min: 40, max: 40 }, // Length, info hash is 20 bytes length but we represent it in hexadecimal so 20 * 2 | |
283 | DURATION: { min: 0 }, // Number | |
284 | TAGS: { min: 0, max: 5 }, // Number of total tags | |
285 | TAG: { min: 2, max: 30 }, // Length | |
286 | VIEWS: { min: 0 }, | |
287 | LIKES: { min: 0 }, | |
288 | DISLIKES: { min: 0 }, | |
289 | FILE_SIZE: { min: -1 }, | |
290 | PARTIAL_UPLOAD_SIZE: { max: 50 * 1024 * 1024 * 1024 }, // 50GB | |
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: 4 * 1024 * 1024 // 4MB | |
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 | IMAGE: { | |
309 | EXTNAME: [ '.png', '.jpeg', '.jpg', '.gif', '.webp' ], | |
310 | FILE_SIZE: { | |
311 | max: 4 * 1024 * 1024 // 4MB | |
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/gif': '.gif', | |
470 | 'image/webp': '.webp', | |
471 | 'image/jpg': '.jpg', | |
472 | 'image/jpeg': '.jpg' | |
473 | }, | |
474 | EXT_MIMETYPE: null as { [ id: string ]: string } | |
475 | }, | |
476 | VIDEO_CAPTIONS: { | |
477 | MIMETYPE_EXT: { | |
478 | 'text/vtt': '.vtt', | |
479 | 'application/x-subrip': '.srt', | |
480 | 'text/plain': '.srt' | |
481 | } | |
482 | }, | |
483 | TORRENT: { | |
484 | MIMETYPE_EXT: { | |
485 | 'application/x-bittorrent': '.torrent' | |
486 | } | |
487 | } | |
488 | } | |
489 | MIMETYPES.AUDIO.EXT_MIMETYPE = invert(MIMETYPES.AUDIO.MIMETYPE_EXT) | |
490 | MIMETYPES.IMAGE.EXT_MIMETYPE = invert(MIMETYPES.IMAGE.MIMETYPE_EXT) | |
491 | ||
492 | // --------------------------------------------------------------------------- | |
493 | ||
494 | const OVERVIEWS = { | |
495 | VIDEOS: { | |
496 | SAMPLE_THRESHOLD: 6, | |
497 | SAMPLES_COUNT: 20 | |
498 | } | |
499 | } | |
500 | ||
501 | const VIDEO_CHANNELS = { | |
502 | MAX_PER_USER: 20 | |
503 | } | |
504 | ||
505 | // --------------------------------------------------------------------------- | |
506 | ||
507 | const SERVER_ACTOR_NAME = 'peertube' | |
508 | ||
509 | const ACTIVITY_PUB = { | |
510 | POTENTIAL_ACCEPT_HEADERS: [ | |
511 | 'application/activity+json', | |
512 | 'application/ld+json', | |
513 | 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' | |
514 | ], | |
515 | ACCEPT_HEADER: 'application/activity+json, application/ld+json', | |
516 | PUBLIC: 'https://www.w3.org/ns/activitystreams#Public', | |
517 | COLLECTION_ITEMS_PER_PAGE: 10, | |
518 | FETCH_PAGE_LIMIT: 2000, | |
519 | URL_MIME_TYPES: { | |
520 | VIDEO: [] as string[], | |
521 | TORRENT: [ 'application/x-bittorrent' ], | |
522 | MAGNET: [ 'application/x-bittorrent;x-scheme-handler/magnet' ] | |
523 | }, | |
524 | MAX_RECURSION_COMMENTS: 100, | |
525 | ACTOR_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2, // 2 days | |
526 | VIDEO_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2, // 2 days | |
527 | VIDEO_PLAYLIST_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2 // 2 days | |
528 | } | |
529 | ||
530 | const ACTIVITY_PUB_ACTOR_TYPES: { [ id: string ]: ActivityPubActorType } = { | |
531 | GROUP: 'Group', | |
532 | PERSON: 'Person', | |
533 | APPLICATION: 'Application', | |
534 | ORGANIZATION: 'Organization', | |
535 | SERVICE: 'Service' | |
536 | } | |
537 | ||
538 | const HTTP_SIGNATURE = { | |
539 | HEADER_NAME: 'signature', | |
540 | ALGORITHM: 'rsa-sha256', | |
541 | HEADERS_TO_SIGN: [ '(request-target)', 'host', 'date', 'digest' ], | |
542 | REQUIRED_HEADERS: { | |
543 | ALL: [ '(request-target)', 'host', 'date' ], | |
544 | POST: [ '(request-target)', 'host', 'date', 'digest' ] | |
545 | }, | |
546 | CLOCK_SKEW_SECONDS: 1800 | |
547 | } | |
548 | ||
549 | // --------------------------------------------------------------------------- | |
550 | ||
551 | let PRIVATE_RSA_KEY_SIZE = 2048 | |
552 | ||
553 | // Password encryption | |
554 | const BCRYPT_SALT_SIZE = 10 | |
555 | ||
556 | const USER_PASSWORD_RESET_LIFETIME = 60000 * 60 // 60 minutes | |
557 | const USER_PASSWORD_CREATE_LIFETIME = 60000 * 60 * 24 * 7 // 7 days | |
558 | ||
559 | const USER_EMAIL_VERIFY_LIFETIME = 60000 * 60 // 60 minutes | |
560 | ||
561 | const NSFW_POLICY_TYPES: { [ id: string ]: NSFWPolicyType } = { | |
562 | DO_NOT_LIST: 'do_not_list', | |
563 | BLUR: 'blur', | |
564 | DISPLAY: 'display' | |
565 | } | |
566 | ||
567 | // --------------------------------------------------------------------------- | |
568 | ||
569 | // Express static paths (router) | |
570 | const STATIC_PATHS = { | |
571 | THUMBNAILS: '/static/thumbnails/', | |
572 | TORRENTS: '/static/torrents/', | |
573 | WEBSEED: '/static/webseed/', | |
574 | REDUNDANCY: '/static/redundancy/', | |
575 | STREAMING_PLAYLISTS: { | |
576 | HLS: '/static/streaming-playlists/hls' | |
577 | } | |
578 | } | |
579 | const STATIC_DOWNLOAD_PATHS = { | |
580 | TORRENTS: '/download/torrents/', | |
581 | VIDEOS: '/download/videos/', | |
582 | HLS_VIDEOS: '/download/streaming-playlists/hls/videos/' | |
583 | } | |
584 | const LAZY_STATIC_PATHS = { | |
585 | BANNERS: '/lazy-static/banners/', | |
586 | AVATARS: '/lazy-static/avatars/', | |
587 | PREVIEWS: '/lazy-static/previews/', | |
588 | VIDEO_CAPTIONS: '/lazy-static/video-captions/', | |
589 | TORRENTS: '/lazy-static/torrents/' | |
590 | } | |
591 | ||
592 | // Cache control | |
593 | const STATIC_MAX_AGE = { | |
594 | SERVER: '2h', | |
595 | LAZY_SERVER: '2d', | |
596 | CLIENT: '30d' | |
597 | } | |
598 | ||
599 | // Videos thumbnail size | |
600 | const THUMBNAILS_SIZE = { | |
601 | width: 280, | |
602 | height: 157, | |
603 | minWidth: 150 | |
604 | } | |
605 | const PREVIEWS_SIZE = { | |
606 | width: 850, | |
607 | height: 480, | |
608 | minWidth: 400 | |
609 | } | |
610 | const ACTOR_IMAGES_SIZE = { | |
611 | AVATARS: { | |
612 | width: 120, | |
613 | height: 120 | |
614 | }, | |
615 | BANNERS: { | |
616 | width: 1920, | |
617 | height: 317 // 6/1 ratio | |
618 | } | |
619 | } | |
620 | ||
621 | const EMBED_SIZE = { | |
622 | width: 560, | |
623 | height: 315 | |
624 | } | |
625 | ||
626 | // Sub folders of cache directory | |
627 | const FILES_CACHE = { | |
628 | PREVIEWS: { | |
629 | DIRECTORY: join(CONFIG.STORAGE.CACHE_DIR, 'previews'), | |
630 | MAX_AGE: 1000 * 3600 * 3 // 3 hours | |
631 | }, | |
632 | VIDEO_CAPTIONS: { | |
633 | DIRECTORY: join(CONFIG.STORAGE.CACHE_DIR, 'video-captions'), | |
634 | MAX_AGE: 1000 * 3600 * 3 // 3 hours | |
635 | }, | |
636 | TORRENTS: { | |
637 | DIRECTORY: join(CONFIG.STORAGE.CACHE_DIR, 'torrents'), | |
638 | MAX_AGE: 1000 * 3600 * 3 // 3 hours | |
639 | } | |
640 | } | |
641 | ||
642 | const LRU_CACHE = { | |
643 | USER_TOKENS: { | |
644 | MAX_SIZE: 1000 | |
645 | }, | |
646 | ACTOR_IMAGE_STATIC: { | |
647 | MAX_SIZE: 500 | |
648 | } | |
649 | } | |
650 | ||
651 | const RESUMABLE_UPLOAD_DIRECTORY = join(CONFIG.STORAGE.TMP_DIR, 'resumable-uploads') | |
652 | const HLS_STREAMING_PLAYLIST_DIRECTORY = join(CONFIG.STORAGE.STREAMING_PLAYLISTS_DIR, 'hls') | |
653 | const HLS_REDUNDANCY_DIRECTORY = join(CONFIG.STORAGE.REDUNDANCY_DIR, 'hls') | |
654 | ||
655 | const VIDEO_LIVE = { | |
656 | EXTENSION: '.ts', | |
657 | CLEANUP_DELAY: 1000 * 60 * 5, // 5 minutes | |
658 | SEGMENT_TIME_SECONDS: 4, // 4 seconds | |
659 | SEGMENTS_LIST_SIZE: 15, // 15 maximum segments in live playlist | |
660 | REPLAY_DIRECTORY: 'replay', | |
661 | EDGE_LIVE_DELAY_SEGMENTS_NOTIFICATION: 4, | |
662 | MAX_SOCKET_WAITING_DATA: 1024 * 1000 * 100, // 100MB | |
663 | RTMP: { | |
664 | CHUNK_SIZE: 60000, | |
665 | GOP_CACHE: true, | |
666 | PING: 60, | |
667 | PING_TIMEOUT: 30, | |
668 | BASE_PATH: 'live' | |
669 | } | |
670 | } | |
671 | ||
672 | const MEMOIZE_TTL = { | |
673 | OVERVIEWS_SAMPLE: 1000 * 3600 * 4, // 4 hours | |
674 | INFO_HASH_EXISTS: 1000 * 3600 * 12, // 12 hours | |
675 | LIVE_ABLE_TO_UPLOAD: 1000 * 60, // 1 minute | |
676 | LIVE_CHECK_SOCKET_HEALTH: 1000 * 60 // 1 minute | |
677 | } | |
678 | ||
679 | const MEMOIZE_LENGTH = { | |
680 | INFO_HASH_EXISTS: 200 | |
681 | } | |
682 | ||
683 | const QUEUE_CONCURRENCY = { | |
684 | ACTOR_PROCESS_IMAGE: 3 | |
685 | } | |
686 | ||
687 | const REDUNDANCY = { | |
688 | VIDEOS: { | |
689 | RANDOMIZED_FACTOR: 5 | |
690 | } | |
691 | } | |
692 | ||
693 | const ACCEPT_HEADERS = [ 'html', 'application/json' ].concat(ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS) | |
694 | ||
695 | const ASSETS_PATH = { | |
696 | DEFAULT_AUDIO_BACKGROUND: join(root(), 'dist', 'server', 'assets', 'default-audio-background.jpg'), | |
697 | DEFAULT_LIVE_BACKGROUND: join(root(), 'dist', 'server', 'assets', 'default-live-background.jpg') | |
698 | } | |
699 | ||
700 | // --------------------------------------------------------------------------- | |
701 | ||
702 | const CUSTOM_HTML_TAG_COMMENTS = { | |
703 | TITLE: '<!-- title tag -->', | |
704 | DESCRIPTION: '<!-- description tag -->', | |
705 | CUSTOM_CSS: '<!-- custom css tag -->', | |
706 | META_TAGS: '<!-- meta tags -->', | |
707 | SERVER_CONFIG: '<!-- server config -->' | |
708 | } | |
709 | ||
710 | // --------------------------------------------------------------------------- | |
711 | ||
712 | const FEEDS = { | |
713 | COUNT: 20 | |
714 | } | |
715 | ||
716 | const MAX_LOGS_OUTPUT_CHARACTERS = 10 * 1000 * 1000 | |
717 | const LOG_FILENAME = 'peertube.log' | |
718 | const AUDIT_LOG_FILENAME = 'peertube-audit.log' | |
719 | ||
720 | // --------------------------------------------------------------------------- | |
721 | ||
722 | const TRACKER_RATE_LIMITS = { | |
723 | INTERVAL: 60000 * 5, // 5 minutes | |
724 | ANNOUNCES_PER_IP_PER_INFOHASH: 15, // maximum announces per torrent in the interval | |
725 | ANNOUNCES_PER_IP: 30, // maximum announces for all our torrents in the interval | |
726 | BLOCK_IP_LIFETIME: 60000 * 3 // 3 minutes | |
727 | } | |
728 | ||
729 | const P2P_MEDIA_LOADER_PEER_VERSION = 2 | |
730 | ||
731 | // --------------------------------------------------------------------------- | |
732 | ||
733 | const PLUGIN_GLOBAL_CSS_FILE_NAME = 'plugins-global.css' | |
734 | const PLUGIN_GLOBAL_CSS_PATH = join(CONFIG.STORAGE.TMP_DIR, PLUGIN_GLOBAL_CSS_FILE_NAME) | |
735 | ||
736 | let PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME = 1000 * 60 * 5 // 5 minutes | |
737 | ||
738 | const DEFAULT_THEME_NAME = 'default' | |
739 | const DEFAULT_USER_THEME_NAME = 'instance-default' | |
740 | ||
741 | // --------------------------------------------------------------------------- | |
742 | ||
743 | const SEARCH_INDEX = { | |
744 | ROUTES: { | |
745 | VIDEOS: '/api/v1/search/videos', | |
746 | VIDEO_CHANNELS: '/api/v1/search/video-channels' | |
747 | } | |
748 | } | |
749 | ||
750 | // --------------------------------------------------------------------------- | |
751 | ||
752 | // Special constants for a test instance | |
753 | if (isTestInstance() === true) { | |
754 | PRIVATE_RSA_KEY_SIZE = 1024 | |
755 | ||
756 | ACTOR_FOLLOW_SCORE.BASE = 20 | |
757 | ||
758 | REMOTE_SCHEME.HTTP = 'http' | |
759 | REMOTE_SCHEME.WS = 'ws' | |
760 | ||
761 | STATIC_MAX_AGE.SERVER = '0' | |
762 | ||
763 | ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE = 2 | |
764 | ACTIVITY_PUB.ACTOR_REFRESH_INTERVAL = 10 * 1000 // 10 seconds | |
765 | ACTIVITY_PUB.VIDEO_REFRESH_INTERVAL = 10 * 1000 // 10 seconds | |
766 | ACTIVITY_PUB.VIDEO_PLAYLIST_REFRESH_INTERVAL = 10 * 1000 // 10 seconds | |
767 | ||
768 | CONSTRAINTS_FIELDS.ACTORS.IMAGE.FILE_SIZE.max = 100 * 1024 // 100KB | |
769 | CONSTRAINTS_FIELDS.VIDEOS.IMAGE.FILE_SIZE.max = 400 * 1024 // 400KB | |
770 | ||
771 | SCHEDULER_INTERVALS_MS.actorFollowScores = 1000 | |
772 | SCHEDULER_INTERVALS_MS.removeOldJobs = 10000 | |
773 | SCHEDULER_INTERVALS_MS.removeOldHistory = 5000 | |
774 | SCHEDULER_INTERVALS_MS.removeOldViews = 5000 | |
775 | SCHEDULER_INTERVALS_MS.updateVideos = 5000 | |
776 | SCHEDULER_INTERVALS_MS.autoFollowIndexInstances = 5000 | |
777 | SCHEDULER_INTERVALS_MS.updateInboxStats = 5000 | |
778 | SCHEDULER_INTERVALS_MS.checkPeerTubeVersion = 2000 | |
779 | REPEAT_JOBS['videos-views'] = { every: 5000 } | |
780 | REPEAT_JOBS['activitypub-cleaner'] = { every: 5000 } | |
781 | ||
782 | REDUNDANCY.VIDEOS.RANDOMIZED_FACTOR = 1 | |
783 | ||
784 | VIEW_LIFETIME.VIDEO = 1000 // 1 second | |
785 | VIEW_LIFETIME.LIVE = 1000 * 5 // 5 second | |
786 | CONTACT_FORM_LIFETIME = 1000 // 1 second | |
787 | ||
788 | JOB_ATTEMPTS['email'] = 1 | |
789 | ||
790 | FILES_CACHE.VIDEO_CAPTIONS.MAX_AGE = 3000 | |
791 | MEMOIZE_TTL.OVERVIEWS_SAMPLE = 3000 | |
792 | MEMOIZE_TTL.LIVE_ABLE_TO_UPLOAD = 3000 | |
793 | OVERVIEWS.VIDEOS.SAMPLE_THRESHOLD = 2 | |
794 | ||
795 | PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME = 5000 | |
796 | ||
797 | VIDEO_LIVE.CLEANUP_DELAY = 5000 | |
798 | VIDEO_LIVE.SEGMENT_TIME_SECONDS = 2 | |
799 | VIDEO_LIVE.EDGE_LIVE_DELAY_SEGMENTS_NOTIFICATION = 1 | |
800 | } | |
801 | ||
802 | updateWebserverUrls() | |
803 | updateWebserverConfig() | |
804 | ||
805 | registerConfigChangedHandler(() => { | |
806 | updateWebserverUrls() | |
807 | updateWebserverConfig() | |
808 | }) | |
809 | ||
810 | // --------------------------------------------------------------------------- | |
811 | ||
812 | const FILES_CONTENT_HASH = { | |
813 | MANIFEST: generateContentHash(), | |
814 | FAVICON: generateContentHash(), | |
815 | LOGO: generateContentHash() | |
816 | } | |
817 | ||
818 | // --------------------------------------------------------------------------- | |
819 | ||
820 | export { | |
821 | WEBSERVER, | |
822 | API_VERSION, | |
823 | VIDEO_LIVE, | |
824 | PEERTUBE_VERSION, | |
825 | LAZY_STATIC_PATHS, | |
826 | SEARCH_INDEX, | |
827 | RESUMABLE_UPLOAD_DIRECTORY, | |
828 | HLS_REDUNDANCY_DIRECTORY, | |
829 | P2P_MEDIA_LOADER_PEER_VERSION, | |
830 | ACTOR_IMAGES_SIZE, | |
831 | ACCEPT_HEADERS, | |
832 | BCRYPT_SALT_SIZE, | |
833 | TRACKER_RATE_LIMITS, | |
834 | FILES_CACHE, | |
835 | LOG_FILENAME, | |
836 | CONSTRAINTS_FIELDS, | |
837 | EMBED_SIZE, | |
838 | REDUNDANCY, | |
839 | JOB_CONCURRENCY, | |
840 | JOB_ATTEMPTS, | |
841 | AP_CLEANER_CONCURRENCY, | |
842 | LAST_MIGRATION_VERSION, | |
843 | OAUTH_LIFETIME, | |
844 | CUSTOM_HTML_TAG_COMMENTS, | |
845 | BROADCAST_CONCURRENCY, | |
846 | AUDIT_LOG_FILENAME, | |
847 | PAGINATION, | |
848 | ACTOR_FOLLOW_SCORE, | |
849 | PREVIEWS_SIZE, | |
850 | REMOTE_SCHEME, | |
851 | FOLLOW_STATES, | |
852 | DEFAULT_USER_THEME_NAME, | |
853 | SERVER_ACTOR_NAME, | |
854 | PLUGIN_GLOBAL_CSS_FILE_NAME, | |
855 | PLUGIN_GLOBAL_CSS_PATH, | |
856 | PRIVATE_RSA_KEY_SIZE, | |
857 | ROUTE_CACHE_LIFETIME, | |
858 | SORTABLE_COLUMNS, | |
859 | HLS_STREAMING_PLAYLIST_DIRECTORY, | |
860 | FEEDS, | |
861 | JOB_TTL, | |
862 | DEFAULT_THEME_NAME, | |
863 | NSFW_POLICY_TYPES, | |
864 | STATIC_MAX_AGE, | |
865 | STATIC_PATHS, | |
866 | VIDEO_IMPORT_TIMEOUT, | |
867 | VIDEO_PLAYLIST_TYPES, | |
868 | MAX_LOGS_OUTPUT_CHARACTERS, | |
869 | ACTIVITY_PUB, | |
870 | ACTIVITY_PUB_ACTOR_TYPES, | |
871 | THUMBNAILS_SIZE, | |
872 | VIDEO_CATEGORIES, | |
873 | MEMOIZE_LENGTH, | |
874 | VIDEO_LANGUAGES, | |
875 | VIDEO_PRIVACIES, | |
876 | VIDEO_LICENCES, | |
877 | VIDEO_STATES, | |
878 | QUEUE_CONCURRENCY, | |
879 | VIDEO_RATE_TYPES, | |
880 | JOB_PRIORITY, | |
881 | VIDEO_TRANSCODING_FPS, | |
882 | FFMPEG_NICE, | |
883 | ABUSE_STATES, | |
884 | VIDEO_CHANNELS, | |
885 | LRU_CACHE, | |
886 | REQUEST_TIMEOUT, | |
887 | USER_PASSWORD_RESET_LIFETIME, | |
888 | USER_PASSWORD_CREATE_LIFETIME, | |
889 | MEMOIZE_TTL, | |
890 | USER_EMAIL_VERIFY_LIFETIME, | |
891 | OVERVIEWS, | |
892 | SCHEDULER_INTERVALS_MS, | |
893 | REPEAT_JOBS, | |
894 | STATIC_DOWNLOAD_PATHS, | |
895 | MIMETYPES, | |
896 | CRAWL_REQUEST_CONCURRENCY, | |
897 | DEFAULT_AUDIO_RESOLUTION, | |
898 | JOB_COMPLETED_LIFETIME, | |
899 | HTTP_SIGNATURE, | |
900 | VIDEO_IMPORT_STATES, | |
901 | VIEW_LIFETIME, | |
902 | CONTACT_FORM_LIFETIME, | |
903 | VIDEO_PLAYLIST_PRIVACIES, | |
904 | PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME, | |
905 | ASSETS_PATH, | |
906 | FILES_CONTENT_HASH, | |
907 | loadLanguages, | |
908 | buildLanguages, | |
909 | generateContentHash | |
910 | } | |
911 | ||
912 | // --------------------------------------------------------------------------- | |
913 | ||
914 | function buildVideoMimetypeExt () { | |
915 | const data = { | |
916 | // streamable formats that warrant cross-browser compatibility | |
917 | 'video/webm': '.webm', | |
918 | // We'll add .ogg if additional extensions are enabled | |
919 | // We could add .ogg here but since it could be an audio file, | |
920 | // it would be confusing for users because PeerTube will refuse their file (based on the mimetype) | |
921 | 'video/ogg': [ '.ogv' ], | |
922 | 'video/mp4': '.mp4' | |
923 | } | |
924 | ||
925 | if (CONFIG.TRANSCODING.ENABLED) { | |
926 | if (CONFIG.TRANSCODING.ALLOW_ADDITIONAL_EXTENSIONS) { | |
927 | data['video/ogg'].push('.ogg') | |
928 | ||
929 | Object.assign(data, { | |
930 | 'video/x-matroska': '.mkv', | |
931 | ||
932 | // Developed by Apple | |
933 | 'video/quicktime': [ '.mov', '.qt', '.mqv' ], // often used as output format by editing software | |
934 | 'video/x-m4v': '.m4v', | |
935 | 'video/m4v': '.m4v', | |
936 | ||
937 | // Developed by the Adobe Flash Platform | |
938 | 'video/x-flv': '.flv', | |
939 | 'video/x-f4v': '.f4v', // replacement for flv | |
940 | ||
941 | // Developed by Microsoft | |
942 | 'video/x-ms-wmv': '.wmv', | |
943 | 'video/x-msvideo': '.avi', | |
944 | 'video/avi': '.avi', | |
945 | ||
946 | // Developed by 3GPP | |
947 | // common video formats for cell phones | |
948 | 'video/3gpp': [ '.3gp', '.3gpp' ], | |
949 | 'video/3gpp2': [ '.3g2', '.3gpp2' ], | |
950 | ||
951 | // Developed by FFmpeg/Mplayer | |
952 | 'application/x-nut': '.nut', | |
953 | ||
954 | // The standard video format used by many Sony and Panasonic HD camcorders. | |
955 | // It is also used for storing high definition video on Blu-ray discs. | |
956 | 'video/mp2t': '.mts', | |
957 | 'video/m2ts': '.m2ts', | |
958 | ||
959 | // Old formats reliant on MPEG-1/MPEG-2 | |
960 | 'video/mpv': '.mpv', | |
961 | 'video/mpeg2': '.m2v', | |
962 | 'video/mpeg': [ '.m1v', '.mpg', '.mpe', '.mpeg', '.vob' ], | |
963 | 'video/dvd': '.vob', | |
964 | ||
965 | // Could be anything | |
966 | 'application/octet-stream': null, | |
967 | 'application/mxf': '.mxf' // often used as exchange format by editing software | |
968 | }) | |
969 | } | |
970 | ||
971 | if (CONFIG.TRANSCODING.ALLOW_AUDIO_FILES) { | |
972 | Object.assign(data, MIMETYPES.AUDIO.MIMETYPE_EXT) | |
973 | } | |
974 | } | |
975 | ||
976 | return data | |
977 | } | |
978 | ||
979 | function updateWebserverUrls () { | |
980 | WEBSERVER.URL = sanitizeUrl(CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT) | |
981 | WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT, REMOTE_SCHEME.HTTP) | |
982 | WEBSERVER.WS = CONFIG.WEBSERVER.WS | |
983 | ||
984 | WEBSERVER.SCHEME = CONFIG.WEBSERVER.SCHEME | |
985 | WEBSERVER.HOSTNAME = CONFIG.WEBSERVER.HOSTNAME | |
986 | WEBSERVER.PORT = CONFIG.WEBSERVER.PORT | |
987 | ||
988 | WEBSERVER.RTMP_URL = 'rtmp://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.LIVE.RTMP.PORT + '/' + VIDEO_LIVE.RTMP.BASE_PATH | |
989 | } | |
990 | ||
991 | function updateWebserverConfig () { | |
992 | MIMETYPES.VIDEO.MIMETYPE_EXT = buildVideoMimetypeExt() | |
993 | MIMETYPES.VIDEO.MIMETYPES_REGEX = buildMimetypesRegex(MIMETYPES.VIDEO.MIMETYPE_EXT) | |
994 | ||
995 | ACTIVITY_PUB.URL_MIME_TYPES.VIDEO = Object.keys(MIMETYPES.VIDEO.MIMETYPE_EXT) | |
996 | ||
997 | MIMETYPES.VIDEO.EXT_MIMETYPE = buildVideoExtMimetype(MIMETYPES.VIDEO.MIMETYPE_EXT) | |
998 | ||
999 | CONSTRAINTS_FIELDS.VIDEOS.EXTNAME = Object.keys(MIMETYPES.VIDEO.EXT_MIMETYPE) | |
1000 | } | |
1001 | ||
1002 | function buildVideoExtMimetype (obj: { [ id: string ]: string | string[] }) { | |
1003 | const result: { [id: string]: string } = {} | |
1004 | ||
1005 | for (const mimetype of Object.keys(obj)) { | |
1006 | const value = obj[mimetype] | |
1007 | if (!value) continue | |
1008 | ||
1009 | const extensions = Array.isArray(value) ? value : [ value ] | |
1010 | ||
1011 | for (const extension of extensions) { | |
1012 | result[extension] = mimetype | |
1013 | } | |
1014 | } | |
1015 | ||
1016 | return result | |
1017 | } | |
1018 | ||
1019 | function buildMimetypesRegex (obj: { [id: string]: string | string[] }) { | |
1020 | return Object.keys(obj) | |
1021 | .map(m => `(${m})`) | |
1022 | .join('|') | |
1023 | } | |
1024 | ||
1025 | function loadLanguages () { | |
1026 | Object.assign(VIDEO_LANGUAGES, buildLanguages()) | |
1027 | } | |
1028 | ||
1029 | function buildLanguages () { | |
1030 | const iso639 = require('iso-639-3') | |
1031 | ||
1032 | const languages: { [id: string]: string } = {} | |
1033 | ||
1034 | const additionalLanguages = { | |
1035 | sgn: true, // Sign languages (macro language) | |
1036 | ase: true, // American sign language | |
1037 | sdl: true, // Arabian sign language | |
1038 | bfi: true, // British sign language | |
1039 | bzs: true, // Brazilian sign language | |
1040 | csl: true, // Chinese sign language | |
1041 | cse: true, // Czech sign language | |
1042 | dsl: true, // Danish sign language | |
1043 | fsl: true, // French sign language | |
1044 | gsg: true, // German sign language | |
1045 | pks: true, // Pakistan sign language | |
1046 | jsl: true, // Japanese sign language | |
1047 | sfs: true, // South African sign language | |
1048 | swl: true, // Swedish sign language | |
1049 | rsl: true, // Russian sign language | |
1050 | ||
1051 | kab: true, // Kabyle | |
1052 | ||
1053 | epo: true, // Esperanto | |
1054 | tlh: true, // Klingon | |
1055 | jbo: true, // Lojban | |
1056 | avk: true // Kotava | |
1057 | } | |
1058 | ||
1059 | // Only add ISO639-1 languages and some sign languages (ISO639-3) | |
1060 | iso639 | |
1061 | .filter(l => { | |
1062 | return (l.iso6391 !== undefined && l.type === 'living') || | |
1063 | additionalLanguages[l.iso6393] === true | |
1064 | }) | |
1065 | .forEach(l => { languages[l.iso6391 || l.iso6393] = l.name }) | |
1066 | ||
1067 | // Override Occitan label | |
1068 | languages['oc'] = 'Occitan' | |
1069 | languages['el'] = 'Greek' | |
1070 | ||
1071 | return languages | |
1072 | } | |
1073 | ||
1074 | function generateContentHash () { | |
1075 | return randomBytes(20).toString('hex') | |
1076 | } |