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