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