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,
13 RemoteVideoRequestType,
15 } from '../../shared/models'
17 // ---------------------------------------------------------------------------
19 const LAST_MIGRATION_VERSION = 80
21 // ---------------------------------------------------------------------------
24 const API_VERSION = 'v1'
26 // Number of results by default for the pagination
27 const PAGINATION_COUNT_DEFAULT = 15
29 // Sortable columns per schema
30 const SEARCHABLE_COLUMNS = {
31 VIDEOS: [ 'name', 'magnetUri', 'host', 'author', 'tags' ]
34 // Sortable columns per schema
35 const SORTABLE_COLUMNS = {
36 PODS: [ 'id', 'host', 'score', 'createdAt' ],
37 USERS: [ 'id', 'username', 'createdAt' ],
38 VIDEO_ABUSES: [ 'id', 'createdAt' ],
39 VIDEO_CHANNELS: [ 'id', 'name', 'updatedAt', 'createdAt' ],
40 VIDEOS: [ 'name', 'duration', 'createdAt', 'views', 'likes' ],
41 BLACKLISTS: [ 'id', 'name', 'duration', 'views', 'likes', 'dislikes', 'uuid', 'createdAt' ]
44 const OAUTH_LIFETIME = {
45 ACCESS_TOKEN: 3600 * 4, // 4 hours
46 REFRESH_TOKEN: 1209600 // 2 weeks
49 // ---------------------------------------------------------------------------
53 PORT: config.get<number>('listen.port')
56 DBNAME: 'peertube' + config.get<string>('database.suffix'),
57 HOSTNAME: config.get<string>('database.hostname'),
58 PORT: config.get<number>('database.port'),
59 USERNAME: config.get<string>('database.username'),
60 PASSWORD: config.get<string>('database.password')
63 CERT_DIR: join(root(), config.get<string>('storage.certs')),
64 LOG_DIR: join(root(), config.get<string>('storage.logs')),
65 VIDEOS_DIR: join(root(), config.get<string>('storage.videos')),
66 THUMBNAILS_DIR: join(root(), config.get<string>('storage.thumbnails')),
67 PREVIEWS_DIR: join(root(), config.get<string>('storage.previews')),
68 TORRENTS_DIR: join(root(), config.get<string>('storage.torrents')),
69 CACHE_DIR: join(root(), config.get<string>('storage.cache'))
72 SCHEME: config.get<boolean>('webserver.https') === true ? 'https' : 'http',
73 WS: config.get<boolean>('webserver.https') === true ? 'wss' : 'ws',
74 HOSTNAME: config.get<string>('webserver.hostname'),
75 PORT: config.get<number>('webserver.port'),
80 EMAIL: config.get<string>('admin.email')
83 ENABLED: config.get<boolean>('signup.enabled'),
84 LIMIT: config.get<number>('signup.limit')
87 VIDEO_QUOTA: config.get<number>('user.video_quota')
90 ENABLED: config.get<boolean>('transcoding.enabled'),
91 THREADS: config.get<number>('transcoding.threads'),
93 '240' : config.get<boolean>('transcoding.resolutions.240p'),
94 '360': config.get<boolean>('transcoding.resolutions.360p'),
95 '480': config.get<boolean>('transcoding.resolutions.480p'),
96 '720': config.get<boolean>('transcoding.resolutions.720p'),
97 '1080': config.get<boolean>('transcoding.resolutions.1080p')
102 SIZE: config.get<number>('cache.previews.size')
106 CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
107 CONFIG.WEBSERVER.HOST = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
109 // ---------------------------------------------------------------------------
111 const CONSTRAINTS_FIELDS = {
113 USERNAME: { min: 3, max: 20 }, // Length
114 PASSWORD: { min: 6, max: 255 }, // Length
115 VIDEO_QUOTA: { min: -1 }
118 REASON: { min: 2, max: 300 } // Length
121 NAME: { min: 3, max: 120 }, // Length
122 DESCRIPTION: { min: 3, max: 250 } // Length
125 NAME: { min: 3, max: 120 }, // Length
126 DESCRIPTION: { min: 3, max: 250 }, // Length
127 EXTNAME: [ '.mp4', '.ogv', '.webm' ],
128 INFO_HASH: { min: 40, max: 40 }, // Length, info hash is 20 bytes length but we represent it in hexadecimal so 20 * 2
129 DURATION: { min: 1, max: 7200 }, // Number
130 TAGS: { min: 0, max: 5 }, // Number of total tags
131 TAG: { min: 2, max: 30 }, // Length
132 THUMBNAIL: { min: 2, max: 30 },
133 THUMBNAIL_DATA: { min: 0, max: 20000 }, // Bytes
136 DISLIKES: { min: 0 },
137 FILE_SIZE: { min: 10, max: 1024 * 1024 * 1024 * 3 /* 3Go */ }
144 const VIDEO_RATE_TYPES: { [ id: string ]: VideoRateType } = {
149 const VIDEO_CATEGORIES = {
164 15: 'Science & Technology',
170 // See https://creativecommons.org/licenses/?lang=en
171 const VIDEO_LICENCES = {
173 2: 'Attribution - Share Alike',
174 3: 'Attribution - No Derivatives',
175 4: 'Attribution - Non Commercial',
176 5: 'Attribution - Non Commercial - Share Alike',
177 6: 'Attribution - Non Commercial - No Derivatives',
178 7: 'Public Domain Dedication'
181 // See https://en.wikipedia.org/wiki/List_of_languages_by_number_of_native_speakers#Nationalencyklopedin
182 const VIDEO_LANGUAGES = {
199 // ---------------------------------------------------------------------------
201 // Score a pod has when we create it as a friend
202 const FRIEND_SCORE = {
207 // ---------------------------------------------------------------------------
209 // Number of points we add/remove from a friend after a successful/bad request
215 // Time to wait between requests to the friends (10 min)
216 let REQUESTS_INTERVAL = 600000
218 // Number of requests in parallel we can make
219 const REQUESTS_IN_PARALLEL = 10
221 // To how many pods we send requests
222 const REQUESTS_LIMIT_PODS = 10
223 // How many requests we send to a pod per interval
224 const REQUESTS_LIMIT_PER_POD = 5
226 const REQUESTS_VIDEO_QADU_LIMIT_PODS = 10
227 // The QADU requests are not big
228 const REQUESTS_VIDEO_QADU_LIMIT_PER_POD = 50
230 const REQUESTS_VIDEO_EVENT_LIMIT_PODS = 10
231 // The EVENTS requests are not big
232 const REQUESTS_VIDEO_EVENT_LIMIT_PER_POD = 50
234 // Number of requests to retry for replay requests module
235 const RETRY_REQUESTS = 5
237 const REQUEST_ENDPOINTS: { [ id: string ]: RequestEndpoint } = {
241 const REQUEST_ENDPOINT_ACTIONS: {
243 [ id: string ]: RemoteVideoRequestType
246 REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS] = {
247 ADD_VIDEO: 'add-video',
248 UPDATE_VIDEO: 'update-video',
249 REMOVE_VIDEO: 'remove-video',
250 ADD_CHANNEL: 'add-channel',
251 UPDATE_CHANNEL: 'update-channel',
252 REMOVE_CHANNEL: 'remove-channel',
253 ADD_AUTHOR: 'add-author',
254 REMOVE_AUTHOR: 'remove-author',
255 REPORT_ABUSE: 'report-abuse'
258 const REQUEST_VIDEO_QADU_ENDPOINT = 'videos/qadu'
259 const REQUEST_VIDEO_EVENT_ENDPOINT = 'videos/events'
261 const REQUEST_VIDEO_QADU_TYPES: { [ id: string ]: RequestVideoQaduType } = {
263 DISLIKES: 'dislikes',
267 const REQUEST_VIDEO_EVENT_TYPES: { [ id: string ]: RequestVideoEventType } = {
269 DISLIKES: 'dislikes',
273 const REMOTE_SCHEME = {
278 const JOB_STATES: { [ id: string ]: JobState } = {
280 PROCESSING: 'processing',
284 // How many maximum jobs we fetch from the database per cycle
285 const JOBS_FETCH_LIMIT_PER_CYCLE = 10
286 const JOBS_CONCURRENCY = 1
288 let JOBS_FETCHING_INTERVAL = 60000
290 // ---------------------------------------------------------------------------
292 const PRIVATE_CERT_NAME = 'peertube.key.pem'
293 const PUBLIC_CERT_NAME = 'peertube.pub'
294 const SIGNATURE_ALGORITHM = 'RSA-SHA256'
295 const SIGNATURE_ENCODING = 'hex'
297 // Password encryption
298 const BCRYPT_SALT_SIZE = 10
300 // ---------------------------------------------------------------------------
302 // Express static paths (router)
303 const STATIC_PATHS = {
304 PREVIEWS: '/static/previews/',
305 THUMBNAILS: '/static/thumbnails/',
306 TORRENTS: '/static/torrents/',
307 WEBSEED: '/static/webseed/'
311 let STATIC_MAX_AGE = '30d'
313 // Videos thumbnail size
314 const THUMBNAILS_SIZE = {
318 const PREVIEWS_SIZE = {
328 // Sub folders of cache directory
331 PREVIEWS: join(CONFIG.STORAGE.CACHE_DIR, 'previews')
335 // ---------------------------------------------------------------------------
337 const USER_ROLES: { [ id: string ]: UserRole } = {
342 // ---------------------------------------------------------------------------
344 const OPENGRAPH_AND_OEMBED_COMMENT = '<!-- open graph and oembed tags -->'
346 // ---------------------------------------------------------------------------
348 // Special constants for a test instance
349 if (isTestInstance() === true) {
350 CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14
351 FRIEND_SCORE.BASE = 20
352 REQUESTS_INTERVAL = 10000
353 JOBS_FETCHING_INTERVAL = 10000
354 REMOTE_SCHEME.HTTP = 'http'
355 REMOTE_SCHEME.WS = 'ws'
359 // ---------------------------------------------------------------------------
371 JOBS_FETCH_LIMIT_PER_CYCLE,
372 JOBS_FETCHING_INTERVAL,
373 LAST_MIGRATION_VERSION,
375 OPENGRAPH_AND_OEMBED_COMMENT,
376 PAGINATION_COUNT_DEFAULT,
382 REQUEST_ENDPOINT_ACTIONS,
384 REQUEST_VIDEO_EVENT_ENDPOINT,
385 REQUEST_VIDEO_EVENT_TYPES,
386 REQUEST_VIDEO_QADU_ENDPOINT,
387 REQUEST_VIDEO_QADU_TYPES,
388 REQUESTS_IN_PARALLEL,
390 REQUESTS_LIMIT_PER_POD,
392 REQUESTS_VIDEO_EVENT_LIMIT_PER_POD,
393 REQUESTS_VIDEO_EVENT_LIMIT_PODS,
394 REQUESTS_VIDEO_QADU_LIMIT_PER_POD,
395 REQUESTS_VIDEO_QADU_LIMIT_PODS,