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