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,
15 } from '../../shared/models'
16 import { VideoPrivacy } from '../../shared/models/videos/video-privacy.enum'
18 // ---------------------------------------------------------------------------
20 const LAST_MIGRATION_VERSION = 95
22 // ---------------------------------------------------------------------------
25 const API_VERSION = 'v1'
27 // Number of results by default for the pagination
28 const PAGINATION_COUNT_DEFAULT = 15
30 // Sortable columns per schema
31 const SEARCHABLE_COLUMNS = {
32 VIDEOS: [ 'name', 'magnetUri', 'host', 'account', 'tags' ]
35 // Sortable columns per schema
36 const SORTABLE_COLUMNS = {
37 PODS: [ 'id', 'host', 'score', 'createdAt' ],
38 USERS: [ 'id', 'username', 'createdAt' ],
39 VIDEO_ABUSES: [ 'id', 'createdAt' ],
40 VIDEO_CHANNELS: [ 'id', 'name', 'updatedAt', 'createdAt' ],
41 VIDEOS: [ 'name', 'duration', 'createdAt', 'views', 'likes' ],
42 BLACKLISTS: [ 'id', 'name', 'duration', 'views', 'likes', 'dislikes', 'uuid', 'createdAt' ]
45 const OAUTH_LIFETIME = {
46 ACCESS_TOKEN: 3600 * 4, // 4 hours
47 REFRESH_TOKEN: 1209600 // 2 weeks
50 // ---------------------------------------------------------------------------
54 PORT: config.get<number>('listen.port')
57 DBNAME: 'peertube' + config.get<string>('database.suffix'),
58 HOSTNAME: config.get<string>('database.hostname'),
59 PORT: config.get<number>('database.port'),
60 USERNAME: config.get<string>('database.username'),
61 PASSWORD: config.get<string>('database.password')
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 const VIDEO_MIMETYPE_EXT = {
207 'video/webm': 'webm',
212 // ---------------------------------------------------------------------------
214 // Score a pod has when we create it as a friend
215 const FRIEND_SCORE = {
220 const ACTIVITY_PUB = {
221 COLLECTION_ITEMS_PER_PAGE: 10,
222 VIDEO_URL_MIME_TYPES: [
226 'application/x-bittorrent',
227 'application/x-bittorrent;x-scheme-handler/magnet'
231 // ---------------------------------------------------------------------------
233 // Number of points we add/remove from a friend after a successful/bad request
239 // Time to wait between requests to the friends (10 min)
240 let REQUESTS_INTERVAL = 600000
242 // Number of requests in parallel we can make
243 const REQUESTS_IN_PARALLEL = 10
245 // To how many pods we send requests
246 const REQUESTS_LIMIT_PODS = 10
247 // How many requests we send to a pod per interval
248 const REQUESTS_LIMIT_PER_POD = 5
250 const REQUESTS_VIDEO_QADU_LIMIT_PODS = 10
251 // The QADU requests are not big
252 const REQUESTS_VIDEO_QADU_LIMIT_PER_POD = 50
254 const REQUESTS_VIDEO_EVENT_LIMIT_PODS = 10
255 // The EVENTS requests are not big
256 const REQUESTS_VIDEO_EVENT_LIMIT_PER_POD = 50
258 // Number of requests to retry for replay requests module
259 const RETRY_REQUESTS = 5
261 const REMOTE_SCHEME = {
266 const JOB_STATES: { [ id: string ]: JobState } = {
268 PROCESSING: 'processing',
272 const JOB_CATEGORIES: { [ id: string ]: JobCategory } = {
273 TRANSCODING: 'transcoding',
274 HTTP_REQUEST: 'http-request'
276 // How many maximum jobs we fetch from the database per cycle
277 const JOBS_FETCH_LIMIT_PER_CYCLE = {
282 let JOBS_FETCHING_INTERVAL = 60000
284 // ---------------------------------------------------------------------------
286 const PRIVATE_RSA_KEY_SIZE = 2048
288 // Password encryption
289 const BCRYPT_SALT_SIZE = 10
291 // ---------------------------------------------------------------------------
293 // Express static paths (router)
294 const STATIC_PATHS = {
295 PREVIEWS: '/static/previews/',
296 THUMBNAILS: '/static/thumbnails/',
297 TORRENTS: '/static/torrents/',
298 WEBSEED: '/static/webseed/'
302 let STATIC_MAX_AGE = '30d'
304 // Videos thumbnail size
305 const THUMBNAILS_SIZE = {
309 const PREVIEWS_SIZE = {
319 // Sub folders of cache directory
322 PREVIEWS: join(CONFIG.STORAGE.CACHE_DIR, 'previews')
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 // ---------------------------------------------------------------------------
354 JOBS_FETCH_LIMIT_PER_CYCLE,
355 JOBS_FETCHING_INTERVAL,
357 LAST_MIGRATION_VERSION,
359 OPENGRAPH_AND_OEMBED_COMMENT,
360 PAGINATION_COUNT_DEFAULT,
364 REQUEST_ENDPOINT_ACTIONS,
366 REQUEST_VIDEO_EVENT_ENDPOINT,
367 REQUEST_VIDEO_EVENT_TYPES,
368 REQUEST_VIDEO_QADU_ENDPOINT,
369 REQUEST_VIDEO_QADU_TYPES,
370 REQUESTS_IN_PARALLEL,
372 REQUESTS_LIMIT_PER_POD,
374 REQUESTS_VIDEO_EVENT_LIMIT_PER_POD,
375 REQUESTS_VIDEO_EVENT_LIMIT_PODS,
376 REQUESTS_VIDEO_QADU_LIMIT_PER_POD,
377 REQUESTS_VIDEO_QADU_LIMIT_PODS,
380 PRIVATE_RSA_KEY_SIZE,