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