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'
10 RequestVideoEventType,
12 RemoteVideoRequestType,
14 } from '../../shared/models'
15 import { VideoPrivacy } from '../../shared/models/videos/video-privacy.enum'
17 // ---------------------------------------------------------------------------
19 const LAST_MIGRATION_VERSION = 95
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 TRUNCATED_DESCRIPTION: { min: 3, max: 250 }, // Length
127 DESCRIPTION: { min: 3, max: 3000 }, // Length
128 EXTNAME: [ '.mp4', '.ogv', '.webm' ],
129 INFO_HASH: { min: 40, max: 40 }, // Length, info hash is 20 bytes length but we represent it in hexadecimal so 20 * 2
130 DURATION: { min: 1, max: 7200 }, // Number
131 TAGS: { min: 0, max: 5 }, // Number of total tags
132 TAG: { min: 2, max: 30 }, // Length
133 THUMBNAIL: { min: 2, max: 30 },
134 THUMBNAIL_DATA: { min: 0, max: 20000 }, // Bytes
137 DISLIKES: { min: 0 },
138 FILE_SIZE: { min: 10, max: 1024 * 1024 * 1024 * 3 /* 3Go */ }
145 const VIDEO_RATE_TYPES: { [ id: string ]: VideoRateType } = {
150 const VIDEO_CATEGORIES = {
165 15: 'Science & Technology',
171 // See https://creativecommons.org/licenses/?lang=en
172 const VIDEO_LICENCES = {
174 2: 'Attribution - Share Alike',
175 3: 'Attribution - No Derivatives',
176 4: 'Attribution - Non Commercial',
177 5: 'Attribution - Non Commercial - Share Alike',
178 6: 'Attribution - Non Commercial - No Derivatives',
179 7: 'Public Domain Dedication'
182 // See https://en.wikipedia.org/wiki/List_of_languages_by_number_of_native_speakers#Nationalencyklopedin
183 const VIDEO_LANGUAGES = {
200 const VIDEO_PRIVACIES = {
201 [VideoPrivacy.PUBLIC]: 'Public',
202 [VideoPrivacy.UNLISTED]: 'Unlisted',
203 [VideoPrivacy.PRIVATE]: 'Private'
206 // ---------------------------------------------------------------------------
208 // Score a pod has when we create it as a friend
209 const FRIEND_SCORE = {
214 // ---------------------------------------------------------------------------
216 // Number of points we add/remove from a friend after a successful/bad request
222 // Time to wait between requests to the friends (10 min)
223 let REQUESTS_INTERVAL = 600000
225 // Number of requests in parallel we can make
226 const REQUESTS_IN_PARALLEL = 10
228 // To how many pods we send requests
229 const REQUESTS_LIMIT_PODS = 10
230 // How many requests we send to a pod per interval
231 const REQUESTS_LIMIT_PER_POD = 5
233 const REQUESTS_VIDEO_QADU_LIMIT_PODS = 10
234 // The QADU requests are not big
235 const REQUESTS_VIDEO_QADU_LIMIT_PER_POD = 50
237 const REQUESTS_VIDEO_EVENT_LIMIT_PODS = 10
238 // The EVENTS requests are not big
239 const REQUESTS_VIDEO_EVENT_LIMIT_PER_POD = 50
241 // Number of requests to retry for replay requests module
242 const RETRY_REQUESTS = 5
244 const REQUEST_ENDPOINTS: { [ id: string ]: RequestEndpoint } = {
248 const REQUEST_ENDPOINT_ACTIONS: {
250 [ id: string ]: RemoteVideoRequestType
253 REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS] = {
254 ADD_VIDEO: 'add-video',
255 UPDATE_VIDEO: 'update-video',
256 REMOVE_VIDEO: 'remove-video',
257 ADD_CHANNEL: 'add-channel',
258 UPDATE_CHANNEL: 'update-channel',
259 REMOVE_CHANNEL: 'remove-channel',
260 ADD_AUTHOR: 'add-author',
261 REMOVE_AUTHOR: 'remove-author',
262 REPORT_ABUSE: 'report-abuse'
265 const REQUEST_VIDEO_QADU_ENDPOINT = 'videos/qadu'
266 const REQUEST_VIDEO_EVENT_ENDPOINT = 'videos/events'
268 const REQUEST_VIDEO_QADU_TYPES: { [ id: string ]: RequestVideoQaduType } = {
270 DISLIKES: 'dislikes',
274 const REQUEST_VIDEO_EVENT_TYPES: { [ id: string ]: RequestVideoEventType } = {
276 DISLIKES: 'dislikes',
280 const REMOTE_SCHEME = {
285 const JOB_STATES: { [ id: string ]: JobState } = {
287 PROCESSING: 'processing',
291 // How many maximum jobs we fetch from the database per cycle
292 const JOBS_FETCH_LIMIT_PER_CYCLE = 10
294 let JOBS_FETCHING_INTERVAL = 60000
296 // ---------------------------------------------------------------------------
298 const PRIVATE_CERT_NAME = 'peertube.key.pem'
299 const PUBLIC_CERT_NAME = 'peertube.pub'
300 const SIGNATURE_ALGORITHM = 'RSA-SHA256'
301 const SIGNATURE_ENCODING = 'hex'
303 // Password encryption
304 const BCRYPT_SALT_SIZE = 10
306 // ---------------------------------------------------------------------------
308 // Express static paths (router)
309 const STATIC_PATHS = {
310 PREVIEWS: '/static/previews/',
311 THUMBNAILS: '/static/thumbnails/',
312 TORRENTS: '/static/torrents/',
313 WEBSEED: '/static/webseed/'
317 let STATIC_MAX_AGE = '30d'
319 // Videos thumbnail size
320 const THUMBNAILS_SIZE = {
324 const PREVIEWS_SIZE = {
334 // Sub folders of cache directory
337 PREVIEWS: join(CONFIG.STORAGE.CACHE_DIR, 'previews')
341 // ---------------------------------------------------------------------------
343 const OPENGRAPH_AND_OEMBED_COMMENT = '<!-- open graph and oembed tags -->'
345 // ---------------------------------------------------------------------------
347 // Special constants for a test instance
348 if (isTestInstance() === true) {
349 CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14
350 FRIEND_SCORE.BASE = 20
351 REQUESTS_INTERVAL = 10000
352 JOBS_FETCHING_INTERVAL = 10000
353 REMOTE_SCHEME.HTTP = 'http'
354 REMOTE_SCHEME.WS = 'ws'
358 // ---------------------------------------------------------------------------
369 JOBS_FETCH_LIMIT_PER_CYCLE,
370 JOBS_FETCHING_INTERVAL,
371 LAST_MIGRATION_VERSION,
373 OPENGRAPH_AND_OEMBED_COMMENT,
374 PAGINATION_COUNT_DEFAULT,
380 REQUEST_ENDPOINT_ACTIONS,
382 REQUEST_VIDEO_EVENT_ENDPOINT,
383 REQUEST_VIDEO_EVENT_TYPES,
384 REQUEST_VIDEO_QADU_ENDPOINT,
385 REQUEST_VIDEO_QADU_TYPES,
386 REQUESTS_IN_PARALLEL,
388 REQUESTS_LIMIT_PER_POD,
390 REQUESTS_VIDEO_EVENT_LIMIT_PER_POD,
391 REQUESTS_VIDEO_EVENT_LIMIT_PODS,
392 REQUESTS_VIDEO_QADU_LIMIT_PER_POD,
393 REQUESTS_VIDEO_QADU_LIMIT_PODS,