]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/initializers/constants.ts
Add ability to forbid followers
[github/Chocobozzz/PeerTube.git] / server / initializers / constants.ts
CommitLineData
fd206f0b
C
1import { IConfig } from 'config'
2import { dirname, join } from 'path'
3f6b6a56 3import { JobType, VideoRateType, VideoState, VideosRedundancy } from '../../shared/models'
50d6de9c 4import { ActivityPubActorType } from '../../shared/models/activitypub'
225a89c2 5import { FollowState } from '../../shared/models/actors'
edb4ffc7 6import { VideoAbuseState, VideoImportState, VideoPrivacy, VideoTranscodingFPS } from '../../shared/models/videos'
e02643f3 7// Do not use barrels, remain constants as independent as possible
0e5ff97f 8import { buildPath, isTestInstance, parseDuration, parseBytes, root, sanitizeHost, sanitizeUrl } from '../helpers/core-utils'
0883b324 9import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type'
28be8916 10import { invert } from 'lodash'
6b616860 11import { CronRepeatOptions, EveryRepeatOptions } from 'bull'
c48e82b5 12import * as bytes from 'bytes'
418d092a 13import { VideoPlaylistPrivacy } from '../../shared/models/videos/playlist/video-playlist-privacy.model'
df0b219d 14import { VideoPlaylistType } from '../../shared/models/videos/playlist/video-playlist-type.model'
fd206f0b
C
15
16// Use a variable to reload the configuration if we need
17let config: IConfig = require('config')
ee9e7b61 18
9f6bae3a
C
19// ---------------------------------------------------------------------------
20
ae9bbed4 21const LAST_MIGRATION_VERSION = 355
5804c0db
C
22
23// ---------------------------------------------------------------------------
24
9f6bae3a 25// API version
f0f5567b 26const API_VERSION = 'v1'
9f10b292 27
1194e8b4
C
28const PAGINATION = {
29 COUNT: {
30 DEFAULT: 15,
31 MAX: 100
32 }
33}
9f6bae3a 34
9f6bae3a
C
35// Sortable columns per schema
36const SORTABLE_COLUMNS = {
9c2c18f3 37 USERS: [ 'id', 'username', 'createdAt' ],
06a05d5f 38 USER_SUBSCRIPTIONS: [ 'id', 'createdAt' ],
265ba139 39 ACCOUNTS: [ 'createdAt' ],
94a5ff8a 40 JOBS: [ 'createdAt' ],
26b7305a 41 VIDEO_ABUSES: [ 'id', 'createdAt', 'state' ],
72c7248b 42 VIDEO_CHANNELS: [ 'id', 'name', 'updatedAt', 'createdAt' ],
ed31c059 43 VIDEO_IMPORTS: [ 'createdAt' ],
bf1f6508 44 VIDEO_COMMENT_THREADS: [ 'createdAt' ],
7a7724e6
C
45 BLACKLISTS: [ 'id', 'name', 'duration', 'views', 'likes', 'dislikes', 'uuid', 'createdAt' ],
46 FOLLOWERS: [ 'createdAt' ],
57c36b27
C
47 FOLLOWING: [ 'createdAt' ],
48
9a629c6e
C
49 VIDEOS: [ 'name', 'duration', 'createdAt', 'publishedAt', 'views', 'likes', 'trending' ],
50
51 VIDEOS_SEARCH: [ 'name', 'duration', 'createdAt', 'publishedAt', 'views', 'likes', 'match' ],
7ad9b984
C
52 VIDEO_CHANNELS_SEARCH: [ 'match', 'displayName', 'createdAt' ],
53
54 ACCOUNTS_BLOCKLIST: [ 'createdAt' ],
cef534ed
C
55 SERVERS_BLOCKLIST: [ 'createdAt' ],
56
418d092a
C
57 USER_NOTIFICATIONS: [ 'createdAt' ],
58
f0a39880 59 VIDEO_PLAYLISTS: [ 'displayName', 'createdAt', 'updatedAt' ]
9f6bae3a 60}
9f10b292 61
2f372a86 62const OAUTH_LIFETIME = {
ff193d5e 63 ACCESS_TOKEN: 3600 * 24, // 1 day, for upload
2f372a86
C
64 REFRESH_TOKEN: 1209600 // 2 weeks
65}
66
fd4484f1 67const ROUTE_CACHE_LIFETIME = {
3f6d68d9
RK
68 FEEDS: '15 minutes',
69 ROBOTS: '2 hours',
2feebf3e 70 SITEMAP: '1 day',
5447516b 71 SECURITYTXT: '2 hours',
3f6d68d9 72 NODEINFO: '10 minutes',
aad0ec24 73 DNT_POLICY: '1 week',
2d3741d6
C
74 OVERVIEWS: {
75 VIDEOS: '1 hour'
76 },
fd4484f1 77 ACTIVITY_PUB: {
3f6d68d9 78 VIDEOS: '1 second' // 1 second, cache concurrent requests after a broadcast for example
4b5384f6
C
79 },
80 STATS: '4 hours'
fd4484f1
C
81}
82
9f6bae3a 83// ---------------------------------------------------------------------------
26d7d31b 84
60650c77
C
85// Number of points we add/remove after a successful/bad request
86const ACTOR_FOLLOW_SCORE = {
225a89c2
C
87 PENALTY: -10,
88 BONUS: 10,
60650c77
C
89 BASE: 1000,
90 MAX: 10000
225a89c2
C
91}
92
93const FOLLOW_STATES: { [ id: string ]: FollowState } = {
94 PENDING: 'pending',
95 ACCEPTED: 'accepted'
96}
97
98const REMOTE_SCHEME = {
99 HTTP: 'https',
100 WS: 'wss'
101}
102
a0327eed
C
103// TODO: remove 'video-file'
104const JOB_ATTEMPTS: { [ id in (JobType | 'video-file') ]: number } = {
94a5ff8a
C
105 'activitypub-http-broadcast': 5,
106 'activitypub-http-unicast': 5,
107 'activitypub-http-fetcher': 5,
5350fd8e 108 'activitypub-follow': 5,
0138af92 109 'video-file-import': 1,
a0327eed 110 'video-transcoding': 1,
ecb4e35f 111 'video-file': 1,
fbad87b0 112 'video-import': 1,
6b616860 113 'email': 5,
04b8c3fb
C
114 'videos-views': 1,
115 'activitypub-refresher': 1
225a89c2 116}
a0327eed 117const JOB_CONCURRENCY: { [ id in (JobType | 'video-file') ]: number } = {
94a5ff8a
C
118 'activitypub-http-broadcast': 1,
119 'activitypub-http-unicast': 5,
120 'activitypub-http-fetcher': 1,
5350fd8e 121 'activitypub-follow': 3,
0138af92 122 'video-file-import': 1,
a0327eed 123 'video-transcoding': 1,
ecb4e35f 124 'video-file': 1,
fbad87b0 125 'video-import': 1,
6b616860 126 'email': 5,
04b8c3fb
C
127 'videos-views': 1,
128 'activitypub-refresher': 1
225a89c2 129}
a0327eed 130const JOB_TTL: { [ id in (JobType | 'video-file') ]: number } = {
2b86fe72
C
131 'activitypub-http-broadcast': 60000 * 10, // 10 minutes
132 'activitypub-http-unicast': 60000 * 10, // 10 minutes
133 'activitypub-http-fetcher': 60000 * 10, // 10 minutes
134 'activitypub-follow': 60000 * 10, // 10 minutes
135 'video-file-import': 1000 * 3600, // 1 hour
a0327eed 136 'video-transcoding': 1000 * 3600 * 48, // 2 days, transcoding could be long
2b86fe72 137 'video-file': 1000 * 3600 * 48, // 2 days, transcoding could be long
cf9166cf 138 'video-import': 1000 * 3600 * 2, // hours
6b616860 139 'email': 60000 * 10, // 10 minutes
04b8c3fb
C
140 'videos-views': undefined, // Unlimited
141 'activitypub-refresher': 60000 * 10 // 10 minutes
2b86fe72 142}
6b616860
C
143const REPEAT_JOBS: { [ id: string ]: EveryRepeatOptions | CronRepeatOptions } = {
144 'videos-views': {
04b8c3fb 145 cron: '1 * * * *' // At 1 minute past the hour
6b616860
C
146 }
147}
148
71e3dfda 149const BROADCAST_CONCURRENCY = 10 // How many requests in parallel we do in activitypub-http-broadcast job
240085d0 150const CRAWL_REQUEST_CONCURRENCY = 1 // How many requests in parallel to fetch remote data (likes, shares...)
71e3dfda 151const JOB_REQUEST_TIMEOUT = 3000 // 3 seconds
71e3dfda 152const JOB_COMPLETED_LIFETIME = 60000 * 60 * 24 * 2 // 2 days
cf9166cf 153const VIDEO_IMPORT_TIMEOUT = 1000 * 3600 // 1 hour
225a89c2 154
60650c77 155// 1 hour
2baea0c7 156let SCHEDULER_INTERVALS_MS = {
2f5c6b2f 157 actorFollowScores: 60000 * 60, // 1 hour
bbe0f064 158 removeOldJobs: 60000 * 60, // 1 hour
ce32426b 159 updateVideos: 60000, // 1 minute
f9f899b9 160 youtubeDLUpdate: 60000 * 60 * 24 // 1 day
2baea0c7 161}
60650c77 162
225a89c2
C
163// ---------------------------------------------------------------------------
164
e861452f 165const CONFIG = {
fd206f0b 166 CUSTOM_FILE: getLocalConfigFilePath(),
d16b5172 167 LISTEN: {
cff8b272
PAT
168 PORT: config.get<number>('listen.port'),
169 HOSTNAME: config.get<string>('listen.hostname')
d16b5172 170 },
e861452f 171 DATABASE: {
65fcc311
C
172 DBNAME: 'peertube' + config.get<string>('database.suffix'),
173 HOSTNAME: config.get<string>('database.hostname'),
174 PORT: config.get<number>('database.port'),
175 USERNAME: config.get<string>('database.username'),
1c3386e8
RK
176 PASSWORD: config.get<string>('database.password'),
177 POOL: {
178 MAX: config.get<number>('database.pool.max')
179 }
e861452f 180 },
94a5ff8a 181 REDIS: {
19f7b248
RK
182 HOSTNAME: config.has('redis.hostname') ? config.get<string>('redis.hostname') : null,
183 PORT: config.has('redis.port') ? config.get<number>('redis.port') : null,
184 SOCKET: config.has('redis.socket') ? config.get<string>('redis.socket') : null,
185 AUTH: config.has('redis.auth') ? config.get<string>('redis.auth') : null,
186 DB: config.has('redis.db') ? config.get<number>('redis.db') : null
94a5ff8a 187 },
ecb4e35f
C
188 SMTP: {
189 HOSTNAME: config.get<string>('smtp.hostname'),
190 PORT: config.get<number>('smtp.port'),
191 USERNAME: config.get<string>('smtp.username'),
192 PASSWORD: config.get<string>('smtp.password'),
193 TLS: config.get<boolean>('smtp.tls'),
bebf2d89 194 DISABLE_STARTTLS: config.get<boolean>('smtp.disable_starttls'),
ecb4e35f
C
195 CA_FILE: config.get<string>('smtp.ca_file'),
196 FROM_ADDRESS: config.get<string>('smtp.from_address')
197 },
e861452f 198 STORAGE: {
6040f87d 199 TMP_DIR: buildPath(config.get<string>('storage.tmp')),
0b4204f9
C
200 AVATARS_DIR: buildPath(config.get<string>('storage.avatars')),
201 LOG_DIR: buildPath(config.get<string>('storage.logs')),
202 VIDEOS_DIR: buildPath(config.get<string>('storage.videos')),
9c6ca37f 203 STREAMING_PLAYLISTS_DIR: buildPath(config.get<string>('storage.streaming_playlists')),
6040f87d 204 REDUNDANCY_DIR: buildPath(config.get<string>('storage.redundancy')),
0b4204f9
C
205 THUMBNAILS_DIR: buildPath(config.get<string>('storage.thumbnails')),
206 PREVIEWS_DIR: buildPath(config.get<string>('storage.previews')),
40e87e9e 207 CAPTIONS_DIR: buildPath(config.get<string>('storage.captions')),
0b4204f9
C
208 TORRENTS_DIR: buildPath(config.get<string>('storage.torrents')),
209 CACHE_DIR: buildPath(config.get<string>('storage.cache'))
e861452f
C
210 },
211 WEBSERVER: {
65fcc311
C
212 SCHEME: config.get<boolean>('webserver.https') === true ? 'https' : 'http',
213 WS: config.get<boolean>('webserver.https') === true ? 'wss' : 'ws',
214 HOSTNAME: config.get<string>('webserver.hostname'),
215 PORT: config.get<number>('webserver.port'),
216 URL: '',
217 HOST: ''
4793c343 218 },
490b595a 219 TRUST_PROXY: config.get<string[]>('trust_proxy'),
23e27dd5
C
220 LOG: {
221 LEVEL: config.get<string>('log.level')
222 },
1297eb5d
C
223 SEARCH: {
224 REMOTE_URI: {
225 USERS: config.get<boolean>('search.remote_uri.users'),
226 ANONYMOUS: config.get<boolean>('search.remote_uri.anonymous')
227 }
228 },
9a629c6e
C
229 TRENDING: {
230 VIDEOS: {
231 INTERVAL_DAYS: config.get<number>('trending.videos.interval_days')
232 }
233 },
c48e82b5 234 REDUNDANCY: {
d9bdd007 235 VIDEOS: {
f9f899b9 236 CHECK_INTERVAL: parseDuration(config.get<string>('redundancy.videos.check_interval')),
d9bdd007
C
237 STRATEGIES: buildVideosRedundancy(config.get<any[]>('redundancy.videos.strategies'))
238 }
c48e82b5 239 },
539d3f4f
C
240 CSP: {
241 ENABLED: config.get<boolean>('csp.enabled'),
242 REPORT_ONLY: config.get<boolean>('csp.report_only'),
243 REPORT_URI: config.get<boolean>('csp.report_uri')
244 },
4793c343 245 ADMIN: {
fd206f0b 246 get EMAIL () { return config.get<string>('admin.email') }
e22528ac 247 },
a4101923
C
248 CONTACT_FORM: {
249 get ENABLED () { return config.get<boolean>('contact_form.enabled') }
250 },
e22528ac 251 SIGNUP: {
fd206f0b 252 get ENABLED () { return config.get<boolean>('signup.enabled') },
ff2c1fe8 253 get LIMIT () { return config.get<number>('signup.limit') },
d9eaee39 254 get REQUIRES_EMAIL_VERIFICATION () { return config.get<boolean>('signup.requires_email_verification') },
ff2c1fe8
RK
255 FILTERS: {
256 CIDR: {
257 get WHITELIST () { return config.get<string[]>('signup.filters.cidr.whitelist') },
258 get BLACKLIST () { return config.get<string[]>('signup.filters.cidr.blacklist') }
259 }
260 }
b0f9f39e
C
261 },
262 USER: {
0e5ff97f
BY
263 get VIDEO_QUOTA () { return parseBytes(config.get<number>('user.video_quota')) },
264 get VIDEO_QUOTA_DAILY () { return parseBytes(config.get<number>('user.video_quota_daily')) }
227d02fe
C
265 },
266 TRANSCODING: {
fd206f0b 267 get ENABLED () { return config.get<boolean>('transcoding.enabled') },
14e2014a 268 get ALLOW_ADDITIONAL_EXTENSIONS () { return config.get<boolean>('transcoding.allow_additional_extensions') },
fd206f0b 269 get THREADS () { return config.get<number>('transcoding.threads') },
40298b02 270 RESOLUTIONS: {
fd206f0b
C
271 get '240p' () { return config.get<boolean>('transcoding.resolutions.240p') },
272 get '360p' () { return config.get<boolean>('transcoding.resolutions.360p') },
273 get '480p' () { return config.get<boolean>('transcoding.resolutions.480p') },
274 get '720p' () { return config.get<boolean>('transcoding.resolutions.720p') },
275 get '1080p' () { return config.get<boolean>('transcoding.resolutions.1080p') }
09209296
C
276 },
277 HLS: {
278 get ENABLED () { return config.get<boolean>('transcoding.hls.enabled') }
40298b02 279 }
f981dae8 280 },
5d08a6a7
C
281 IMPORT: {
282 VIDEOS: {
283 HTTP: {
284 get ENABLED () { return config.get<boolean>('import.videos.http.enabled') }
a84b8fa5
C
285 },
286 TORRENT: {
287 get ENABLED () { return config.get<boolean>('import.videos.torrent.enabled') }
5d08a6a7
C
288 }
289 }
290 },
7ccddd7b
JM
291 AUTO_BLACKLIST: {
292 VIDEOS: {
293 OF_USERS: {
294 get ENABLED () { return config.get<boolean>('auto_blacklist.videos.of_users.enabled') }
295 }
296 }
297 },
f981dae8
C
298 CACHE: {
299 PREVIEWS: {
fd206f0b 300 get SIZE () { return config.get<number>('cache.previews.size') }
40e87e9e
C
301 },
302 VIDEO_CAPTIONS: {
303 get SIZE () { return config.get<number>('cache.captions.size') }
f981dae8 304 }
66b16caf
C
305 },
306 INSTANCE: {
307 get NAME () { return config.get<string>('instance.name') },
2e3a0215 308 get SHORT_DESCRIPTION () { return config.get<string>('instance.short_description') },
66b16caf 309 get DESCRIPTION () { return config.get<string>('instance.description') },
00b5556c 310 get TERMS () { return config.get<string>('instance.terms') },
f8802489 311 get IS_NSFW () { return config.get<boolean>('instance.is_nsfw') },
901637bb 312 get DEFAULT_CLIENT_ROUTE () { return config.get<string>('instance.default_client_route') },
81e504b3 313 get DEFAULT_NSFW_POLICY () { return config.get<NSFWPolicyType>('instance.default_nsfw_policy') },
00b5556c
C
314 CUSTOMIZATIONS: {
315 get JAVASCRIPT () { return config.get<string>('instance.customizations.javascript') },
316 get CSS () { return config.get<string>('instance.customizations.css') }
ac235c37 317 },
5447516b
AH
318 get ROBOTS () { return config.get<string>('instance.robots') },
319 get SECURITYTXT () { return config.get<string>('instance.securitytxt') },
320 get SECURITYTXT_CONTACT () { return config.get<string>('admin.email') }
8be1afa1
C
321 },
322 SERVICES: {
323 TWITTER: {
324 get USERNAME () { return config.get<string>('services.twitter.username') },
325 get WHITELISTED () { return config.get<boolean>('services.twitter.whitelisted') }
326 }
5b9c965d
C
327 },
328 FOLLOWERS: {
329 INSTANCE: {
330 get ENABLED () { return config.get<boolean>('followers.instance.enabled') }
331 }
e861452f
C
332 }
333}
e861452f 334
9f6bae3a
C
335// ---------------------------------------------------------------------------
336
14e2014a 337let CONSTRAINTS_FIELDS = {
e4c55619 338 USERS: {
9f7a1953 339 NAME: { min: 1, max: 120 }, // Length
d23e6a1c 340 DESCRIPTION: { min: 3, max: 1000 }, // Length
d0ce42c1 341 USERNAME: { min: 1, max: 50 }, // Length
b0f9f39e 342 PASSWORD: { min: 6, max: 255 }, // Length
eacb25c4 343 VIDEO_QUOTA: { min: -1 },
bee0abff 344 VIDEO_QUOTA_DAILY: { min: -1 },
eacb25c4 345 BLOCKED_REASON: { min: 3, max: 250 } // Length
e4c55619 346 },
55fa55a9 347 VIDEO_ABUSES: {
1506307f
C
348 REASON: { min: 2, max: 3000 }, // Length
349 MODERATION_COMMENT: { min: 2, max: 3000 } // Length
55fa55a9 350 },
26b7305a
C
351 VIDEO_BLACKLIST: {
352 REASON: { min: 2, max: 300 } // Length
353 },
72c7248b 354 VIDEO_CHANNELS: {
9f7a1953 355 NAME: { min: 1, max: 120 }, // Length
d23e6a1c
BY
356 DESCRIPTION: { min: 3, max: 1000 }, // Length
357 SUPPORT: { min: 3, max: 1000 }, // Length
e34c85e5 358 URL: { min: 3, max: 2000 } // Length
72c7248b 359 },
40e87e9e
C
360 VIDEO_CAPTIONS: {
361 CAPTION_FILE: {
f4001cf4 362 EXTNAME: [ '.vtt', '.srt' ],
40e87e9e
C
363 FILE_SIZE: {
364 max: 2 * 1024 * 1024 // 2MB
365 }
366 }
367 },
fbad87b0 368 VIDEO_IMPORTS: {
ce33919c
C
369 URL: { min: 3, max: 2000 }, // Length
370 TORRENT_NAME: { min: 3, max: 255 }, // Length
990b6a0b
C
371 TORRENT_FILE: {
372 EXTNAME: [ '.torrent' ],
373 FILE_SIZE: {
374 max: 1024 * 200 // 200 KB
375 }
376 }
fbad87b0 377 },
c48e82b5
C
378 VIDEOS_REDUNDANCY: {
379 URL: { min: 3, max: 2000 } // Length
380 },
5c6d985f
C
381 VIDEO_RATES: {
382 URL: { min: 3, max: 2000 } // Length
383 },
e4c55619 384 VIDEOS: {
a265f7f3 385 NAME: { min: 3, max: 120 }, // Length
9d3ef9fe 386 LANGUAGE: { min: 1, max: 10 }, // Length
9567011b 387 TRUNCATED_DESCRIPTION: { min: 3, max: 250 }, // Length
2422c46b 388 DESCRIPTION: { min: 3, max: 10000 }, // Length
d23e6a1c 389 SUPPORT: { min: 3, max: 1000 }, // Length
ac81d1a0
C
390 IMAGE: {
391 EXTNAME: [ '.jpg', '.jpeg' ],
392 FILE_SIZE: {
393 max: 2 * 1024 * 1024 // 2MB
394 }
395 },
14e2014a 396 EXTNAME: buildVideosExtname(),
0e1dc3e7 397 INFO_HASH: { min: 40, max: 40 }, // Length, info hash is 20 bytes length but we represent it in hexadecimal so 20 * 2
fbad87b0 398 DURATION: { min: 0 }, // Number
a265f7f3
C
399 TAGS: { min: 0, max: 5 }, // Number of total tags
400 TAG: { min: 2, max: 30 }, // Length
e4c55619 401 THUMBNAIL: { min: 2, max: 30 },
e4c87ec2
C
402 THUMBNAIL_DATA: { min: 0, max: 20000 }, // Bytes
403 VIEWS: { min: 0 },
404 LIKES: { min: 0 },
93e1258c 405 DISLIKES: { min: 0 },
c60774b0 406 FILE_SIZE: { min: 10 },
e34c85e5
C
407 URL: { min: 3, max: 2000 } // Length
408 },
418d092a
C
409 VIDEO_PLAYLISTS: {
410 NAME: { min: 1, max: 120 }, // Length
411 DESCRIPTION: { min: 3, max: 1000 }, // Length
412 URL: { min: 3, max: 2000 }, // Length
413 IMAGE: {
414 EXTNAME: [ '.jpg', '.jpeg' ],
415 FILE_SIZE: {
416 max: 2 * 1024 * 1024 // 2MB
417 }
418 }
419 },
01de67b9 420 ACTORS: {
e34c85e5
C
421 PUBLIC_KEY: { min: 10, max: 5000 }, // Length
422 PRIVATE_KEY: { min: 10, max: 5000 }, // Length
c5911fd3
C
423 URL: { min: 3, max: 2000 }, // Length
424 AVATAR: {
01de67b9
C
425 EXTNAME: [ '.png', '.jpeg', '.jpg' ],
426 FILE_SIZE: {
427 max: 2 * 1024 * 1024 // 2MB
428 }
c5911fd3 429 }
e4c87ec2
C
430 },
431 VIDEO_EVENTS: {
432 COUNT: { min: 0 }
6d852470 433 },
bf1f6508 434 VIDEO_COMMENTS: {
b32b7827 435 TEXT: { min: 1, max: 3000 }, // Length
6d852470 436 URL: { min: 3, max: 2000 } // Length
4ba3b8ea
C
437 },
438 VIDEO_SHARE: {
439 URL: { min: 3, max: 2000 } // Length
a4101923
C
440 },
441 CONTACT_FORM: {
442 FROM_NAME: { min: 1, max: 120 }, // Length
443 BODY: { min: 3, max: 5000 } // Length
e4c55619
C
444 }
445}
446
490b595a
C
447const RATES_LIMIT = {
448 LOGIN: {
449 WINDOW_MS: 5 * 60 * 1000, // 5 minutes
09becad8 450 MAX: 15 // 15 attempts
288fe385
C
451 },
452 ASK_SEND_EMAIL: {
453 WINDOW_MS: 5 * 60 * 1000, // 5 minutes
454 MAX: 3 // 3 attempts
490b595a
C
455 }
456}
457
b5c0e955 458let VIDEO_VIEW_LIFETIME = 60000 * 60 // 1 hour
a4101923
C
459let CONTACT_FORM_LIFETIME = 60000 * 60 // 1 hour
460
edb4ffc7 461const VIDEO_TRANSCODING_FPS: VideoTranscodingFPS = {
a7977280 462 MIN: 10,
3a6f351b
C
463 AVERAGE: 30,
464 MAX: 60,
465 KEEP_ORIGIN_FPS_RESOLUTION_MIN: 720 // We keep the original FPS on high resolutions (720 minimum)
a7977280 466}
b5c0e955 467
ee9e7b61 468const VIDEO_RATE_TYPES: { [ id: string ]: VideoRateType } = {
d38b8281
C
469 LIKE: 'like',
470 DISLIKE: 'dislike'
471}
472
80bc88c1
J
473const FFMPEG_NICE: { [ id: string ]: number } = {
474 THUMBNAIL: 2, // 2 just for don't blocking servers
475 TRANSCODING: 15
476}
477
6e07c3de
C
478const VIDEO_CATEGORIES = {
479 1: 'Music',
480 2: 'Films',
481 3: 'Vehicles',
482 4: 'Art',
483 5: 'Sports',
484 6: 'Travels',
485 7: 'Gaming',
486 8: 'People',
487 9: 'Comedy',
488 10: 'Entertainment',
6f2ae7a1 489 11: 'News & Politics',
40298b02 490 12: 'How To',
6e07c3de
C
491 13: 'Education',
492 14: 'Activism',
493 15: 'Science & Technology',
494 16: 'Animals',
495 17: 'Kids',
496 18: 'Food'
497}
498
6f0c39e2
C
499// See https://creativecommons.org/licenses/?lang=en
500const VIDEO_LICENCES = {
501 1: 'Attribution',
502 2: 'Attribution - Share Alike',
503 3: 'Attribution - No Derivatives',
504 4: 'Attribution - Non Commercial',
505 5: 'Attribution - Non Commercial - Share Alike',
506 6: 'Attribution - Non Commercial - No Derivatives',
507 7: 'Public Domain Dedication'
508}
509
9d3ef9fe 510const VIDEO_LANGUAGES = buildLanguages()
3092476e 511
fd45e8f4
C
512const VIDEO_PRIVACIES = {
513 [VideoPrivacy.PUBLIC]: 'Public',
514 [VideoPrivacy.UNLISTED]: 'Unlisted',
515 [VideoPrivacy.PRIVATE]: 'Private'
516}
517
2186386c
C
518const VIDEO_STATES = {
519 [VideoState.PUBLISHED]: 'Published',
fbad87b0
C
520 [VideoState.TO_TRANSCODE]: 'To transcode',
521 [VideoState.TO_IMPORT]: 'To import'
522}
523
524const VIDEO_IMPORT_STATES = {
525 [VideoImportState.FAILED]: 'Failed',
526 [VideoImportState.PENDING]: 'Pending',
527 [VideoImportState.SUCCESS]: 'Success'
2186386c
C
528}
529
268eebed
C
530const VIDEO_ABUSE_STATES = {
531 [VideoAbuseState.PENDING]: 'Pending',
532 [VideoAbuseState.REJECTED]: 'Rejected',
533 [VideoAbuseState.ACCEPTED]: 'Accepted'
534}
535
418d092a
C
536const VIDEO_PLAYLIST_PRIVACIES = {
537 [VideoPlaylistPrivacy.PUBLIC]: 'Public',
538 [VideoPlaylistPrivacy.UNLISTED]: 'Unlisted',
539 [VideoPlaylistPrivacy.PRIVATE]: 'Private'
540}
541
df0b219d
C
542const VIDEO_PLAYLIST_TYPES = {
543 [VideoPlaylistType.REGULAR]: 'Regular',
544 [VideoPlaylistType.WATCH_LATER]: 'Watch later'
545}
546
14e2014a
C
547const MIMETYPES = {
548 VIDEO: {
549 MIMETYPE_EXT: buildVideoMimetypeExt(),
550 EXT_MIMETYPE: null as { [ id: string ]: string }
551 },
552 IMAGE: {
553 MIMETYPE_EXT: {
554 'image/png': '.png',
555 'image/jpg': '.jpg',
556 'image/jpeg': '.jpg'
557 }
558 },
559 VIDEO_CAPTIONS: {
560 MIMETYPE_EXT: {
561 'text/vtt': '.vtt',
562 'application/x-subrip': '.srt'
563 }
564 },
565 TORRENT: {
566 MIMETYPE_EXT: {
567 'application/x-bittorrent': '.torrent'
568 }
569 }
990b6a0b 570}
14e2014a 571MIMETYPES.VIDEO.EXT_MIMETYPE = invert(MIMETYPES.VIDEO.MIMETYPE_EXT)
990b6a0b 572
9f6bae3a
C
573// ---------------------------------------------------------------------------
574
2d3741d6
C
575const OVERVIEWS = {
576 VIDEOS: {
1a471091 577 SAMPLE_THRESHOLD: 6,
2d3741d6
C
578 SAMPLES_COUNT: 2
579 }
580}
581
582// ---------------------------------------------------------------------------
583
50d6de9c 584const SERVER_ACTOR_NAME = 'peertube'
350e31d6 585
e4f97bab 586const ACTIVITY_PUB = {
1b5b10d1
C
587 POTENTIAL_ACCEPT_HEADERS: [
588 'application/activity+json',
9a8cbd82
C
589 'application/ld+json',
590 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
165cdc75 591 ],
1b5b10d1 592 ACCEPT_HEADER: 'application/activity+json, application/ld+json',
9a27cdc2 593 PUBLIC: 'https://www.w3.org/ns/activitystreams#Public',
0d0e8dd0 594 COLLECTION_ITEMS_PER_PAGE: 10,
c986175d 595 FETCH_PAGE_LIMIT: 100,
20494f12 596 URL_MIME_TYPES: {
14e2014a 597 VIDEO: Object.keys(MIMETYPES.VIDEO.MIMETYPE_EXT),
20494f12
C
598 TORRENT: [ 'application/x-bittorrent' ],
599 MAGNET: [ 'application/x-bittorrent;x-scheme-handler/magnet' ]
a5625b41 600 },
2ccaeeb3 601 MAX_RECURSION_COMMENTS: 100,
0e0c745b 602 ACTOR_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2, // 2 days
9f79ade6
C
603 VIDEO_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2, // 2 days
604 VIDEO_PLAYLIST_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2 // 2 days
e4f97bab
C
605}
606
50d6de9c
C
607const ACTIVITY_PUB_ACTOR_TYPES: { [ id: string ]: ActivityPubActorType } = {
608 GROUP: 'Group',
609 PERSON: 'Person',
610 APPLICATION: 'Application'
611}
612
41f2ebae
C
613const HTTP_SIGNATURE = {
614 HEADER_NAME: 'signature',
615 ALGORITHM: 'rsa-sha256',
df66d815 616 HEADERS_TO_SIGN: [ '(request-target)', 'host', 'date', 'digest' ]
41f2ebae
C
617}
618
9f6bae3a
C
619// ---------------------------------------------------------------------------
620
04b8c3fb 621let PRIVATE_RSA_KEY_SIZE = 2048
bdfbd4f1 622
9f6bae3a
C
623// Password encryption
624const BCRYPT_SALT_SIZE = 10
a877d5ac 625
ecb4e35f
C
626const USER_PASSWORD_RESET_LIFETIME = 60000 * 5 // 5 minutes
627
d9eaee39
JM
628const USER_EMAIL_VERIFY_LIFETIME = 60000 * 60 // 60 minutes
629
0883b324
C
630const NSFW_POLICY_TYPES: { [ id: string]: NSFWPolicyType } = {
631 DO_NOT_LIST: 'do_not_list',
632 BLUR: 'blur',
633 DISPLAY: 'display'
634}
635
bdfbd4f1
C
636// ---------------------------------------------------------------------------
637
052937db
C
638// Express static paths (router)
639const STATIC_PATHS = {
f285faa0
C
640 PREVIEWS: '/static/previews/',
641 THUMBNAILS: '/static/thumbnails/',
052937db 642 TORRENTS: '/static/torrents/',
c5911fd3 643 WEBSEED: '/static/webseed/',
b9fffa29 644 REDUNDANCY: '/static/redundancy/',
9c6ca37f
C
645 STREAMING_PLAYLISTS: {
646 HLS: '/static/streaming-playlists/hls'
09209296 647 },
40e87e9e
C
648 AVATARS: '/static/avatars/',
649 VIDEO_CAPTIONS: '/static/video-captions/'
052937db 650}
02756fbd
C
651const STATIC_DOWNLOAD_PATHS = {
652 TORRENTS: '/download/torrents/',
653 VIDEOS: '/download/videos/'
654}
052937db 655
dc009132 656// Cache control
57a81ff6 657let STATIC_MAX_AGE = '2h'
dc009132 658
cbe2f7c3 659// Videos thumbnail size
d8755eed 660const THUMBNAILS_SIZE = {
e5fc7811 661 width: 223,
830b4faf 662 height: 122
d8755eed
C
663}
664const PREVIEWS_SIZE = {
164174a6
C
665 width: 560,
666 height: 315
667}
e8e12200
C
668const AVATARS_SIZE = {
669 width: 120,
670 height: 120
671}
164174a6
C
672
673const EMBED_SIZE = {
674 width: 560,
675 height: 315
d8755eed 676}
cbe2f7c3 677
980246ea 678// Sub folders of cache directory
d74d29ad 679const FILES_CACHE = {
f4001cf4
C
680 PREVIEWS: {
681 DIRECTORY: join(CONFIG.STORAGE.CACHE_DIR, 'previews'),
682 MAX_AGE: 1000 * 3600 * 3 // 3 hours
683 },
684 VIDEO_CAPTIONS: {
685 DIRECTORY: join(CONFIG.STORAGE.CACHE_DIR, 'video-captions'),
686 MAX_AGE: 1000 * 3600 * 3 // 3 hours
f981dae8
C
687 }
688}
689
d74d29ad
C
690const CACHE = {
691 USER_TOKENS: {
692 MAX_SIZE: 10000
693 }
694}
695
9c6ca37f 696const HLS_STREAMING_PLAYLIST_DIRECTORY = join(CONFIG.STORAGE.STREAMING_PLAYLISTS_DIR, 'hls')
09209296
C
697const HLS_REDUNDANCY_DIRECTORY = join(CONFIG.STORAGE.REDUNDANCY_DIR, 'hls')
698
7348b1fd
C
699const MEMOIZE_TTL = {
700 OVERVIEWS_SAMPLE: 1000 * 3600 * 4 // 4 hours
701}
702
c48e82b5
C
703const REDUNDANCY = {
704 VIDEOS: {
c48e82b5
C
705 RANDOMIZED_FACTOR: 5
706 }
707}
708
e12a0092 709const ACCEPT_HEADERS = [ 'html', 'application/json' ].concat(ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS)
4f491371 710
bdfbd4f1
C
711// ---------------------------------------------------------------------------
712
e032aec9
C
713const CUSTOM_HTML_TAG_COMMENTS = {
714 TITLE: '<!-- title tag -->',
715 DESCRIPTION: '<!-- description tag -->',
716 CUSTOM_CSS: '<!-- custom css tag -->',
92bf2f62 717 META_TAGS: '<!-- meta tags -->'
e032aec9 718}
709756b8
C
719
720// ---------------------------------------------------------------------------
721
4195cd2b 722const FEEDS = {
fd4484f1 723 COUNT: 20
4195cd2b
C
724}
725
726// ---------------------------------------------------------------------------
727
9b67da3d
C
728const TRACKER_RATE_LIMITS = {
729 INTERVAL: 60000 * 5, // 5 minutes
8244c85a 730 ANNOUNCES_PER_IP_PER_INFOHASH: 15, // maximum announces per torrent in the interval
9b67da3d
C
731 ANNOUNCES_PER_IP: 30 // maximum announces for all our torrents in the interval
732}
733
ae9bbed4
C
734const P2P_MEDIA_LOADER_PEER_VERSION = 2
735
9b67da3d
C
736// ---------------------------------------------------------------------------
737
9f10b292
C
738// Special constants for a test instance
739if (isTestInstance() === true) {
04b8c3fb
C
740 PRIVATE_RSA_KEY_SIZE = 1024
741
60650c77 742 ACTOR_FOLLOW_SCORE.BASE = 20
3cd0734f 743
f285faa0
C
744 REMOTE_SCHEME.HTTP = 'http'
745 REMOTE_SCHEME.WS = 'ws'
3cd0734f 746
65fcc311 747 STATIC_MAX_AGE = '0'
3cd0734f 748
c46edbc2 749 ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE = 2
7bc29171 750 ACTIVITY_PUB.ACTOR_REFRESH_INTERVAL = 10 * 1000 // 10 seconds
1297eb5d 751 ACTIVITY_PUB.VIDEO_REFRESH_INTERVAL = 10 * 1000 // 10 seconds
9f79ade6 752 ACTIVITY_PUB.VIDEO_PLAYLIST_REFRESH_INTERVAL = 10 * 1000 // 10 seconds
3cd0734f 753
01de67b9 754 CONSTRAINTS_FIELDS.ACTORS.AVATAR.FILE_SIZE.max = 100 * 1024 // 100KB
3cd0734f 755
2f5c6b2f 756 SCHEDULER_INTERVALS_MS.actorFollowScores = 1000
2baea0c7
C
757 SCHEDULER_INTERVALS_MS.removeOldJobs = 10000
758 SCHEDULER_INTERVALS_MS.updateVideos = 5000
6b616860 759 REPEAT_JOBS['videos-views'] = { every: 5000 }
2baea0c7 760
c48e82b5
C
761 REDUNDANCY.VIDEOS.RANDOMIZED_FACTOR = 1
762
b5c0e955 763 VIDEO_VIEW_LIFETIME = 1000 // 1 second
a4101923 764 CONTACT_FORM_LIFETIME = 1000 // 1 second
3cd0734f
C
765
766 JOB_ATTEMPTS['email'] = 1
f4001cf4 767
d74d29ad 768 FILES_CACHE.VIDEO_CAPTIONS.MAX_AGE = 3000
743164fe 769 MEMOIZE_TTL.OVERVIEWS_SAMPLE = 1
c07b6041 770 ROUTE_CACHE_LIFETIME.OVERVIEWS.VIDEOS = '0ms'
b426edd4
C
771
772 RATES_LIMIT.LOGIN.MAX = 20
9f10b292
C
773}
774
14e2014a 775updateWebserverUrls()
225a89c2 776
9f10b292
C
777// ---------------------------------------------------------------------------
778
65fcc311 779export {
9f6bae3a 780 API_VERSION,
09209296 781 HLS_REDUNDANCY_DIRECTORY,
ae9bbed4 782 P2P_MEDIA_LOADER_PEER_VERSION,
e8e12200 783 AVATARS_SIZE,
4f491371 784 ACCEPT_HEADERS,
9f6bae3a 785 BCRYPT_SALT_SIZE,
9b67da3d 786 TRACKER_RATE_LIMITS,
d74d29ad 787 FILES_CACHE,
9f6bae3a
C
788 CONFIG,
789 CONSTRAINTS_FIELDS,
164174a6 790 EMBED_SIZE,
c48e82b5 791 REDUNDANCY,
94a5ff8a
C
792 JOB_CONCURRENCY,
793 JOB_ATTEMPTS,
b769007f 794 LAST_MIGRATION_VERSION,
9f6bae3a 795 OAUTH_LIFETIME,
e032aec9 796 CUSTOM_HTML_TAG_COMMENTS,
f55e5a7b 797 BROADCAST_CONCURRENCY,
1194e8b4 798 PAGINATION,
60650c77 799 ACTOR_FOLLOW_SCORE,
f285faa0
C
800 PREVIEWS_SIZE,
801 REMOTE_SCHEME,
7a7724e6 802 FOLLOW_STATES,
50d6de9c 803 SERVER_ACTOR_NAME,
e4f97bab 804 PRIVATE_RSA_KEY_SIZE,
fd4484f1 805 ROUTE_CACHE_LIFETIME,
9f6bae3a 806 SORTABLE_COLUMNS,
9c6ca37f 807 HLS_STREAMING_PLAYLIST_DIRECTORY,
4195cd2b 808 FEEDS,
2b86fe72 809 JOB_TTL,
0883b324 810 NSFW_POLICY_TYPES,
dc009132 811 STATIC_MAX_AGE,
a6375e69 812 STATIC_PATHS,
cf9166cf 813 VIDEO_IMPORT_TIMEOUT,
df0b219d 814 VIDEO_PLAYLIST_TYPES,
e4f97bab 815 ACTIVITY_PUB,
50d6de9c 816 ACTIVITY_PUB_ACTOR_TYPES,
9f6bae3a 817 THUMBNAILS_SIZE,
6e07c3de 818 VIDEO_CATEGORIES,
3092476e 819 VIDEO_LANGUAGES,
fd45e8f4 820 VIDEO_PRIVACIES,
6f0c39e2 821 VIDEO_LICENCES,
2186386c 822 VIDEO_STATES,
0d0e8dd0 823 VIDEO_RATE_TYPES,
a7977280 824 VIDEO_TRANSCODING_FPS,
80bc88c1 825 FFMPEG_NICE,
268eebed 826 VIDEO_ABUSE_STATES,
d74d29ad 827 CACHE,
71e3dfda 828 JOB_REQUEST_TIMEOUT,
ecb4e35f 829 USER_PASSWORD_RESET_LIFETIME,
7348b1fd 830 MEMOIZE_TTL,
d9eaee39 831 USER_EMAIL_VERIFY_LIFETIME,
2d3741d6 832 OVERVIEWS,
2baea0c7 833 SCHEDULER_INTERVALS_MS,
6b616860 834 REPEAT_JOBS,
02756fbd 835 STATIC_DOWNLOAD_PATHS,
490b595a 836 RATES_LIMIT,
14e2014a 837 MIMETYPES,
f6eebcb3 838 CRAWL_REQUEST_CONCURRENCY,
b5c0e955 839 JOB_COMPLETED_LIFETIME,
41f2ebae 840 HTTP_SIGNATURE,
fbad87b0 841 VIDEO_IMPORT_STATES,
7ce44a74 842 VIDEO_VIEW_LIFETIME,
a4101923 843 CONTACT_FORM_LIFETIME,
418d092a 844 VIDEO_PLAYLIST_PRIVACIES,
7ce44a74 845 buildLanguages
9f10b292 846}
fd206f0b
C
847
848// ---------------------------------------------------------------------------
849
850function getLocalConfigFilePath () {
851 const configSources = config.util.getConfigSources()
852 if (configSources.length === 0) throw new Error('Invalid config source.')
853
854 let filename = 'local'
855 if (process.env.NODE_ENV) filename += `-${process.env.NODE_ENV}`
856 if (process.env.NODE_APP_INSTANCE) filename += `-${process.env.NODE_APP_INSTANCE}`
857
858 return join(dirname(configSources[ 0 ].name), filename + '.json')
859}
860
14e2014a
C
861function buildVideoMimetypeExt () {
862 const data = {
863 'video/webm': '.webm',
864 'video/ogg': '.ogv',
865 'video/mp4': '.mp4'
866 }
867
868 if (CONFIG.TRANSCODING.ENABLED && CONFIG.TRANSCODING.ALLOW_ADDITIONAL_EXTENSIONS) {
869 Object.assign(data, {
870 'video/quicktime': '.mov',
871 'video/x-msvideo': '.avi',
872 'video/x-flv': '.flv',
307902e2
C
873 'video/x-matroska': '.mkv',
874 'application/octet-stream': '.mkv',
875 'video/avi': '.avi'
14e2014a
C
876 })
877 }
878
879 return data
880}
881
882function updateWebserverUrls () {
fd206f0b
C
883 CONFIG.WEBSERVER.URL = sanitizeUrl(CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT)
884 CONFIG.WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT, REMOTE_SCHEME.HTTP)
885}
886
14e2014a
C
887function updateWebserverConfig () {
888 CONSTRAINTS_FIELDS.VIDEOS.EXTNAME = buildVideosExtname()
889
890 MIMETYPES.VIDEO.MIMETYPE_EXT = buildVideoMimetypeExt()
891 MIMETYPES.VIDEO.EXT_MIMETYPE = invert(MIMETYPES.VIDEO.MIMETYPE_EXT)
892}
893
894function buildVideosExtname () {
895 return CONFIG.TRANSCODING.ENABLED && CONFIG.TRANSCODING.ALLOW_ADDITIONAL_EXTENSIONS
896 ? [ '.mp4', '.ogv', '.webm', '.mkv', '.mov', '.avi', '.flv' ]
897 : [ '.mp4', '.ogv', '.webm' ]
898}
899
e5565833 900function buildVideosRedundancy (objs: any[]): VideosRedundancy[] {
c48e82b5
C
901 if (!objs) return []
902
d85798c4
C
903 if (!Array.isArray(objs)) return objs
904
e5565833 905 return objs.map(obj => {
f9a971c6 906 return Object.assign({}, obj, {
e5565833
C
907 minLifetime: parseDuration(obj.min_lifetime),
908 size: bytes.parse(obj.size),
909 minViews: obj.min_views
910 })
911 })
c48e82b5
C
912}
913
9d3ef9fe
C
914function buildLanguages () {
915 const iso639 = require('iso-639-3')
916
917 const languages: { [ id: string ]: string } = {}
918
1d94c154
C
919 const additionalLanguages = {
920 'sgn': true, // Sign languages (macro language)
921 'ase': true, // American sign language
922 'sdl': true, // Arabian sign language
923 'bfi': true, // British sign language
924 'bzs': true, // Brazilian sign language
925 'csl': true, // Chinese sign language
926 'cse': true, // Czech sign language
927 'dsl': true, // Danish sign language
928 'fsl': true, // French sign language
929 'gsg': true, // German sign language
930 'pks': true, // Pakistan sign language
931 'jsl': true, // Japanese sign language
932 'sfs': true, // South African sign language
933 'swl': true, // Swedish sign language
934 'rsl': true, // Russian sign language: true
935
936 'epo': true, // Esperanto
937 'tlh': true, // Klingon
938 'jbo': true, // Lojban
939 'avk': true // Kotava
940 }
9d3ef9fe
C
941
942 // Only add ISO639-1 languages and some sign languages (ISO639-3)
943 iso639
944 .filter(l => {
945 return (l.iso6391 !== null && l.type === 'living') ||
1d94c154 946 additionalLanguages[l.iso6393] === true
9d3ef9fe
C
947 })
948 .forEach(l => languages[l.iso6391 || l.iso6393] = l.name)
949
db6d617d
C
950 // Override Occitan label
951 languages['oc'] = 'Occitan'
952
9d3ef9fe
C
953 return languages
954}
955
fd206f0b
C
956export function reloadConfig () {
957
958 function directory () {
959 if (process.env.NODE_CONFIG_DIR) {
960 return process.env.NODE_CONFIG_DIR
961 }
962
963 return join(root(), 'config')
964 }
965
966 function purge () {
967 for (const fileName in require.cache) {
968 if (-1 === fileName.indexOf(directory())) {
969 continue
970 }
971
972 delete require.cache[fileName]
973 }
974
975 delete require.cache[require.resolve('config')]
976 }
977
978 purge()
979
980 config = require('config')
981
982 updateWebserverConfig()
14e2014a 983 updateWebserverUrls()
fd206f0b 984}