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