]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/initializers/constants.ts
Add new instance follower notification in client
[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
8ce1ba6e 21const LAST_MIGRATION_VERSION = 360
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: {
14893eb7
C
330 get ENABLED () { return config.get<boolean>('followers.instance.enabled') },
331 get MANUAL_APPROVAL () { return config.get<boolean>('followers.instance.manual_approval') }
5b9c965d 332 }
e861452f
C
333 }
334}
e861452f 335
9f6bae3a
C
336// ---------------------------------------------------------------------------
337
14e2014a 338let CONSTRAINTS_FIELDS = {
e4c55619 339 USERS: {
9f7a1953 340 NAME: { min: 1, max: 120 }, // Length
d23e6a1c 341 DESCRIPTION: { min: 3, max: 1000 }, // Length
d0ce42c1 342 USERNAME: { min: 1, max: 50 }, // Length
b0f9f39e 343 PASSWORD: { min: 6, max: 255 }, // Length
eacb25c4 344 VIDEO_QUOTA: { min: -1 },
bee0abff 345 VIDEO_QUOTA_DAILY: { min: -1 },
eacb25c4 346 BLOCKED_REASON: { min: 3, max: 250 } // Length
e4c55619 347 },
55fa55a9 348 VIDEO_ABUSES: {
1506307f
C
349 REASON: { min: 2, max: 3000 }, // Length
350 MODERATION_COMMENT: { min: 2, max: 3000 } // Length
55fa55a9 351 },
26b7305a
C
352 VIDEO_BLACKLIST: {
353 REASON: { min: 2, max: 300 } // Length
354 },
72c7248b 355 VIDEO_CHANNELS: {
9f7a1953 356 NAME: { min: 1, max: 120 }, // Length
d23e6a1c
BY
357 DESCRIPTION: { min: 3, max: 1000 }, // Length
358 SUPPORT: { min: 3, max: 1000 }, // Length
e34c85e5 359 URL: { min: 3, max: 2000 } // Length
72c7248b 360 },
40e87e9e
C
361 VIDEO_CAPTIONS: {
362 CAPTION_FILE: {
f4001cf4 363 EXTNAME: [ '.vtt', '.srt' ],
40e87e9e
C
364 FILE_SIZE: {
365 max: 2 * 1024 * 1024 // 2MB
366 }
367 }
368 },
fbad87b0 369 VIDEO_IMPORTS: {
ce33919c
C
370 URL: { min: 3, max: 2000 }, // Length
371 TORRENT_NAME: { min: 3, max: 255 }, // Length
990b6a0b
C
372 TORRENT_FILE: {
373 EXTNAME: [ '.torrent' ],
374 FILE_SIZE: {
375 max: 1024 * 200 // 200 KB
376 }
377 }
fbad87b0 378 },
c48e82b5
C
379 VIDEOS_REDUNDANCY: {
380 URL: { min: 3, max: 2000 } // Length
381 },
5c6d985f
C
382 VIDEO_RATES: {
383 URL: { min: 3, max: 2000 } // Length
384 },
e4c55619 385 VIDEOS: {
a265f7f3 386 NAME: { min: 3, max: 120 }, // Length
9d3ef9fe 387 LANGUAGE: { min: 1, max: 10 }, // Length
9567011b 388 TRUNCATED_DESCRIPTION: { min: 3, max: 250 }, // Length
2422c46b 389 DESCRIPTION: { min: 3, max: 10000 }, // Length
d23e6a1c 390 SUPPORT: { min: 3, max: 1000 }, // Length
ac81d1a0
C
391 IMAGE: {
392 EXTNAME: [ '.jpg', '.jpeg' ],
393 FILE_SIZE: {
394 max: 2 * 1024 * 1024 // 2MB
395 }
396 },
14e2014a 397 EXTNAME: buildVideosExtname(),
0e1dc3e7 398 INFO_HASH: { min: 40, max: 40 }, // Length, info hash is 20 bytes length but we represent it in hexadecimal so 20 * 2
fbad87b0 399 DURATION: { min: 0 }, // Number
a265f7f3
C
400 TAGS: { min: 0, max: 5 }, // Number of total tags
401 TAG: { min: 2, max: 30 }, // Length
e4c55619 402 THUMBNAIL: { min: 2, max: 30 },
e4c87ec2
C
403 THUMBNAIL_DATA: { min: 0, max: 20000 }, // Bytes
404 VIEWS: { min: 0 },
405 LIKES: { min: 0 },
93e1258c 406 DISLIKES: { min: 0 },
c60774b0 407 FILE_SIZE: { min: 10 },
e34c85e5
C
408 URL: { min: 3, max: 2000 } // Length
409 },
418d092a
C
410 VIDEO_PLAYLISTS: {
411 NAME: { min: 1, max: 120 }, // Length
412 DESCRIPTION: { min: 3, max: 1000 }, // Length
413 URL: { min: 3, max: 2000 }, // Length
414 IMAGE: {
415 EXTNAME: [ '.jpg', '.jpeg' ],
416 FILE_SIZE: {
417 max: 2 * 1024 * 1024 // 2MB
418 }
419 }
420 },
01de67b9 421 ACTORS: {
e34c85e5
C
422 PUBLIC_KEY: { min: 10, max: 5000 }, // Length
423 PRIVATE_KEY: { min: 10, max: 5000 }, // Length
c5911fd3
C
424 URL: { min: 3, max: 2000 }, // Length
425 AVATAR: {
01de67b9
C
426 EXTNAME: [ '.png', '.jpeg', '.jpg' ],
427 FILE_SIZE: {
428 max: 2 * 1024 * 1024 // 2MB
429 }
c5911fd3 430 }
e4c87ec2
C
431 },
432 VIDEO_EVENTS: {
433 COUNT: { min: 0 }
6d852470 434 },
bf1f6508 435 VIDEO_COMMENTS: {
b32b7827 436 TEXT: { min: 1, max: 3000 }, // Length
6d852470 437 URL: { min: 3, max: 2000 } // Length
4ba3b8ea
C
438 },
439 VIDEO_SHARE: {
440 URL: { min: 3, max: 2000 } // Length
a4101923
C
441 },
442 CONTACT_FORM: {
443 FROM_NAME: { min: 1, max: 120 }, // Length
444 BODY: { min: 3, max: 5000 } // Length
e4c55619
C
445 }
446}
447
490b595a
C
448const RATES_LIMIT = {
449 LOGIN: {
450 WINDOW_MS: 5 * 60 * 1000, // 5 minutes
09becad8 451 MAX: 15 // 15 attempts
288fe385
C
452 },
453 ASK_SEND_EMAIL: {
454 WINDOW_MS: 5 * 60 * 1000, // 5 minutes
455 MAX: 3 // 3 attempts
490b595a
C
456 }
457}
458
b5c0e955 459let VIDEO_VIEW_LIFETIME = 60000 * 60 // 1 hour
a4101923
C
460let CONTACT_FORM_LIFETIME = 60000 * 60 // 1 hour
461
edb4ffc7 462const VIDEO_TRANSCODING_FPS: VideoTranscodingFPS = {
a7977280 463 MIN: 10,
3a6f351b
C
464 AVERAGE: 30,
465 MAX: 60,
466 KEEP_ORIGIN_FPS_RESOLUTION_MIN: 720 // We keep the original FPS on high resolutions (720 minimum)
a7977280 467}
b5c0e955 468
ee9e7b61 469const VIDEO_RATE_TYPES: { [ id: string ]: VideoRateType } = {
d38b8281
C
470 LIKE: 'like',
471 DISLIKE: 'dislike'
472}
473
80bc88c1
J
474const FFMPEG_NICE: { [ id: string ]: number } = {
475 THUMBNAIL: 2, // 2 just for don't blocking servers
476 TRANSCODING: 15
477}
478
6e07c3de
C
479const VIDEO_CATEGORIES = {
480 1: 'Music',
481 2: 'Films',
482 3: 'Vehicles',
483 4: 'Art',
484 5: 'Sports',
485 6: 'Travels',
486 7: 'Gaming',
487 8: 'People',
488 9: 'Comedy',
489 10: 'Entertainment',
6f2ae7a1 490 11: 'News & Politics',
40298b02 491 12: 'How To',
6e07c3de
C
492 13: 'Education',
493 14: 'Activism',
494 15: 'Science & Technology',
495 16: 'Animals',
496 17: 'Kids',
497 18: 'Food'
498}
499
6f0c39e2
C
500// See https://creativecommons.org/licenses/?lang=en
501const VIDEO_LICENCES = {
502 1: 'Attribution',
503 2: 'Attribution - Share Alike',
504 3: 'Attribution - No Derivatives',
505 4: 'Attribution - Non Commercial',
506 5: 'Attribution - Non Commercial - Share Alike',
507 6: 'Attribution - Non Commercial - No Derivatives',
508 7: 'Public Domain Dedication'
509}
510
9d3ef9fe 511const VIDEO_LANGUAGES = buildLanguages()
3092476e 512
fd45e8f4
C
513const VIDEO_PRIVACIES = {
514 [VideoPrivacy.PUBLIC]: 'Public',
515 [VideoPrivacy.UNLISTED]: 'Unlisted',
516 [VideoPrivacy.PRIVATE]: 'Private'
517}
518
2186386c
C
519const VIDEO_STATES = {
520 [VideoState.PUBLISHED]: 'Published',
fbad87b0
C
521 [VideoState.TO_TRANSCODE]: 'To transcode',
522 [VideoState.TO_IMPORT]: 'To import'
523}
524
525const VIDEO_IMPORT_STATES = {
526 [VideoImportState.FAILED]: 'Failed',
527 [VideoImportState.PENDING]: 'Pending',
528 [VideoImportState.SUCCESS]: 'Success'
2186386c
C
529}
530
268eebed
C
531const VIDEO_ABUSE_STATES = {
532 [VideoAbuseState.PENDING]: 'Pending',
533 [VideoAbuseState.REJECTED]: 'Rejected',
534 [VideoAbuseState.ACCEPTED]: 'Accepted'
535}
536
418d092a
C
537const VIDEO_PLAYLIST_PRIVACIES = {
538 [VideoPlaylistPrivacy.PUBLIC]: 'Public',
539 [VideoPlaylistPrivacy.UNLISTED]: 'Unlisted',
540 [VideoPlaylistPrivacy.PRIVATE]: 'Private'
541}
542
df0b219d
C
543const VIDEO_PLAYLIST_TYPES = {
544 [VideoPlaylistType.REGULAR]: 'Regular',
545 [VideoPlaylistType.WATCH_LATER]: 'Watch later'
546}
547
14e2014a
C
548const MIMETYPES = {
549 VIDEO: {
550 MIMETYPE_EXT: buildVideoMimetypeExt(),
551 EXT_MIMETYPE: null as { [ id: string ]: string }
552 },
553 IMAGE: {
554 MIMETYPE_EXT: {
555 'image/png': '.png',
556 'image/jpg': '.jpg',
557 'image/jpeg': '.jpg'
558 }
559 },
560 VIDEO_CAPTIONS: {
561 MIMETYPE_EXT: {
562 'text/vtt': '.vtt',
563 'application/x-subrip': '.srt'
564 }
565 },
566 TORRENT: {
567 MIMETYPE_EXT: {
568 'application/x-bittorrent': '.torrent'
569 }
570 }
990b6a0b 571}
14e2014a 572MIMETYPES.VIDEO.EXT_MIMETYPE = invert(MIMETYPES.VIDEO.MIMETYPE_EXT)
990b6a0b 573
9f6bae3a
C
574// ---------------------------------------------------------------------------
575
2d3741d6
C
576const OVERVIEWS = {
577 VIDEOS: {
1a471091 578 SAMPLE_THRESHOLD: 6,
2d3741d6
C
579 SAMPLES_COUNT: 2
580 }
581}
582
583// ---------------------------------------------------------------------------
584
50d6de9c 585const SERVER_ACTOR_NAME = 'peertube'
350e31d6 586
e4f97bab 587const ACTIVITY_PUB = {
1b5b10d1
C
588 POTENTIAL_ACCEPT_HEADERS: [
589 'application/activity+json',
9a8cbd82
C
590 'application/ld+json',
591 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
165cdc75 592 ],
1b5b10d1 593 ACCEPT_HEADER: 'application/activity+json, application/ld+json',
9a27cdc2 594 PUBLIC: 'https://www.w3.org/ns/activitystreams#Public',
0d0e8dd0 595 COLLECTION_ITEMS_PER_PAGE: 10,
c986175d 596 FETCH_PAGE_LIMIT: 100,
20494f12 597 URL_MIME_TYPES: {
14e2014a 598 VIDEO: Object.keys(MIMETYPES.VIDEO.MIMETYPE_EXT),
20494f12
C
599 TORRENT: [ 'application/x-bittorrent' ],
600 MAGNET: [ 'application/x-bittorrent;x-scheme-handler/magnet' ]
a5625b41 601 },
2ccaeeb3 602 MAX_RECURSION_COMMENTS: 100,
0e0c745b 603 ACTOR_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2, // 2 days
9f79ade6
C
604 VIDEO_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2, // 2 days
605 VIDEO_PLAYLIST_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2 // 2 days
e4f97bab
C
606}
607
50d6de9c
C
608const ACTIVITY_PUB_ACTOR_TYPES: { [ id: string ]: ActivityPubActorType } = {
609 GROUP: 'Group',
610 PERSON: 'Person',
611 APPLICATION: 'Application'
612}
613
41f2ebae
C
614const HTTP_SIGNATURE = {
615 HEADER_NAME: 'signature',
616 ALGORITHM: 'rsa-sha256',
df66d815 617 HEADERS_TO_SIGN: [ '(request-target)', 'host', 'date', 'digest' ]
41f2ebae
C
618}
619
9f6bae3a
C
620// ---------------------------------------------------------------------------
621
04b8c3fb 622let PRIVATE_RSA_KEY_SIZE = 2048
bdfbd4f1 623
9f6bae3a
C
624// Password encryption
625const BCRYPT_SALT_SIZE = 10
a877d5ac 626
ecb4e35f
C
627const USER_PASSWORD_RESET_LIFETIME = 60000 * 5 // 5 minutes
628
d9eaee39
JM
629const USER_EMAIL_VERIFY_LIFETIME = 60000 * 60 // 60 minutes
630
0883b324
C
631const NSFW_POLICY_TYPES: { [ id: string]: NSFWPolicyType } = {
632 DO_NOT_LIST: 'do_not_list',
633 BLUR: 'blur',
634 DISPLAY: 'display'
635}
636
bdfbd4f1
C
637// ---------------------------------------------------------------------------
638
052937db
C
639// Express static paths (router)
640const STATIC_PATHS = {
f285faa0
C
641 PREVIEWS: '/static/previews/',
642 THUMBNAILS: '/static/thumbnails/',
052937db 643 TORRENTS: '/static/torrents/',
c5911fd3 644 WEBSEED: '/static/webseed/',
b9fffa29 645 REDUNDANCY: '/static/redundancy/',
9c6ca37f
C
646 STREAMING_PLAYLISTS: {
647 HLS: '/static/streaming-playlists/hls'
09209296 648 },
40e87e9e
C
649 AVATARS: '/static/avatars/',
650 VIDEO_CAPTIONS: '/static/video-captions/'
052937db 651}
02756fbd
C
652const STATIC_DOWNLOAD_PATHS = {
653 TORRENTS: '/download/torrents/',
654 VIDEOS: '/download/videos/'
655}
052937db 656
dc009132 657// Cache control
57a81ff6 658let STATIC_MAX_AGE = '2h'
dc009132 659
cbe2f7c3 660// Videos thumbnail size
d8755eed 661const THUMBNAILS_SIZE = {
e5fc7811 662 width: 223,
830b4faf 663 height: 122
d8755eed
C
664}
665const PREVIEWS_SIZE = {
164174a6
C
666 width: 560,
667 height: 315
668}
e8e12200
C
669const AVATARS_SIZE = {
670 width: 120,
671 height: 120
672}
164174a6
C
673
674const EMBED_SIZE = {
675 width: 560,
676 height: 315
d8755eed 677}
cbe2f7c3 678
980246ea 679// Sub folders of cache directory
d74d29ad 680const FILES_CACHE = {
f4001cf4
C
681 PREVIEWS: {
682 DIRECTORY: join(CONFIG.STORAGE.CACHE_DIR, 'previews'),
683 MAX_AGE: 1000 * 3600 * 3 // 3 hours
684 },
685 VIDEO_CAPTIONS: {
686 DIRECTORY: join(CONFIG.STORAGE.CACHE_DIR, 'video-captions'),
687 MAX_AGE: 1000 * 3600 * 3 // 3 hours
f981dae8
C
688 }
689}
690
d74d29ad
C
691const CACHE = {
692 USER_TOKENS: {
693 MAX_SIZE: 10000
694 }
695}
696
9c6ca37f 697const HLS_STREAMING_PLAYLIST_DIRECTORY = join(CONFIG.STORAGE.STREAMING_PLAYLISTS_DIR, 'hls')
09209296
C
698const HLS_REDUNDANCY_DIRECTORY = join(CONFIG.STORAGE.REDUNDANCY_DIR, 'hls')
699
7348b1fd
C
700const MEMOIZE_TTL = {
701 OVERVIEWS_SAMPLE: 1000 * 3600 * 4 // 4 hours
702}
703
c48e82b5
C
704const REDUNDANCY = {
705 VIDEOS: {
c48e82b5
C
706 RANDOMIZED_FACTOR: 5
707 }
708}
709
e12a0092 710const ACCEPT_HEADERS = [ 'html', 'application/json' ].concat(ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS)
4f491371 711
bdfbd4f1
C
712// ---------------------------------------------------------------------------
713
e032aec9
C
714const CUSTOM_HTML_TAG_COMMENTS = {
715 TITLE: '<!-- title tag -->',
716 DESCRIPTION: '<!-- description tag -->',
717 CUSTOM_CSS: '<!-- custom css tag -->',
92bf2f62 718 META_TAGS: '<!-- meta tags -->'
e032aec9 719}
709756b8
C
720
721// ---------------------------------------------------------------------------
722
4195cd2b 723const FEEDS = {
fd4484f1 724 COUNT: 20
4195cd2b
C
725}
726
727// ---------------------------------------------------------------------------
728
9b67da3d
C
729const TRACKER_RATE_LIMITS = {
730 INTERVAL: 60000 * 5, // 5 minutes
8244c85a 731 ANNOUNCES_PER_IP_PER_INFOHASH: 15, // maximum announces per torrent in the interval
9b67da3d
C
732 ANNOUNCES_PER_IP: 30 // maximum announces for all our torrents in the interval
733}
734
ae9bbed4
C
735const P2P_MEDIA_LOADER_PEER_VERSION = 2
736
9b67da3d
C
737// ---------------------------------------------------------------------------
738
9f10b292
C
739// Special constants for a test instance
740if (isTestInstance() === true) {
04b8c3fb
C
741 PRIVATE_RSA_KEY_SIZE = 1024
742
60650c77 743 ACTOR_FOLLOW_SCORE.BASE = 20
3cd0734f 744
f285faa0
C
745 REMOTE_SCHEME.HTTP = 'http'
746 REMOTE_SCHEME.WS = 'ws'
3cd0734f 747
65fcc311 748 STATIC_MAX_AGE = '0'
3cd0734f 749
c46edbc2 750 ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE = 2
7bc29171 751 ACTIVITY_PUB.ACTOR_REFRESH_INTERVAL = 10 * 1000 // 10 seconds
1297eb5d 752 ACTIVITY_PUB.VIDEO_REFRESH_INTERVAL = 10 * 1000 // 10 seconds
9f79ade6 753 ACTIVITY_PUB.VIDEO_PLAYLIST_REFRESH_INTERVAL = 10 * 1000 // 10 seconds
3cd0734f 754
01de67b9 755 CONSTRAINTS_FIELDS.ACTORS.AVATAR.FILE_SIZE.max = 100 * 1024 // 100KB
3cd0734f 756
2f5c6b2f 757 SCHEDULER_INTERVALS_MS.actorFollowScores = 1000
2baea0c7
C
758 SCHEDULER_INTERVALS_MS.removeOldJobs = 10000
759 SCHEDULER_INTERVALS_MS.updateVideos = 5000
6b616860 760 REPEAT_JOBS['videos-views'] = { every: 5000 }
2baea0c7 761
c48e82b5
C
762 REDUNDANCY.VIDEOS.RANDOMIZED_FACTOR = 1
763
b5c0e955 764 VIDEO_VIEW_LIFETIME = 1000 // 1 second
a4101923 765 CONTACT_FORM_LIFETIME = 1000 // 1 second
3cd0734f
C
766
767 JOB_ATTEMPTS['email'] = 1
f4001cf4 768
d74d29ad 769 FILES_CACHE.VIDEO_CAPTIONS.MAX_AGE = 3000
743164fe 770 MEMOIZE_TTL.OVERVIEWS_SAMPLE = 1
c07b6041 771 ROUTE_CACHE_LIFETIME.OVERVIEWS.VIDEOS = '0ms'
b426edd4
C
772
773 RATES_LIMIT.LOGIN.MAX = 20
9f10b292
C
774}
775
14e2014a 776updateWebserverUrls()
225a89c2 777
9f10b292
C
778// ---------------------------------------------------------------------------
779
65fcc311 780export {
9f6bae3a 781 API_VERSION,
09209296 782 HLS_REDUNDANCY_DIRECTORY,
ae9bbed4 783 P2P_MEDIA_LOADER_PEER_VERSION,
e8e12200 784 AVATARS_SIZE,
4f491371 785 ACCEPT_HEADERS,
9f6bae3a 786 BCRYPT_SALT_SIZE,
9b67da3d 787 TRACKER_RATE_LIMITS,
d74d29ad 788 FILES_CACHE,
9f6bae3a
C
789 CONFIG,
790 CONSTRAINTS_FIELDS,
164174a6 791 EMBED_SIZE,
c48e82b5 792 REDUNDANCY,
94a5ff8a
C
793 JOB_CONCURRENCY,
794 JOB_ATTEMPTS,
b769007f 795 LAST_MIGRATION_VERSION,
9f6bae3a 796 OAUTH_LIFETIME,
e032aec9 797 CUSTOM_HTML_TAG_COMMENTS,
f55e5a7b 798 BROADCAST_CONCURRENCY,
1194e8b4 799 PAGINATION,
60650c77 800 ACTOR_FOLLOW_SCORE,
f285faa0
C
801 PREVIEWS_SIZE,
802 REMOTE_SCHEME,
7a7724e6 803 FOLLOW_STATES,
50d6de9c 804 SERVER_ACTOR_NAME,
e4f97bab 805 PRIVATE_RSA_KEY_SIZE,
fd4484f1 806 ROUTE_CACHE_LIFETIME,
9f6bae3a 807 SORTABLE_COLUMNS,
9c6ca37f 808 HLS_STREAMING_PLAYLIST_DIRECTORY,
4195cd2b 809 FEEDS,
2b86fe72 810 JOB_TTL,
0883b324 811 NSFW_POLICY_TYPES,
dc009132 812 STATIC_MAX_AGE,
a6375e69 813 STATIC_PATHS,
cf9166cf 814 VIDEO_IMPORT_TIMEOUT,
df0b219d 815 VIDEO_PLAYLIST_TYPES,
e4f97bab 816 ACTIVITY_PUB,
50d6de9c 817 ACTIVITY_PUB_ACTOR_TYPES,
9f6bae3a 818 THUMBNAILS_SIZE,
6e07c3de 819 VIDEO_CATEGORIES,
3092476e 820 VIDEO_LANGUAGES,
fd45e8f4 821 VIDEO_PRIVACIES,
6f0c39e2 822 VIDEO_LICENCES,
2186386c 823 VIDEO_STATES,
0d0e8dd0 824 VIDEO_RATE_TYPES,
a7977280 825 VIDEO_TRANSCODING_FPS,
80bc88c1 826 FFMPEG_NICE,
268eebed 827 VIDEO_ABUSE_STATES,
d74d29ad 828 CACHE,
71e3dfda 829 JOB_REQUEST_TIMEOUT,
ecb4e35f 830 USER_PASSWORD_RESET_LIFETIME,
7348b1fd 831 MEMOIZE_TTL,
d9eaee39 832 USER_EMAIL_VERIFY_LIFETIME,
2d3741d6 833 OVERVIEWS,
2baea0c7 834 SCHEDULER_INTERVALS_MS,
6b616860 835 REPEAT_JOBS,
02756fbd 836 STATIC_DOWNLOAD_PATHS,
490b595a 837 RATES_LIMIT,
14e2014a 838 MIMETYPES,
f6eebcb3 839 CRAWL_REQUEST_CONCURRENCY,
b5c0e955 840 JOB_COMPLETED_LIFETIME,
41f2ebae 841 HTTP_SIGNATURE,
fbad87b0 842 VIDEO_IMPORT_STATES,
7ce44a74 843 VIDEO_VIEW_LIFETIME,
a4101923 844 CONTACT_FORM_LIFETIME,
418d092a 845 VIDEO_PLAYLIST_PRIVACIES,
7ce44a74 846 buildLanguages
9f10b292 847}
fd206f0b
C
848
849// ---------------------------------------------------------------------------
850
851function getLocalConfigFilePath () {
852 const configSources = config.util.getConfigSources()
853 if (configSources.length === 0) throw new Error('Invalid config source.')
854
855 let filename = 'local'
856 if (process.env.NODE_ENV) filename += `-${process.env.NODE_ENV}`
857 if (process.env.NODE_APP_INSTANCE) filename += `-${process.env.NODE_APP_INSTANCE}`
858
859 return join(dirname(configSources[ 0 ].name), filename + '.json')
860}
861
14e2014a
C
862function buildVideoMimetypeExt () {
863 const data = {
864 'video/webm': '.webm',
865 'video/ogg': '.ogv',
866 'video/mp4': '.mp4'
867 }
868
869 if (CONFIG.TRANSCODING.ENABLED && CONFIG.TRANSCODING.ALLOW_ADDITIONAL_EXTENSIONS) {
870 Object.assign(data, {
871 'video/quicktime': '.mov',
872 'video/x-msvideo': '.avi',
873 'video/x-flv': '.flv',
307902e2
C
874 'video/x-matroska': '.mkv',
875 'application/octet-stream': '.mkv',
876 'video/avi': '.avi'
14e2014a
C
877 })
878 }
879
880 return data
881}
882
883function updateWebserverUrls () {
fd206f0b
C
884 CONFIG.WEBSERVER.URL = sanitizeUrl(CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT)
885 CONFIG.WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT, REMOTE_SCHEME.HTTP)
886}
887
14e2014a
C
888function updateWebserverConfig () {
889 CONSTRAINTS_FIELDS.VIDEOS.EXTNAME = buildVideosExtname()
890
891 MIMETYPES.VIDEO.MIMETYPE_EXT = buildVideoMimetypeExt()
892 MIMETYPES.VIDEO.EXT_MIMETYPE = invert(MIMETYPES.VIDEO.MIMETYPE_EXT)
893}
894
895function buildVideosExtname () {
896 return CONFIG.TRANSCODING.ENABLED && CONFIG.TRANSCODING.ALLOW_ADDITIONAL_EXTENSIONS
897 ? [ '.mp4', '.ogv', '.webm', '.mkv', '.mov', '.avi', '.flv' ]
898 : [ '.mp4', '.ogv', '.webm' ]
899}
900
e5565833 901function buildVideosRedundancy (objs: any[]): VideosRedundancy[] {
c48e82b5
C
902 if (!objs) return []
903
d85798c4
C
904 if (!Array.isArray(objs)) return objs
905
e5565833 906 return objs.map(obj => {
f9a971c6 907 return Object.assign({}, obj, {
e5565833
C
908 minLifetime: parseDuration(obj.min_lifetime),
909 size: bytes.parse(obj.size),
910 minViews: obj.min_views
911 })
912 })
c48e82b5
C
913}
914
9d3ef9fe
C
915function buildLanguages () {
916 const iso639 = require('iso-639-3')
917
918 const languages: { [ id: string ]: string } = {}
919
1d94c154
C
920 const additionalLanguages = {
921 'sgn': true, // Sign languages (macro language)
922 'ase': true, // American sign language
923 'sdl': true, // Arabian sign language
924 'bfi': true, // British sign language
925 'bzs': true, // Brazilian sign language
926 'csl': true, // Chinese sign language
927 'cse': true, // Czech sign language
928 'dsl': true, // Danish sign language
929 'fsl': true, // French sign language
930 'gsg': true, // German sign language
931 'pks': true, // Pakistan sign language
932 'jsl': true, // Japanese sign language
933 'sfs': true, // South African sign language
934 'swl': true, // Swedish sign language
935 'rsl': true, // Russian sign language: true
936
937 'epo': true, // Esperanto
938 'tlh': true, // Klingon
939 'jbo': true, // Lojban
940 'avk': true // Kotava
941 }
9d3ef9fe
C
942
943 // Only add ISO639-1 languages and some sign languages (ISO639-3)
944 iso639
945 .filter(l => {
946 return (l.iso6391 !== null && l.type === 'living') ||
1d94c154 947 additionalLanguages[l.iso6393] === true
9d3ef9fe
C
948 })
949 .forEach(l => languages[l.iso6391 || l.iso6393] = l.name)
950
db6d617d
C
951 // Override Occitan label
952 languages['oc'] = 'Occitan'
953
9d3ef9fe
C
954 return languages
955}
956
fd206f0b
C
957export function reloadConfig () {
958
959 function directory () {
960 if (process.env.NODE_CONFIG_DIR) {
961 return process.env.NODE_CONFIG_DIR
962 }
963
964 return join(root(), 'config')
965 }
966
967 function purge () {
968 for (const fileName in require.cache) {
969 if (-1 === fileName.indexOf(directory())) {
970 continue
971 }
972
973 delete require.cache[fileName]
974 }
975
976 delete require.cache[require.resolve('config')]
977 }
978
979 purge()
980
981 config = require('config')
982
983 updateWebserverConfig()
14e2014a 984 updateWebserverUrls()
fd206f0b 985}