1 import * as config from 'config'
2 import { join } from 'path'
4 // Do not use barrels, remain constants as independent as possible
5 import { root, isTestInstance } from '../helpers/core-utils'
11 RequestVideoEventType,
14 } from '../../shared/models'
16 // ---------------------------------------------------------------------------
18 const LAST_MIGRATION_VERSION = 75
20 // ---------------------------------------------------------------------------
23 const API_VERSION = 'v1'
25 // Number of results by default for the pagination
26 const PAGINATION_COUNT_DEFAULT = 15
28 // Sortable columns per schema
29 const SEARCHABLE_COLUMNS = {
30 VIDEOS: [ 'name', 'magnetUri', 'host', 'author', 'tags' ]
33 // Sortable columns per schema
34 const SORTABLE_COLUMNS = {
35 USERS: [ 'id', 'username', 'createdAt' ],
36 VIDEO_ABUSES: [ 'id', 'createdAt' ],
37 VIDEOS: [ 'name', 'duration', 'createdAt', 'views', 'likes' ],
38 BLACKLISTS: [ 'id', 'name', 'duration', 'views', 'likes', 'dislikes', 'uuid', 'createdAt' ]
41 const OAUTH_LIFETIME = {
42 ACCESS_TOKEN: 3600 * 4, // 4 hours
43 REFRESH_TOKEN: 1209600 // 2 weeks
46 // ---------------------------------------------------------------------------
50 PORT: config.get<number>('listen.port')
53 DBNAME: 'peertube' + config.get<string>('database.suffix'),
54 HOSTNAME: config.get<string>('database.hostname'),
55 PORT: config.get<number>('database.port'),
56 USERNAME: config.get<string>('database.username'),
57 PASSWORD: config.get<string>('database.password')
60 CERT_DIR: join(root(), config.get<string>('storage.certs')),
61 LOG_DIR: join(root(), config.get<string>('storage.logs')),
62 VIDEOS_DIR: join(root(), config.get<string>('storage.videos')),
63 THUMBNAILS_DIR: join(root(), config.get<string>('storage.thumbnails')),
64 PREVIEWS_DIR: join(root(), config.get<string>('storage.previews')),
65 TORRENTS_DIR: join(root(), config.get<string>('storage.torrents')),
66 CACHE_DIR: join(root(), config.get<string>('storage.cache'))
69 SCHEME: config.get<boolean>('webserver.https') === true ? 'https' : 'http',
70 WS: config.get<boolean>('webserver.https') === true ? 'wss' : 'ws',
71 HOSTNAME: config.get<string>('webserver.hostname'),
72 PORT: config.get<number>('webserver.port'),
77 EMAIL: config.get<string>('admin.email')
80 ENABLED: config.get<boolean>('signup.enabled'),
81 LIMIT: config.get<number>('signup.limit')
84 VIDEO_QUOTA: config.get<number>('user.video_quota')
87 ENABLED: config.get<boolean>('transcoding.enabled'),
88 THREADS: config.get<number>('transcoding.threads'),
90 '240' : config.get<boolean>('transcoding.resolutions.240p'),
91 '360': config.get<boolean>('transcoding.resolutions.360p'),
92 '480': config.get<boolean>('transcoding.resolutions.480p'),
93 '720': config.get<boolean>('transcoding.resolutions.720p'),
94 '1080': config.get<boolean>('transcoding.resolutions.1080p')
99 SIZE: config.get<number>('cache.previews.size')
103 CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
104 CONFIG.WEBSERVER.HOST = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
106 // ---------------------------------------------------------------------------
108 const CONSTRAINTS_FIELDS = {
110 USERNAME: { min: 3, max: 20 }, // Length
111 PASSWORD: { min: 6, max: 255 }, // Length
112 VIDEO_QUOTA: { min: -1 }
115 REASON: { min: 2, max: 300 } // Length
118 NAME: { min: 3, max: 50 }, // Length
119 DESCRIPTION: { min: 3, max: 250 }, // Length
120 EXTNAME: [ '.mp4', '.ogv', '.webm' ],
121 INFO_HASH: { min: 40, max: 40 }, // Length, info hash is 20 bytes length but we represent it in hexadecimal so 20 * 2
122 DURATION: { min: 1, max: 7200 }, // Number
123 TAGS: { min: 0, max: 3 }, // Number of total tags
124 TAG: { min: 2, max: 10 }, // Length
125 THUMBNAIL: { min: 2, max: 30 },
126 THUMBNAIL_DATA: { min: 0, max: 20000 }, // Bytes
129 DISLIKES: { min: 0 },
130 FILE_SIZE: { min: 10, max: 1024 * 1024 * 1024 * 3 /* 3Go */ }
137 const VIDEO_RATE_TYPES: { [ id: string ]: VideoRateType } = {
142 const VIDEO_CATEGORIES = {
157 15: 'Science & Technology',
163 // See https://creativecommons.org/licenses/?lang=en
164 const VIDEO_LICENCES = {
166 2: 'Attribution - Share Alike',
167 3: 'Attribution - No Derivatives',
168 4: 'Attribution - Non Commercial',
169 5: 'Attribution - Non Commercial - Share Alike',
170 6: 'Attribution - Non Commercial - No Derivatives',
171 7: 'Public Domain Dedication'
174 // See https://en.wikipedia.org/wiki/List_of_languages_by_number_of_native_speakers#Nationalencyklopedin
175 const VIDEO_LANGUAGES = {
192 // ---------------------------------------------------------------------------
194 // Score a pod has when we create it as a friend
195 const FRIEND_SCORE = {
200 // ---------------------------------------------------------------------------
202 // Number of points we add/remove from a friend after a successful/bad request
208 // Time to wait between requests to the friends (10 min)
209 let REQUESTS_INTERVAL = 600000
211 // Number of requests in parallel we can make
212 const REQUESTS_IN_PARALLEL = 10
214 // To how many pods we send requests
215 const REQUESTS_LIMIT_PODS = 10
216 // How many requests we send to a pod per interval
217 const REQUESTS_LIMIT_PER_POD = 5
219 const REQUESTS_VIDEO_QADU_LIMIT_PODS = 10
220 // The QADU requests are not big
221 const REQUESTS_VIDEO_QADU_LIMIT_PER_POD = 50
223 const REQUESTS_VIDEO_EVENT_LIMIT_PODS = 10
224 // The EVENTS requests are not big
225 const REQUESTS_VIDEO_EVENT_LIMIT_PER_POD = 50
227 // Number of requests to retry for replay requests module
228 const RETRY_REQUESTS = 5
230 const REQUEST_ENDPOINTS: { [ id: string ]: RequestEndpoint } = {
234 const REQUEST_ENDPOINT_ACTIONS: { [ id: string ]: any } = {}
235 REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS] = {
239 REPORT_ABUSE: 'report-abuse'
242 const REQUEST_VIDEO_QADU_ENDPOINT = 'videos/qadu'
243 const REQUEST_VIDEO_EVENT_ENDPOINT = 'videos/events'
245 const REQUEST_VIDEO_QADU_TYPES: { [ id: string ]: RequestVideoQaduType } = {
247 DISLIKES: 'dislikes',
251 const REQUEST_VIDEO_EVENT_TYPES: { [ id: string ]: RequestVideoEventType } = {
253 DISLIKES: 'dislikes',
257 const REMOTE_SCHEME = {
262 const JOB_STATES: { [ id: string ]: JobState } = {
264 PROCESSING: 'processing',
268 // How many maximum jobs we fetch from the database per cycle
269 const JOBS_FETCH_LIMIT_PER_CYCLE = 10
270 const JOBS_CONCURRENCY = 1
272 let JOBS_FETCHING_INTERVAL = 60000
274 // ---------------------------------------------------------------------------
276 const PRIVATE_CERT_NAME = 'peertube.key.pem'
277 const PUBLIC_CERT_NAME = 'peertube.pub'
278 const SIGNATURE_ALGORITHM = 'RSA-SHA256'
279 const SIGNATURE_ENCODING = 'hex'
281 // Password encryption
282 const BCRYPT_SALT_SIZE = 10
284 // ---------------------------------------------------------------------------
286 // Express static paths (router)
287 const STATIC_PATHS = {
288 PREVIEWS: '/static/previews/',
289 THUMBNAILS: '/static/thumbnails/',
290 TORRENTS: '/static/torrents/',
291 WEBSEED: '/static/webseed/'
295 let STATIC_MAX_AGE = '30d'
297 // Videos thumbnail size
298 const THUMBNAILS_SIZE = {
302 const PREVIEWS_SIZE = {
312 // Sub folders of cache directory
315 PREVIEWS: join(CONFIG.STORAGE.CACHE_DIR, 'previews')
319 // ---------------------------------------------------------------------------
321 const USER_ROLES: { [ id: string ]: UserRole } = {
326 // ---------------------------------------------------------------------------
328 const OPENGRAPH_AND_OEMBED_COMMENT = '<!-- open graph and oembed tags -->'
330 // ---------------------------------------------------------------------------
332 // Special constants for a test instance
333 if (isTestInstance() === true) {
334 CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14
335 FRIEND_SCORE.BASE = 20
336 REQUESTS_INTERVAL = 10000
337 JOBS_FETCHING_INTERVAL = 10000
338 REMOTE_SCHEME.HTTP = 'http'
339 REMOTE_SCHEME.WS = 'ws'
343 // ---------------------------------------------------------------------------
355 JOBS_FETCH_LIMIT_PER_CYCLE,
356 JOBS_FETCHING_INTERVAL,
357 LAST_MIGRATION_VERSION,
359 OPENGRAPH_AND_OEMBED_COMMENT,
360 PAGINATION_COUNT_DEFAULT,
366 REQUEST_ENDPOINT_ACTIONS,
368 REQUEST_VIDEO_EVENT_ENDPOINT,
369 REQUEST_VIDEO_EVENT_TYPES,
370 REQUEST_VIDEO_QADU_ENDPOINT,
371 REQUEST_VIDEO_QADU_TYPES,
372 REQUESTS_IN_PARALLEL,
374 REQUESTS_LIMIT_PER_POD,
376 REQUESTS_VIDEO_EVENT_LIMIT_PER_POD,
377 REQUESTS_VIDEO_EVENT_LIMIT_PODS,
378 REQUESTS_VIDEO_QADU_LIMIT_PER_POD,
379 REQUESTS_VIDEO_QADU_LIMIT_PODS,