]>
Commit | Line | Data |
---|---|---|
adbf1ed8 | 1 | import { randomInt } from '../../shared/core-utils/miscs/miscs' |
0223291c | 2 | import { CronRepeatOptions, EveryRepeatOptions } from 'bull' |
adbf1ed8 | 3 | import { randomBytes } from 'crypto' |
0223291c | 4 | import { invert } from 'lodash' |
6dd9de95 | 5 | import { join } from 'path' |
d95d1559 C |
6 | import { |
7 | AbuseState, | |
0223291c | 8 | JobType, |
d95d1559 C |
9 | VideoImportState, |
10 | VideoPrivacy, | |
d95d1559 C |
11 | VideoRateType, |
12 | VideoResolution, | |
0223291c C |
13 | VideoState, |
14 | VideoTranscodingFPS | |
d95d1559 | 15 | } from '../../shared/models' |
0223291c C |
16 | import { ActivityPubActorType } from '../../shared/models/activitypub' |
17 | import { FollowState } from '../../shared/models/actors' | |
0883b324 | 18 | import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type' |
418d092a | 19 | import { VideoPlaylistPrivacy } from '../../shared/models/videos/playlist/video-playlist-privacy.model' |
df0b219d | 20 | import { VideoPlaylistType } from '../../shared/models/videos/playlist/video-playlist-type.model' |
0223291c C |
21 | // Do not use barrels, remain constants as independent as possible |
22 | import { isTestInstance, root, sanitizeHost, sanitizeUrl } from '../helpers/core-utils' | |
6dd9de95 | 23 | import { CONFIG, registerConfigChangedHandler } from './config' |
ee9e7b61 | 24 | |
9f6bae3a C |
25 | // --------------------------------------------------------------------------- |
26 | ||
2af337c8 | 27 | const LAST_MIGRATION_VERSION = 550 |
5804c0db C |
28 | |
29 | // --------------------------------------------------------------------------- | |
30 | ||
f0f5567b | 31 | const API_VERSION = 'v1' |
9fa6ca16 | 32 | const PEERTUBE_VERSION = require(join(root(), 'package.json')).version |
9f10b292 | 33 | |
1194e8b4 | 34 | const PAGINATION = { |
e0b56b74 C |
35 | GLOBAL: { |
36 | COUNT: { | |
37 | DEFAULT: 15, | |
38 | MAX: 100 | |
39 | } | |
40 | }, | |
41 | OUTBOX: { | |
42 | COUNT: { | |
43 | MAX: 50 | |
44 | } | |
1194e8b4 C |
45 | } |
46 | } | |
9f6bae3a | 47 | |
6dd9de95 C |
48 | const WEBSERVER = { |
49 | URL: '', | |
50 | HOST: '', | |
51 | SCHEME: '', | |
52 | WS: '', | |
53 | HOSTNAME: '', | |
c6c0fa6c C |
54 | PORT: 0, |
55 | RTMP_URL: '' | |
6dd9de95 C |
56 | } |
57 | ||
9f6bae3a C |
58 | // Sortable columns per schema |
59 | const SORTABLE_COLUMNS = { | |
654a188f | 60 | USERS: [ 'id', 'username', 'videoQuotaUsed', 'createdAt', 'lastLoginDate', 'role' ], |
06a05d5f | 61 | USER_SUBSCRIPTIONS: [ 'id', 'createdAt' ], |
265ba139 | 62 | ACCOUNTS: [ 'createdAt' ], |
94a5ff8a | 63 | JOBS: [ 'createdAt' ], |
72c7248b | 64 | VIDEO_CHANNELS: [ 'id', 'name', 'updatedAt', 'createdAt' ], |
ed31c059 | 65 | VIDEO_IMPORTS: [ 'createdAt' ], |
c1125bca | 66 | VIDEO_COMMENT_THREADS: [ 'createdAt', 'totalReplies' ], |
c100a614 | 67 | VIDEO_RATES: [ 'createdAt' ], |
7a7724e6 | 68 | BLACKLISTS: [ 'id', 'name', 'duration', 'views', 'likes', 'dislikes', 'uuid', 'createdAt' ], |
cb5ce4cb C |
69 | FOLLOWERS: [ 'createdAt', 'state', 'score' ], |
70 | FOLLOWING: [ 'createdAt', 'redundancyAllowed', 'state' ], | |
57c36b27 | 71 | |
2fd59d7d | 72 | VIDEOS: [ 'name', 'duration', 'createdAt', 'publishedAt', 'originallyPublishedAt', 'views', 'likes', 'trending' ], |
9a629c6e | 73 | |
5fb2e288 | 74 | // Don't forget to update peertube-search-index with the same values |
2fd59d7d | 75 | VIDEOS_SEARCH: [ 'name', 'duration', 'createdAt', 'publishedAt', 'originallyPublishedAt', 'views', 'likes', 'match' ], |
7ad9b984 C |
76 | VIDEO_CHANNELS_SEARCH: [ 'match', 'displayName', 'createdAt' ], |
77 | ||
d95d1559 C |
78 | ABUSES: [ 'id', 'createdAt', 'state' ], |
79 | ||
7ad9b984 | 80 | ACCOUNTS_BLOCKLIST: [ 'createdAt' ], |
cef534ed C |
81 | SERVERS_BLOCKLIST: [ 'createdAt' ], |
82 | ||
654a188f | 83 | USER_NOTIFICATIONS: [ 'createdAt', 'read' ], |
418d092a | 84 | |
ad91e700 C |
85 | VIDEO_PLAYLISTS: [ 'displayName', 'createdAt', 'updatedAt' ], |
86 | ||
6702a1b2 C |
87 | PLUGINS: [ 'name', 'createdAt', 'updatedAt' ], |
88 | ||
b764380a C |
89 | AVAILABLE_PLUGINS: [ 'npmName', 'popularity' ], |
90 | ||
91 | VIDEO_REDUNDANCIES: [ 'name' ] | |
9f6bae3a | 92 | } |
9f10b292 | 93 | |
2f372a86 | 94 | const OAUTH_LIFETIME = { |
ff193d5e | 95 | ACCESS_TOKEN: 3600 * 24, // 1 day, for upload |
2f372a86 C |
96 | REFRESH_TOKEN: 1209600 // 2 weeks |
97 | } | |
98 | ||
fd4484f1 | 99 | const ROUTE_CACHE_LIFETIME = { |
3f6d68d9 RK |
100 | FEEDS: '15 minutes', |
101 | ROBOTS: '2 hours', | |
2feebf3e | 102 | SITEMAP: '1 day', |
5447516b | 103 | SECURITYTXT: '2 hours', |
3f6d68d9 | 104 | NODEINFO: '10 minutes', |
aad0ec24 | 105 | DNT_POLICY: '1 week', |
fd4484f1 | 106 | ACTIVITY_PUB: { |
3f6d68d9 | 107 | VIDEOS: '1 second' // 1 second, cache concurrent requests after a broadcast for example |
4b5384f6 C |
108 | }, |
109 | STATS: '4 hours' | |
fd4484f1 C |
110 | } |
111 | ||
9f6bae3a | 112 | // --------------------------------------------------------------------------- |
26d7d31b | 113 | |
60650c77 C |
114 | // Number of points we add/remove after a successful/bad request |
115 | const ACTOR_FOLLOW_SCORE = { | |
225a89c2 C |
116 | PENALTY: -10, |
117 | BONUS: 10, | |
60650c77 C |
118 | BASE: 1000, |
119 | MAX: 10000 | |
225a89c2 C |
120 | } |
121 | ||
122 | const FOLLOW_STATES: { [ id: string ]: FollowState } = { | |
123 | PENDING: 'pending', | |
124 | ACCEPTED: 'accepted' | |
125 | } | |
126 | ||
127 | const REMOTE_SCHEME = { | |
128 | HTTP: 'https', | |
129 | WS: 'wss' | |
130 | } | |
131 | ||
b764380a | 132 | const JOB_ATTEMPTS: { [id in JobType]: number } = { |
94a5ff8a C |
133 | 'activitypub-http-broadcast': 5, |
134 | 'activitypub-http-unicast': 5, | |
135 | 'activitypub-http-fetcher': 5, | |
5350fd8e | 136 | 'activitypub-follow': 5, |
0138af92 | 137 | 'video-file-import': 1, |
a0327eed | 138 | 'video-transcoding': 1, |
fbad87b0 | 139 | 'video-import': 1, |
6b616860 | 140 | 'email': 5, |
04b8c3fb | 141 | 'videos-views': 1, |
b764380a | 142 | 'activitypub-refresher': 1, |
a5cf76af C |
143 | 'video-redundancy': 1, |
144 | 'video-live-ending': 1 | |
225a89c2 | 145 | } |
b764380a | 146 | const JOB_CONCURRENCY: { [id in JobType]: number } = { |
94a5ff8a C |
147 | 'activitypub-http-broadcast': 1, |
148 | 'activitypub-http-unicast': 5, | |
149 | 'activitypub-http-fetcher': 1, | |
ab4d4db4 | 150 | 'activitypub-follow': 1, |
0138af92 | 151 | 'video-file-import': 1, |
a0327eed | 152 | 'video-transcoding': 1, |
fbad87b0 | 153 | 'video-import': 1, |
6b616860 | 154 | 'email': 5, |
04b8c3fb | 155 | 'videos-views': 1, |
b764380a | 156 | 'activitypub-refresher': 1, |
a5cf76af | 157 | 'video-redundancy': 1, |
31c82cd9 | 158 | 'video-live-ending': 10 |
225a89c2 | 159 | } |
b764380a | 160 | const JOB_TTL: { [id in JobType]: number } = { |
2b86fe72 C |
161 | 'activitypub-http-broadcast': 60000 * 10, // 10 minutes |
162 | 'activitypub-http-unicast': 60000 * 10, // 10 minutes | |
d694b193 | 163 | 'activitypub-http-fetcher': 1000 * 3600 * 10, // 10 hours |
2b86fe72 C |
164 | 'activitypub-follow': 60000 * 10, // 10 minutes |
165 | 'video-file-import': 1000 * 3600, // 1 hour | |
a0327eed | 166 | 'video-transcoding': 1000 * 3600 * 48, // 2 days, transcoding could be long |
d694b193 | 167 | 'video-import': 1000 * 3600 * 2, // 2 hours |
6b616860 | 168 | 'email': 60000 * 10, // 10 minutes |
04b8c3fb | 169 | 'videos-views': undefined, // Unlimited |
b764380a | 170 | 'activitypub-refresher': 60000 * 10, // 10 minutes |
a5cf76af C |
171 | 'video-redundancy': 1000 * 3600 * 3, // 3 hours |
172 | 'video-live-ending': 1000 * 60 * 10 // 10 minutes | |
2b86fe72 | 173 | } |
6b616860 C |
174 | const REPEAT_JOBS: { [ id: string ]: EveryRepeatOptions | CronRepeatOptions } = { |
175 | 'videos-views': { | |
0223291c | 176 | cron: randomInt(1, 20) + ' * * * *' // Between 1-20 minutes past the hour |
6b616860 C |
177 | } |
178 | } | |
179 | ||
71e3dfda | 180 | const BROADCAST_CONCURRENCY = 10 // How many requests in parallel we do in activitypub-http-broadcast job |
240085d0 | 181 | const CRAWL_REQUEST_CONCURRENCY = 1 // How many requests in parallel to fetch remote data (likes, shares...) |
71e3dfda | 182 | const JOB_REQUEST_TIMEOUT = 3000 // 3 seconds |
71e3dfda | 183 | const JOB_COMPLETED_LIFETIME = 60000 * 60 * 24 * 2 // 2 days |
cf9166cf | 184 | const VIDEO_IMPORT_TIMEOUT = 1000 * 3600 // 1 hour |
225a89c2 | 185 | |
8f0bc73d | 186 | const SCHEDULER_INTERVALS_MS = { |
2f5c6b2f | 187 | actorFollowScores: 60000 * 60, // 1 hour |
bbe0f064 | 188 | removeOldJobs: 60000 * 60, // 1 hour |
ce32426b | 189 | updateVideos: 60000, // 1 minute |
8f0bc73d | 190 | youtubeDLUpdate: 60000 * 60 * 24, // 1 day |
d133f385 | 191 | checkPlugins: CONFIG.PLUGINS.INDEX.CHECK_LATEST_VERSIONS_INTERVAL, |
6f1b4fa4 | 192 | autoFollowIndexInstances: 60000 * 60 * 24, // 1 day |
cda03765 | 193 | removeOldViews: 60000 * 60 * 24, // 1 day |
8f0bc73d | 194 | removeOldHistory: 60000 * 60 * 24 // 1 day |
2baea0c7 | 195 | } |
60650c77 | 196 | |
225a89c2 C |
197 | // --------------------------------------------------------------------------- |
198 | ||
503c6f44 | 199 | const CONSTRAINTS_FIELDS = { |
e4c55619 | 200 | USERS: { |
9f7a1953 | 201 | NAME: { min: 1, max: 120 }, // Length |
d23e6a1c | 202 | DESCRIPTION: { min: 3, max: 1000 }, // Length |
d0ce42c1 | 203 | USERNAME: { min: 1, max: 50 }, // Length |
b0f9f39e | 204 | PASSWORD: { min: 6, max: 255 }, // Length |
eacb25c4 | 205 | VIDEO_QUOTA: { min: -1 }, |
bee0abff | 206 | VIDEO_QUOTA_DAILY: { min: -1 }, |
3caf77d3 | 207 | VIDEO_LANGUAGES: { max: 500 }, // Array length |
eacb25c4 | 208 | BLOCKED_REASON: { min: 3, max: 250 } // Length |
e4c55619 | 209 | }, |
d95d1559 | 210 | ABUSES: { |
1506307f C |
211 | REASON: { min: 2, max: 3000 }, // Length |
212 | MODERATION_COMMENT: { min: 2, max: 3000 } // Length | |
55fa55a9 | 213 | }, |
edbc9325 C |
214 | ABUSE_MESSAGES: { |
215 | MESSAGE: { min: 2, max: 3000 } // Length | |
216 | }, | |
26b7305a C |
217 | VIDEO_BLACKLIST: { |
218 | REASON: { min: 2, max: 300 } // Length | |
219 | }, | |
72c7248b | 220 | VIDEO_CHANNELS: { |
9f7a1953 | 221 | NAME: { min: 1, max: 120 }, // Length |
d23e6a1c BY |
222 | DESCRIPTION: { min: 3, max: 1000 }, // Length |
223 | SUPPORT: { min: 3, max: 1000 }, // Length | |
e34c85e5 | 224 | URL: { min: 3, max: 2000 } // Length |
72c7248b | 225 | }, |
40e87e9e C |
226 | VIDEO_CAPTIONS: { |
227 | CAPTION_FILE: { | |
f4001cf4 | 228 | EXTNAME: [ '.vtt', '.srt' ], |
40e87e9e C |
229 | FILE_SIZE: { |
230 | max: 2 * 1024 * 1024 // 2MB | |
231 | } | |
232 | } | |
233 | }, | |
fbad87b0 | 234 | VIDEO_IMPORTS: { |
ce33919c C |
235 | URL: { min: 3, max: 2000 }, // Length |
236 | TORRENT_NAME: { min: 3, max: 255 }, // Length | |
990b6a0b C |
237 | TORRENT_FILE: { |
238 | EXTNAME: [ '.torrent' ], | |
239 | FILE_SIZE: { | |
240 | max: 1024 * 200 // 200 KB | |
241 | } | |
242 | } | |
fbad87b0 | 243 | }, |
c48e82b5 C |
244 | VIDEOS_REDUNDANCY: { |
245 | URL: { min: 3, max: 2000 } // Length | |
246 | }, | |
5c6d985f C |
247 | VIDEO_RATES: { |
248 | URL: { min: 3, max: 2000 } // Length | |
249 | }, | |
e4c55619 | 250 | VIDEOS: { |
a265f7f3 | 251 | NAME: { min: 3, max: 120 }, // Length |
9d3ef9fe | 252 | LANGUAGE: { min: 1, max: 10 }, // Length |
9567011b | 253 | TRUNCATED_DESCRIPTION: { min: 3, max: 250 }, // Length |
2422c46b | 254 | DESCRIPTION: { min: 3, max: 10000 }, // Length |
d23e6a1c | 255 | SUPPORT: { min: 3, max: 1000 }, // Length |
ac81d1a0 C |
256 | IMAGE: { |
257 | EXTNAME: [ '.jpg', '.jpeg' ], | |
258 | FILE_SIZE: { | |
259 | max: 2 * 1024 * 1024 // 2MB | |
260 | } | |
261 | }, | |
536598cf | 262 | EXTNAME: [] as string[], |
0e1dc3e7 | 263 | INFO_HASH: { min: 40, max: 40 }, // Length, info hash is 20 bytes length but we represent it in hexadecimal so 20 * 2 |
fbad87b0 | 264 | DURATION: { min: 0 }, // Number |
a265f7f3 C |
265 | TAGS: { min: 0, max: 5 }, // Number of total tags |
266 | TAG: { min: 2, max: 30 }, // Length | |
e4c55619 | 267 | THUMBNAIL: { min: 2, max: 30 }, |
e4c87ec2 C |
268 | THUMBNAIL_DATA: { min: 0, max: 20000 }, // Bytes |
269 | VIEWS: { min: 0 }, | |
270 | LIKES: { min: 0 }, | |
93e1258c | 271 | DISLIKES: { min: 0 }, |
c6c0fa6c | 272 | FILE_SIZE: { min: -1 }, |
e34c85e5 C |
273 | URL: { min: 3, max: 2000 } // Length |
274 | }, | |
418d092a C |
275 | VIDEO_PLAYLISTS: { |
276 | NAME: { min: 1, max: 120 }, // Length | |
277 | DESCRIPTION: { min: 3, max: 1000 }, // Length | |
278 | URL: { min: 3, max: 2000 }, // Length | |
279 | IMAGE: { | |
280 | EXTNAME: [ '.jpg', '.jpeg' ], | |
281 | FILE_SIZE: { | |
282 | max: 2 * 1024 * 1024 // 2MB | |
283 | } | |
284 | } | |
285 | }, | |
01de67b9 | 286 | ACTORS: { |
e34c85e5 C |
287 | PUBLIC_KEY: { min: 10, max: 5000 }, // Length |
288 | PRIVATE_KEY: { min: 10, max: 5000 }, // Length | |
c5911fd3 C |
289 | URL: { min: 3, max: 2000 }, // Length |
290 | AVATAR: { | |
01de67b9 C |
291 | EXTNAME: [ '.png', '.jpeg', '.jpg' ], |
292 | FILE_SIZE: { | |
293 | max: 2 * 1024 * 1024 // 2MB | |
294 | } | |
c5911fd3 | 295 | } |
e4c87ec2 C |
296 | }, |
297 | VIDEO_EVENTS: { | |
298 | COUNT: { min: 0 } | |
6d852470 | 299 | }, |
bf1f6508 | 300 | VIDEO_COMMENTS: { |
298b3fd3 | 301 | TEXT: { min: 1, max: 10000 }, // Length |
6d852470 | 302 | URL: { min: 3, max: 2000 } // Length |
4ba3b8ea C |
303 | }, |
304 | VIDEO_SHARE: { | |
305 | URL: { min: 3, max: 2000 } // Length | |
a4101923 C |
306 | }, |
307 | CONTACT_FORM: { | |
308 | FROM_NAME: { min: 1, max: 120 }, // Length | |
309 | BODY: { min: 3, max: 5000 } // Length | |
345da516 C |
310 | }, |
311 | PLUGINS: { | |
312 | NAME: { min: 1, max: 214 }, // Length | |
313 | DESCRIPTION: { min: 1, max: 20000 } // Length | |
2735a154 C |
314 | }, |
315 | COMMONS: { | |
316 | URL: { min: 5, max: 2000 } // Length | |
e4c55619 C |
317 | } |
318 | } | |
319 | ||
c655c9ef | 320 | const VIEW_LIFETIME = { |
e4bf7856 C |
321 | VIDEO: 60000 * 60, // 1 hour |
322 | LIVE: 60000 * 5 // 5 minutes | |
323 | } | |
324 | ||
a4101923 C |
325 | let CONTACT_FORM_LIFETIME = 60000 * 60 // 1 hour |
326 | ||
edb4ffc7 | 327 | const VIDEO_TRANSCODING_FPS: VideoTranscodingFPS = { |
a7977280 | 328 | MIN: 10, |
a1587156 C |
329 | STANDARD: [ 24, 25, 30 ], |
330 | HD_STANDARD: [ 50, 60 ], | |
3a6f351b C |
331 | AVERAGE: 30, |
332 | MAX: 60, | |
333 | KEEP_ORIGIN_FPS_RESOLUTION_MIN: 720 // We keep the original FPS on high resolutions (720 minimum) | |
a7977280 | 334 | } |
b5c0e955 | 335 | |
536598cf C |
336 | const DEFAULT_AUDIO_RESOLUTION = VideoResolution.H_480P |
337 | ||
ee9e7b61 | 338 | const VIDEO_RATE_TYPES: { [ id: string ]: VideoRateType } = { |
d38b8281 C |
339 | LIKE: 'like', |
340 | DISLIKE: 'dislike' | |
341 | } | |
342 | ||
80bc88c1 J |
343 | const FFMPEG_NICE: { [ id: string ]: number } = { |
344 | THUMBNAIL: 2, // 2 just for don't blocking servers | |
345 | TRANSCODING: 15 | |
346 | } | |
347 | ||
6e07c3de C |
348 | const VIDEO_CATEGORIES = { |
349 | 1: 'Music', | |
350 | 2: 'Films', | |
351 | 3: 'Vehicles', | |
352 | 4: 'Art', | |
353 | 5: 'Sports', | |
354 | 6: 'Travels', | |
355 | 7: 'Gaming', | |
356 | 8: 'People', | |
357 | 9: 'Comedy', | |
358 | 10: 'Entertainment', | |
6f2ae7a1 | 359 | 11: 'News & Politics', |
40298b02 | 360 | 12: 'How To', |
6e07c3de C |
361 | 13: 'Education', |
362 | 14: 'Activism', | |
363 | 15: 'Science & Technology', | |
364 | 16: 'Animals', | |
365 | 17: 'Kids', | |
366 | 18: 'Food' | |
367 | } | |
368 | ||
6f0c39e2 C |
369 | // See https://creativecommons.org/licenses/?lang=en |
370 | const VIDEO_LICENCES = { | |
371 | 1: 'Attribution', | |
372 | 2: 'Attribution - Share Alike', | |
373 | 3: 'Attribution - No Derivatives', | |
374 | 4: 'Attribution - Non Commercial', | |
375 | 5: 'Attribution - Non Commercial - Share Alike', | |
376 | 6: 'Attribution - Non Commercial - No Derivatives', | |
377 | 7: 'Public Domain Dedication' | |
378 | } | |
379 | ||
a1587156 | 380 | const VIDEO_LANGUAGES: { [id: string]: string } = {} |
3092476e | 381 | |
c6c0fa6c | 382 | const VIDEO_PRIVACIES: { [ id in VideoPrivacy ]: string } = { |
a1587156 C |
383 | [VideoPrivacy.PUBLIC]: 'Public', |
384 | [VideoPrivacy.UNLISTED]: 'Unlisted', | |
385 | [VideoPrivacy.PRIVATE]: 'Private', | |
386 | [VideoPrivacy.INTERNAL]: 'Internal' | |
fd45e8f4 C |
387 | } |
388 | ||
c6c0fa6c | 389 | const VIDEO_STATES: { [ id in VideoState ]: string } = { |
a1587156 C |
390 | [VideoState.PUBLISHED]: 'Published', |
391 | [VideoState.TO_TRANSCODE]: 'To transcode', | |
c6c0fa6c C |
392 | [VideoState.TO_IMPORT]: 'To import', |
393 | [VideoState.WAITING_FOR_LIVE]: 'Waiting for livestream', | |
394 | [VideoState.LIVE_ENDED]: 'Livestream ended' | |
fbad87b0 C |
395 | } |
396 | ||
c6c0fa6c | 397 | const VIDEO_IMPORT_STATES: { [ id in VideoImportState ]: string } = { |
a1587156 C |
398 | [VideoImportState.FAILED]: 'Failed', |
399 | [VideoImportState.PENDING]: 'Pending', | |
2158ac90 RK |
400 | [VideoImportState.SUCCESS]: 'Success', |
401 | [VideoImportState.REJECTED]: 'Rejected' | |
2186386c C |
402 | } |
403 | ||
c6c0fa6c | 404 | const ABUSE_STATES: { [ id in AbuseState ]: string } = { |
d95d1559 C |
405 | [AbuseState.PENDING]: 'Pending', |
406 | [AbuseState.REJECTED]: 'Rejected', | |
407 | [AbuseState.ACCEPTED]: 'Accepted' | |
268eebed C |
408 | } |
409 | ||
c6c0fa6c | 410 | const VIDEO_PLAYLIST_PRIVACIES: { [ id in VideoPlaylistPrivacy ]: string } = { |
a1587156 C |
411 | [VideoPlaylistPrivacy.PUBLIC]: 'Public', |
412 | [VideoPlaylistPrivacy.UNLISTED]: 'Unlisted', | |
413 | [VideoPlaylistPrivacy.PRIVATE]: 'Private' | |
418d092a C |
414 | } |
415 | ||
c6c0fa6c | 416 | const VIDEO_PLAYLIST_TYPES: { [ id in VideoPlaylistType ]: string } = { |
a1587156 C |
417 | [VideoPlaylistType.REGULAR]: 'Regular', |
418 | [VideoPlaylistType.WATCH_LATER]: 'Watch later' | |
df0b219d C |
419 | } |
420 | ||
14e2014a | 421 | const MIMETYPES = { |
536598cf C |
422 | AUDIO: { |
423 | MIMETYPE_EXT: { | |
424 | 'audio/mpeg': '.mp3', | |
425 | 'audio/mp3': '.mp3', | |
426 | 'application/ogg': '.ogg', | |
427 | 'audio/ogg': '.ogg', | |
99d362de C |
428 | 'audio/x-ms-wma': '.wma', |
429 | 'audio/wav': '.wav', | |
430 | 'audio/x-flac': '.flac', | |
b056afe0 RK |
431 | 'audio/flac': '.flac', |
432 | '‎audio/aac': '.aac', | |
433 | 'audio/ac3': '.ac3' | |
536598cf C |
434 | }, |
435 | EXT_MIMETYPE: null as { [ id: string ]: string } | |
436 | }, | |
14e2014a | 437 | VIDEO: { |
30bc55c8 C |
438 | MIMETYPE_EXT: null as { [ id: string ]: string | string[] }, |
439 | MIMETYPES_REGEX: null as string, | |
14e2014a C |
440 | EXT_MIMETYPE: null as { [ id: string ]: string } |
441 | }, | |
442 | IMAGE: { | |
443 | MIMETYPE_EXT: { | |
444 | 'image/png': '.png', | |
445 | 'image/jpg': '.jpg', | |
446 | 'image/jpeg': '.jpg' | |
c6de3a85 C |
447 | }, |
448 | EXT_MIMETYPE: null as { [ id: string ]: string } | |
14e2014a C |
449 | }, |
450 | VIDEO_CAPTIONS: { | |
451 | MIMETYPE_EXT: { | |
452 | 'text/vtt': '.vtt', | |
2f26030d C |
453 | 'application/x-subrip': '.srt', |
454 | 'text/plain': '.srt' | |
14e2014a C |
455 | } |
456 | }, | |
457 | TORRENT: { | |
458 | MIMETYPE_EXT: { | |
459 | 'application/x-bittorrent': '.torrent' | |
460 | } | |
461 | } | |
990b6a0b | 462 | } |
536598cf | 463 | MIMETYPES.AUDIO.EXT_MIMETYPE = invert(MIMETYPES.AUDIO.MIMETYPE_EXT) |
c6de3a85 | 464 | MIMETYPES.IMAGE.EXT_MIMETYPE = invert(MIMETYPES.IMAGE.MIMETYPE_EXT) |
990b6a0b | 465 | |
9f6bae3a C |
466 | // --------------------------------------------------------------------------- |
467 | ||
2d3741d6 C |
468 | const OVERVIEWS = { |
469 | VIDEOS: { | |
1a471091 | 470 | SAMPLE_THRESHOLD: 6, |
764a9657 | 471 | SAMPLES_COUNT: 20 |
2d3741d6 C |
472 | } |
473 | } | |
474 | ||
a3ce4ae8 C |
475 | const VIDEO_CHANNELS = { |
476 | MAX_PER_USER: 20 | |
477 | } | |
478 | ||
2d3741d6 C |
479 | // --------------------------------------------------------------------------- |
480 | ||
50d6de9c | 481 | const SERVER_ACTOR_NAME = 'peertube' |
350e31d6 | 482 | |
e4f97bab | 483 | const ACTIVITY_PUB = { |
1b5b10d1 C |
484 | POTENTIAL_ACCEPT_HEADERS: [ |
485 | 'application/activity+json', | |
9a8cbd82 C |
486 | 'application/ld+json', |
487 | 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' | |
165cdc75 | 488 | ], |
1b5b10d1 | 489 | ACCEPT_HEADER: 'application/activity+json, application/ld+json', |
9a27cdc2 | 490 | PUBLIC: 'https://www.w3.org/ns/activitystreams#Public', |
0d0e8dd0 | 491 | COLLECTION_ITEMS_PER_PAGE: 10, |
4d9ae8f7 | 492 | FETCH_PAGE_LIMIT: 2000, |
20494f12 | 493 | URL_MIME_TYPES: { |
536598cf | 494 | VIDEO: [] as string[], |
20494f12 C |
495 | TORRENT: [ 'application/x-bittorrent' ], |
496 | MAGNET: [ 'application/x-bittorrent;x-scheme-handler/magnet' ] | |
a5625b41 | 497 | }, |
2ccaeeb3 | 498 | MAX_RECURSION_COMMENTS: 100, |
0e0c745b | 499 | ACTOR_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2, // 2 days |
9f79ade6 C |
500 | VIDEO_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2, // 2 days |
501 | VIDEO_PLAYLIST_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2 // 2 days | |
e4f97bab C |
502 | } |
503 | ||
50d6de9c C |
504 | const ACTIVITY_PUB_ACTOR_TYPES: { [ id: string ]: ActivityPubActorType } = { |
505 | GROUP: 'Group', | |
506 | PERSON: 'Person', | |
47581df0 C |
507 | APPLICATION: 'Application', |
508 | ORGANIZATION: 'Organization', | |
509 | SERVICE: 'Service' | |
50d6de9c C |
510 | } |
511 | ||
41f2ebae C |
512 | const HTTP_SIGNATURE = { |
513 | HEADER_NAME: 'signature', | |
514 | ALGORITHM: 'rsa-sha256', | |
f67d7574 C |
515 | HEADERS_TO_SIGN: [ '(request-target)', 'host', 'date', 'digest' ], |
516 | CLOCK_SKEW_SECONDS: 1800 | |
41f2ebae C |
517 | } |
518 | ||
9f6bae3a C |
519 | // --------------------------------------------------------------------------- |
520 | ||
04b8c3fb | 521 | let PRIVATE_RSA_KEY_SIZE = 2048 |
bdfbd4f1 | 522 | |
9f6bae3a C |
523 | // Password encryption |
524 | const BCRYPT_SALT_SIZE = 10 | |
a877d5ac | 525 | |
f88ee4a9 | 526 | const USER_PASSWORD_RESET_LIFETIME = 60000 * 60 // 60 minutes |
45f1bd72 | 527 | const USER_PASSWORD_CREATE_LIFETIME = 60000 * 60 * 24 * 7 // 7 days |
ecb4e35f | 528 | |
d9eaee39 JM |
529 | const USER_EMAIL_VERIFY_LIFETIME = 60000 * 60 // 60 minutes |
530 | ||
6dd9de95 | 531 | const NSFW_POLICY_TYPES: { [ id: string ]: NSFWPolicyType } = { |
0883b324 C |
532 | DO_NOT_LIST: 'do_not_list', |
533 | BLUR: 'blur', | |
534 | DISPLAY: 'display' | |
535 | } | |
536 | ||
bdfbd4f1 C |
537 | // --------------------------------------------------------------------------- |
538 | ||
052937db C |
539 | // Express static paths (router) |
540 | const STATIC_PATHS = { | |
f285faa0 C |
541 | PREVIEWS: '/static/previews/', |
542 | THUMBNAILS: '/static/thumbnails/', | |
052937db | 543 | TORRENTS: '/static/torrents/', |
c5911fd3 | 544 | WEBSEED: '/static/webseed/', |
b9fffa29 | 545 | REDUNDANCY: '/static/redundancy/', |
9c6ca37f C |
546 | STREAMING_PLAYLISTS: { |
547 | HLS: '/static/streaming-playlists/hls' | |
09209296 | 548 | }, |
40e87e9e C |
549 | AVATARS: '/static/avatars/', |
550 | VIDEO_CAPTIONS: '/static/video-captions/' | |
052937db | 551 | } |
02756fbd C |
552 | const STATIC_DOWNLOAD_PATHS = { |
553 | TORRENTS: '/download/torrents/', | |
d7a25329 C |
554 | VIDEOS: '/download/videos/', |
555 | HLS_VIDEOS: '/download/streaming-playlists/hls/videos/' | |
02756fbd | 556 | } |
557b13ae C |
557 | const LAZY_STATIC_PATHS = { |
558 | AVATARS: '/lazy-static/avatars/', | |
20dcfd74 C |
559 | PREVIEWS: '/lazy-static/previews/', |
560 | VIDEO_CAPTIONS: '/lazy-static/video-captions/' | |
557b13ae | 561 | } |
052937db | 562 | |
dc009132 | 563 | // Cache control |
a1587156 | 564 | const STATIC_MAX_AGE = { |
cd4cb177 C |
565 | SERVER: '2h', |
566 | CLIENT: '30d' | |
567 | } | |
dc009132 | 568 | |
cbe2f7c3 | 569 | // Videos thumbnail size |
d8755eed | 570 | const THUMBNAILS_SIZE = { |
e5fc7811 | 571 | width: 223, |
ca6d3622 C |
572 | height: 122, |
573 | minWidth: 150 | |
d8755eed C |
574 | } |
575 | const PREVIEWS_SIZE = { | |
b345a804 | 576 | width: 850, |
ca6d3622 C |
577 | height: 480, |
578 | minWidth: 400 | |
164174a6 | 579 | } |
e8e12200 C |
580 | const AVATARS_SIZE = { |
581 | width: 120, | |
582 | height: 120 | |
583 | } | |
164174a6 C |
584 | |
585 | const EMBED_SIZE = { | |
586 | width: 560, | |
587 | height: 315 | |
d8755eed | 588 | } |
cbe2f7c3 | 589 | |
980246ea | 590 | // Sub folders of cache directory |
d74d29ad | 591 | const FILES_CACHE = { |
f4001cf4 C |
592 | PREVIEWS: { |
593 | DIRECTORY: join(CONFIG.STORAGE.CACHE_DIR, 'previews'), | |
594 | MAX_AGE: 1000 * 3600 * 3 // 3 hours | |
595 | }, | |
596 | VIDEO_CAPTIONS: { | |
597 | DIRECTORY: join(CONFIG.STORAGE.CACHE_DIR, 'video-captions'), | |
598 | MAX_AGE: 1000 * 3600 * 3 // 3 hours | |
f981dae8 C |
599 | } |
600 | } | |
601 | ||
557b13ae | 602 | const LRU_CACHE = { |
d74d29ad | 603 | USER_TOKENS: { |
557b13ae C |
604 | MAX_SIZE: 1000 |
605 | }, | |
606 | AVATAR_STATIC: { | |
607 | MAX_SIZE: 500 | |
d74d29ad C |
608 | } |
609 | } | |
610 | ||
9c6ca37f | 611 | const HLS_STREAMING_PLAYLIST_DIRECTORY = join(CONFIG.STORAGE.STREAMING_PLAYLISTS_DIR, 'hls') |
09209296 C |
612 | const HLS_REDUNDANCY_DIRECTORY = join(CONFIG.STORAGE.REDUNDANCY_DIR, 'hls') |
613 | ||
c6c0fa6c C |
614 | const VIDEO_LIVE = { |
615 | EXTENSION: '.ts', | |
fb719404 | 616 | CLEANUP_DELAY: 1000 * 60 * 5, // 5 minutes |
68e70a74 | 617 | SEGMENT_TIME_SECONDS: 4, // 4 seconds |
fb719404 | 618 | SEGMENTS_LIST_SIZE: 15, // 15 maximum segments in live playlist |
c6c0fa6c C |
619 | RTMP: { |
620 | CHUNK_SIZE: 60000, | |
621 | GOP_CACHE: true, | |
622 | PING: 60, | |
623 | PING_TIMEOUT: 30, | |
624 | BASE_PATH: 'live' | |
625 | } | |
626 | } | |
627 | ||
7348b1fd | 628 | const MEMOIZE_TTL = { |
35f28e94 | 629 | OVERVIEWS_SAMPLE: 1000 * 3600 * 4, // 4 hours |
fb719404 C |
630 | INFO_HASH_EXISTS: 1000 * 3600 * 12, // 12 hours |
631 | LIVE_ABLE_TO_UPLOAD: 1000 * 60 // 1 minute | |
35f28e94 C |
632 | } |
633 | ||
634 | const MEMOIZE_LENGTH = { | |
635 | INFO_HASH_EXISTS: 200 | |
7348b1fd C |
636 | } |
637 | ||
557b13ae C |
638 | const QUEUE_CONCURRENCY = { |
639 | AVATAR_PROCESS_IMAGE: 3 | |
640 | } | |
641 | ||
c48e82b5 C |
642 | const REDUNDANCY = { |
643 | VIDEOS: { | |
c48e82b5 C |
644 | RANDOMIZED_FACTOR: 5 |
645 | } | |
646 | } | |
647 | ||
e12a0092 | 648 | const ACCEPT_HEADERS = [ 'html', 'application/json' ].concat(ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS) |
4f491371 | 649 | |
536598cf | 650 | const ASSETS_PATH = { |
c6c0fa6c C |
651 | DEFAULT_AUDIO_BACKGROUND: join(root(), 'dist', 'server', 'assets', 'default-audio-background.jpg'), |
652 | DEFAULT_LIVE_BACKGROUND: join(root(), 'dist', 'server', 'assets', 'default-live-background.jpg') | |
536598cf C |
653 | } |
654 | ||
bdfbd4f1 C |
655 | // --------------------------------------------------------------------------- |
656 | ||
e032aec9 C |
657 | const CUSTOM_HTML_TAG_COMMENTS = { |
658 | TITLE: '<!-- title tag -->', | |
659 | DESCRIPTION: '<!-- description tag -->', | |
660 | CUSTOM_CSS: '<!-- custom css tag -->', | |
92bf2f62 | 661 | META_TAGS: '<!-- meta tags -->' |
e032aec9 | 662 | } |
709756b8 C |
663 | |
664 | // --------------------------------------------------------------------------- | |
665 | ||
4195cd2b | 666 | const FEEDS = { |
fd4484f1 | 667 | COUNT: 20 |
4195cd2b C |
668 | } |
669 | ||
fd8710b8 | 670 | const MAX_LOGS_OUTPUT_CHARACTERS = 10 * 1000 * 1000 |
566c125d C |
671 | const LOG_FILENAME = 'peertube.log' |
672 | const AUDIT_LOG_FILENAME = 'peertube-audit.log' | |
fd8710b8 | 673 | |
4195cd2b C |
674 | // --------------------------------------------------------------------------- |
675 | ||
9b67da3d C |
676 | const TRACKER_RATE_LIMITS = { |
677 | INTERVAL: 60000 * 5, // 5 minutes | |
8244c85a | 678 | ANNOUNCES_PER_IP_PER_INFOHASH: 15, // maximum announces per torrent in the interval |
db48de85 | 679 | ANNOUNCES_PER_IP: 30, // maximum announces for all our torrents in the interval |
ba881f0e | 680 | BLOCK_IP_LIFETIME: 60000 * 3 // 3 minutes |
9b67da3d C |
681 | } |
682 | ||
ae9bbed4 C |
683 | const P2P_MEDIA_LOADER_PEER_VERSION = 2 |
684 | ||
9b67da3d C |
685 | // --------------------------------------------------------------------------- |
686 | ||
345da516 C |
687 | const PLUGIN_GLOBAL_CSS_FILE_NAME = 'plugins-global.css' |
688 | const PLUGIN_GLOBAL_CSS_PATH = join(CONFIG.STORAGE.TMP_DIR, PLUGIN_GLOBAL_CSS_FILE_NAME) | |
689 | ||
9107d791 C |
690 | let PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME = 1000 * 60 * 5 // 5 minutes |
691 | ||
ffb321be C |
692 | const DEFAULT_THEME_NAME = 'default' |
693 | const DEFAULT_USER_THEME_NAME = 'instance-default' | |
7cd4d2ba | 694 | |
345da516 C |
695 | // --------------------------------------------------------------------------- |
696 | ||
5fb2e288 C |
697 | const SEARCH_INDEX = { |
698 | ROUTES: { | |
699 | VIDEOS: '/api/v1/search/videos', | |
700 | VIDEO_CHANNELS: '/api/v1/search/video-channels' | |
701 | } | |
702 | } | |
703 | ||
704 | // --------------------------------------------------------------------------- | |
705 | ||
9f10b292 C |
706 | // Special constants for a test instance |
707 | if (isTestInstance() === true) { | |
04b8c3fb C |
708 | PRIVATE_RSA_KEY_SIZE = 1024 |
709 | ||
60650c77 | 710 | ACTOR_FOLLOW_SCORE.BASE = 20 |
3cd0734f | 711 | |
f285faa0 C |
712 | REMOTE_SCHEME.HTTP = 'http' |
713 | REMOTE_SCHEME.WS = 'ws' | |
3cd0734f | 714 | |
cd4cb177 | 715 | STATIC_MAX_AGE.SERVER = '0' |
3cd0734f | 716 | |
c46edbc2 | 717 | ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE = 2 |
529f0372 C |
718 | ACTIVITY_PUB.ACTOR_REFRESH_INTERVAL = 10 * 1000 // 10 seconds |
719 | ACTIVITY_PUB.VIDEO_REFRESH_INTERVAL = 10 * 1000 // 10 seconds | |
720 | ACTIVITY_PUB.VIDEO_PLAYLIST_REFRESH_INTERVAL = 10 * 1000 // 10 seconds | |
3cd0734f | 721 | |
01de67b9 | 722 | CONSTRAINTS_FIELDS.ACTORS.AVATAR.FILE_SIZE.max = 100 * 1024 // 100KB |
3cd0734f | 723 | |
2f5c6b2f | 724 | SCHEDULER_INTERVALS_MS.actorFollowScores = 1000 |
2baea0c7 | 725 | SCHEDULER_INTERVALS_MS.removeOldJobs = 10000 |
8f0bc73d | 726 | SCHEDULER_INTERVALS_MS.removeOldHistory = 5000 |
cda03765 | 727 | SCHEDULER_INTERVALS_MS.removeOldViews = 5000 |
2baea0c7 | 728 | SCHEDULER_INTERVALS_MS.updateVideos = 5000 |
6f1b4fa4 | 729 | SCHEDULER_INTERVALS_MS.autoFollowIndexInstances = 5000 |
a1587156 | 730 | REPEAT_JOBS['videos-views'] = { every: 5000 } |
2baea0c7 | 731 | |
c48e82b5 C |
732 | REDUNDANCY.VIDEOS.RANDOMIZED_FACTOR = 1 |
733 | ||
e4bf7856 C |
734 | VIEW_LIFETIME.VIDEO = 1000 // 1 second |
735 | VIEW_LIFETIME.LIVE = 1000 * 5 // 5 second | |
a4101923 | 736 | CONTACT_FORM_LIFETIME = 1000 // 1 second |
3cd0734f | 737 | |
a1587156 | 738 | JOB_ATTEMPTS['email'] = 1 |
f4001cf4 | 739 | |
d74d29ad | 740 | FILES_CACHE.VIDEO_CAPTIONS.MAX_AGE = 3000 |
764a9657 | 741 | MEMOIZE_TTL.OVERVIEWS_SAMPLE = 3000 |
97969c4e | 742 | MEMOIZE_TTL.LIVE_ABLE_TO_UPLOAD = 3000 |
764a9657 | 743 | OVERVIEWS.VIDEOS.SAMPLE_THRESHOLD = 2 |
9107d791 C |
744 | |
745 | PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME = 5000 | |
31c82cd9 | 746 | |
68e70a74 C |
747 | VIDEO_LIVE.CLEANUP_DELAY = 5000 |
748 | VIDEO_LIVE.SEGMENT_TIME_SECONDS = 2 | |
9f10b292 C |
749 | } |
750 | ||
14e2014a | 751 | updateWebserverUrls() |
536598cf | 752 | updateWebserverConfig() |
225a89c2 | 753 | |
6dd9de95 C |
754 | registerConfigChangedHandler(() => { |
755 | updateWebserverUrls() | |
756 | updateWebserverConfig() | |
757 | }) | |
758 | ||
9f10b292 C |
759 | // --------------------------------------------------------------------------- |
760 | ||
caf2aaf4 K |
761 | const FILES_CONTENT_HASH = { |
762 | MANIFEST: generateContentHash(), | |
763 | FAVICON: generateContentHash(), | |
764 | LOGO: generateContentHash() | |
765 | } | |
766 | ||
767 | // --------------------------------------------------------------------------- | |
768 | ||
65fcc311 | 769 | export { |
6dd9de95 | 770 | WEBSERVER, |
9f6bae3a | 771 | API_VERSION, |
c6c0fa6c | 772 | VIDEO_LIVE, |
66170ca8 | 773 | PEERTUBE_VERSION, |
557b13ae | 774 | LAZY_STATIC_PATHS, |
5fb2e288 | 775 | SEARCH_INDEX, |
09209296 | 776 | HLS_REDUNDANCY_DIRECTORY, |
ae9bbed4 | 777 | P2P_MEDIA_LOADER_PEER_VERSION, |
e8e12200 | 778 | AVATARS_SIZE, |
4f491371 | 779 | ACCEPT_HEADERS, |
9f6bae3a | 780 | BCRYPT_SALT_SIZE, |
9b67da3d | 781 | TRACKER_RATE_LIMITS, |
d74d29ad | 782 | FILES_CACHE, |
566c125d | 783 | LOG_FILENAME, |
9f6bae3a | 784 | CONSTRAINTS_FIELDS, |
164174a6 | 785 | EMBED_SIZE, |
c48e82b5 | 786 | REDUNDANCY, |
94a5ff8a C |
787 | JOB_CONCURRENCY, |
788 | JOB_ATTEMPTS, | |
b769007f | 789 | LAST_MIGRATION_VERSION, |
9f6bae3a | 790 | OAUTH_LIFETIME, |
e032aec9 | 791 | CUSTOM_HTML_TAG_COMMENTS, |
f55e5a7b | 792 | BROADCAST_CONCURRENCY, |
566c125d | 793 | AUDIT_LOG_FILENAME, |
1194e8b4 | 794 | PAGINATION, |
60650c77 | 795 | ACTOR_FOLLOW_SCORE, |
f285faa0 C |
796 | PREVIEWS_SIZE, |
797 | REMOTE_SCHEME, | |
7a7724e6 | 798 | FOLLOW_STATES, |
ffb321be | 799 | DEFAULT_USER_THEME_NAME, |
50d6de9c | 800 | SERVER_ACTOR_NAME, |
345da516 C |
801 | PLUGIN_GLOBAL_CSS_FILE_NAME, |
802 | PLUGIN_GLOBAL_CSS_PATH, | |
e4f97bab | 803 | PRIVATE_RSA_KEY_SIZE, |
fd4484f1 | 804 | ROUTE_CACHE_LIFETIME, |
9f6bae3a | 805 | SORTABLE_COLUMNS, |
9c6ca37f | 806 | HLS_STREAMING_PLAYLIST_DIRECTORY, |
4195cd2b | 807 | FEEDS, |
2b86fe72 | 808 | JOB_TTL, |
ffb321be | 809 | DEFAULT_THEME_NAME, |
0883b324 | 810 | NSFW_POLICY_TYPES, |
dc009132 | 811 | STATIC_MAX_AGE, |
a6375e69 | 812 | STATIC_PATHS, |
cf9166cf | 813 | VIDEO_IMPORT_TIMEOUT, |
df0b219d | 814 | VIDEO_PLAYLIST_TYPES, |
fd8710b8 | 815 | MAX_LOGS_OUTPUT_CHARACTERS, |
e4f97bab | 816 | ACTIVITY_PUB, |
50d6de9c | 817 | ACTIVITY_PUB_ACTOR_TYPES, |
9f6bae3a | 818 | THUMBNAILS_SIZE, |
6e07c3de | 819 | VIDEO_CATEGORIES, |
35f28e94 | 820 | MEMOIZE_LENGTH, |
3092476e | 821 | VIDEO_LANGUAGES, |
fd45e8f4 | 822 | VIDEO_PRIVACIES, |
6f0c39e2 | 823 | VIDEO_LICENCES, |
2186386c | 824 | VIDEO_STATES, |
557b13ae | 825 | QUEUE_CONCURRENCY, |
0d0e8dd0 | 826 | VIDEO_RATE_TYPES, |
a7977280 | 827 | VIDEO_TRANSCODING_FPS, |
80bc88c1 | 828 | FFMPEG_NICE, |
d95d1559 | 829 | ABUSE_STATES, |
a3ce4ae8 | 830 | VIDEO_CHANNELS, |
557b13ae | 831 | LRU_CACHE, |
71e3dfda | 832 | JOB_REQUEST_TIMEOUT, |
ecb4e35f | 833 | USER_PASSWORD_RESET_LIFETIME, |
45f1bd72 | 834 | USER_PASSWORD_CREATE_LIFETIME, |
7348b1fd | 835 | MEMOIZE_TTL, |
d9eaee39 | 836 | USER_EMAIL_VERIFY_LIFETIME, |
2d3741d6 | 837 | OVERVIEWS, |
2baea0c7 | 838 | SCHEDULER_INTERVALS_MS, |
6b616860 | 839 | REPEAT_JOBS, |
02756fbd | 840 | STATIC_DOWNLOAD_PATHS, |
14e2014a | 841 | MIMETYPES, |
f6eebcb3 | 842 | CRAWL_REQUEST_CONCURRENCY, |
536598cf | 843 | DEFAULT_AUDIO_RESOLUTION, |
b5c0e955 | 844 | JOB_COMPLETED_LIFETIME, |
41f2ebae | 845 | HTTP_SIGNATURE, |
fbad87b0 | 846 | VIDEO_IMPORT_STATES, |
e4bf7856 | 847 | VIEW_LIFETIME, |
a4101923 | 848 | CONTACT_FORM_LIFETIME, |
418d092a | 849 | VIDEO_PLAYLIST_PRIVACIES, |
9107d791 | 850 | PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME, |
536598cf | 851 | ASSETS_PATH, |
caf2aaf4 | 852 | FILES_CONTENT_HASH, |
74dc3bca | 853 | loadLanguages, |
caf2aaf4 K |
854 | buildLanguages, |
855 | generateContentHash | |
9f10b292 | 856 | } |
fd206f0b C |
857 | |
858 | // --------------------------------------------------------------------------- | |
859 | ||
14e2014a C |
860 | function buildVideoMimetypeExt () { |
861 | const data = { | |
fccbbc1a | 862 | // streamable formats that warrant cross-browser compatibility |
14e2014a | 863 | 'video/webm': '.webm', |
30bc55c8 C |
864 | // We'll add .ogg if additional extensions are enabled |
865 | // We could add .ogg here but since it could be an audio file, | |
866 | // it would be confusing for users because PeerTube will refuse their file (based on the mimetype) | |
867 | 'video/ogg': [ '.ogv' ], | |
14e2014a C |
868 | 'video/mp4': '.mp4' |
869 | } | |
870 | ||
536598cf C |
871 | if (CONFIG.TRANSCODING.ENABLED) { |
872 | if (CONFIG.TRANSCODING.ALLOW_ADDITIONAL_EXTENSIONS) { | |
30bc55c8 C |
873 | data['video/ogg'].push('.ogg') |
874 | ||
536598cf | 875 | Object.assign(data, { |
536598cf | 876 | 'video/x-matroska': '.mkv', |
fccbbc1a RK |
877 | |
878 | // Developed by Apple | |
b056afe0 | 879 | 'video/quicktime': [ '.mov', '.qt', '.mqv' ], // often used as output format by editing software |
c37a52b0 | 880 | 'video/x-m4v': '.m4v', |
fccbbc1a RK |
881 | 'video/m4v': '.m4v', |
882 | ||
883 | // Developed by the Adobe Flash Platform | |
884 | 'video/x-flv': '.flv', | |
885 | 'video/x-f4v': '.f4v', // replacement for flv | |
886 | ||
887 | // Developed by Microsoft | |
888 | 'video/x-ms-wmv': '.wmv', | |
889 | 'video/x-msvideo': '.avi', | |
890 | 'video/avi': '.avi', | |
891 | ||
892 | // Developed by 3GPP | |
893 | // common video formats for cell phones | |
b056afe0 RK |
894 | 'video/3gpp': [ '.3gp', '.3gpp' ], |
895 | 'video/3gpp2': [ '.3g2', '.3gpp2' ], | |
fccbbc1a RK |
896 | |
897 | // Developed by FFmpeg/Mplayer | |
898 | 'application/x-nut': '.nut', | |
899 | ||
900 | // The standard video format used by many Sony and Panasonic HD camcorders. | |
901 | // It is also used for storing high definition video on Blu-ray discs. | |
902 | 'video/mp2t': '.mts', | |
903 | 'video/m2ts': '.m2ts', | |
904 | ||
905 | // Old formats reliant on MPEG-1/MPEG-2 | |
906 | 'video/mpv': '.mpv', | |
907 | 'video/mpeg2': '.m2v', | |
b056afe0 RK |
908 | 'video/mpeg': [ '.m1v', '.mpg', '.mpe', '.mpeg', '.vob' ], |
909 | 'video/dvd': '.vob', | |
fccbbc1a | 910 | |
26469f9e C |
911 | // Could be anything |
912 | 'application/octet-stream': null, | |
fccbbc1a | 913 | 'application/mxf': '.mxf' // often used as exchange format by editing software |
536598cf C |
914 | }) |
915 | } | |
916 | ||
917 | if (CONFIG.TRANSCODING.ALLOW_AUDIO_FILES) { | |
918 | Object.assign(data, MIMETYPES.AUDIO.MIMETYPE_EXT) | |
919 | } | |
14e2014a C |
920 | } |
921 | ||
922 | return data | |
923 | } | |
924 | ||
925 | function updateWebserverUrls () { | |
6dd9de95 C |
926 | WEBSERVER.URL = sanitizeUrl(CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT) |
927 | WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT, REMOTE_SCHEME.HTTP) | |
6dd9de95 | 928 | WEBSERVER.WS = CONFIG.WEBSERVER.WS |
c6c0fa6c C |
929 | |
930 | WEBSERVER.SCHEME = CONFIG.WEBSERVER.SCHEME | |
6dd9de95 C |
931 | WEBSERVER.HOSTNAME = CONFIG.WEBSERVER.HOSTNAME |
932 | WEBSERVER.PORT = CONFIG.WEBSERVER.PORT | |
c6c0fa6c C |
933 | |
934 | WEBSERVER.RTMP_URL = 'rtmp://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.LIVE.RTMP.PORT + '/' + VIDEO_LIVE.RTMP.BASE_PATH | |
fd206f0b C |
935 | } |
936 | ||
14e2014a | 937 | function updateWebserverConfig () { |
14e2014a | 938 | MIMETYPES.VIDEO.MIMETYPE_EXT = buildVideoMimetypeExt() |
30bc55c8 C |
939 | MIMETYPES.VIDEO.MIMETYPES_REGEX = buildMimetypesRegex(MIMETYPES.VIDEO.MIMETYPE_EXT) |
940 | ||
536598cf C |
941 | ACTIVITY_PUB.URL_MIME_TYPES.VIDEO = Object.keys(MIMETYPES.VIDEO.MIMETYPE_EXT) |
942 | ||
30bc55c8 C |
943 | MIMETYPES.VIDEO.EXT_MIMETYPE = buildVideoExtMimetype(MIMETYPES.VIDEO.MIMETYPE_EXT) |
944 | ||
945 | CONSTRAINTS_FIELDS.VIDEOS.EXTNAME = Object.keys(MIMETYPES.VIDEO.EXT_MIMETYPE) | |
946 | } | |
947 | ||
948 | function buildVideoExtMimetype (obj: { [ id: string ]: string | string[] }) { | |
949 | const result: { [id: string]: string } = {} | |
950 | ||
951 | for (const mimetype of Object.keys(obj)) { | |
952 | const value = obj[mimetype] | |
953 | if (!value) continue | |
954 | ||
955 | const extensions = Array.isArray(value) ? value : [ value ] | |
956 | ||
957 | for (const extension of extensions) { | |
958 | result[extension] = mimetype | |
959 | } | |
960 | } | |
961 | ||
962 | return result | |
14e2014a C |
963 | } |
964 | ||
30bc55c8 C |
965 | function buildMimetypesRegex (obj: { [id: string]: string | string[] }) { |
966 | return Object.keys(obj) | |
967 | .map(m => `(${m})`) | |
968 | .join('|') | |
14e2014a C |
969 | } |
970 | ||
74dc3bca | 971 | function loadLanguages () { |
8f0bc73d | 972 | Object.assign(VIDEO_LANGUAGES, buildLanguages()) |
74dc3bca C |
973 | } |
974 | ||
9d3ef9fe C |
975 | function buildLanguages () { |
976 | const iso639 = require('iso-639-3') | |
977 | ||
a1587156 | 978 | const languages: { [id: string]: string } = {} |
9d3ef9fe | 979 | |
1d94c154 | 980 | const additionalLanguages = { |
a1587156 C |
981 | sgn: true, // Sign languages (macro language) |
982 | ase: true, // American sign language | |
983 | sdl: true, // Arabian sign language | |
984 | bfi: true, // British sign language | |
985 | bzs: true, // Brazilian sign language | |
986 | csl: true, // Chinese sign language | |
987 | cse: true, // Czech sign language | |
988 | dsl: true, // Danish sign language | |
989 | fsl: true, // French sign language | |
990 | gsg: true, // German sign language | |
991 | pks: true, // Pakistan sign language | |
992 | jsl: true, // Japanese sign language | |
993 | sfs: true, // South African sign language | |
994 | swl: true, // Swedish sign language | |
07c01b31 C |
995 | rsl: true, // Russian sign language |
996 | ||
997 | kab: true, // Kabyle | |
a1587156 C |
998 | |
999 | epo: true, // Esperanto | |
1000 | tlh: true, // Klingon | |
1001 | jbo: true, // Lojban | |
1002 | avk: true // Kotava | |
1d94c154 | 1003 | } |
9d3ef9fe C |
1004 | |
1005 | // Only add ISO639-1 languages and some sign languages (ISO639-3) | |
1006 | iso639 | |
1007 | .filter(l => { | |
4fdeef81 | 1008 | return (l.iso6391 !== undefined && l.type === 'living') || |
a1587156 | 1009 | additionalLanguages[l.iso6393] === true |
9d3ef9fe | 1010 | }) |
a1587156 | 1011 | .forEach(l => { languages[l.iso6391 || l.iso6393] = l.name }) |
9d3ef9fe | 1012 | |
db6d617d | 1013 | // Override Occitan label |
a1587156 C |
1014 | languages['oc'] = 'Occitan' |
1015 | languages['el'] = 'Greek' | |
db6d617d | 1016 | |
9d3ef9fe C |
1017 | return languages |
1018 | } | |
caf2aaf4 K |
1019 | |
1020 | function generateContentHash () { | |
1021 | return randomBytes(20).toString('hex') | |
1022 | } |