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', 'author', '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 // ---------------------------------------------------------------------------
208 // Score a pod has when we create it as a friend
209 const FRIEND_SCORE = {
214 const ACTIVITY_PUB = {
215 COLLECTION_ITEMS_PER_PAGE: 10
218 // ---------------------------------------------------------------------------
220 // Number of points we add/remove from a friend after a successful/bad request
226 // Time to wait between requests to the friends (10 min)
227 let REQUESTS_INTERVAL = 600000
229 // Number of requests in parallel we can make
230 const REQUESTS_IN_PARALLEL = 10
232 // To how many pods we send requests
233 const REQUESTS_LIMIT_PODS = 10
234 // How many requests we send to a pod per interval
235 const REQUESTS_LIMIT_PER_POD = 5
237 const REQUESTS_VIDEO_QADU_LIMIT_PODS = 10
238 // The QADU requests are not big
239 const REQUESTS_VIDEO_QADU_LIMIT_PER_POD = 50
241 const REQUESTS_VIDEO_EVENT_LIMIT_PODS = 10
242 // The EVENTS requests are not big
243 const REQUESTS_VIDEO_EVENT_LIMIT_PER_POD = 50
245 // Number of requests to retry for replay requests module
246 const RETRY_REQUESTS = 5
248 const REQUEST_ENDPOINTS: { [ id: string ]: RequestEndpoint } = {
252 const REQUEST_ENDPOINT_ACTIONS: {
254 [ id: string ]: RemoteVideoRequestType
257 REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS] = {
258 ADD_VIDEO: 'add-video',
259 UPDATE_VIDEO: 'update-video',
260 REMOVE_VIDEO: 'remove-video',
261 ADD_CHANNEL: 'add-channel',
262 UPDATE_CHANNEL: 'update-channel',
263 REMOVE_CHANNEL: 'remove-channel',
264 ADD_AUTHOR: 'add-author',
265 REMOVE_AUTHOR: 'remove-author',
266 REPORT_ABUSE: 'report-abuse'
269 const REQUEST_VIDEO_QADU_ENDPOINT = 'videos/qadu'
270 const REQUEST_VIDEO_EVENT_ENDPOINT = 'videos/events'
272 const REQUEST_VIDEO_QADU_TYPES: { [ id: string ]: RequestVideoQaduType } = {
274 DISLIKES: 'dislikes',
278 const REQUEST_VIDEO_EVENT_TYPES: { [ id: string ]: RequestVideoEventType } = {
280 DISLIKES: 'dislikes',
284 const REMOTE_SCHEME = {
289 const JOB_STATES: { [ id: string ]: JobState } = {
291 PROCESSING: 'processing',
295 const JOB_CATEGORIES: { [ id: string ]: JobCategory } = {
296 TRANSCODING: 'transcoding',
297 HTTP_REQUEST: 'http-request'
299 // How many maximum jobs we fetch from the database per cycle
300 const JOBS_FETCH_LIMIT_PER_CYCLE = {
305 let JOBS_FETCHING_INTERVAL = 60000
307 // ---------------------------------------------------------------------------
309 // const SIGNATURE_ALGORITHM = 'RSA-SHA256'
310 // const SIGNATURE_ENCODING = 'hex'
311 const PRIVATE_RSA_KEY_SIZE = 2048
313 // Password encryption
314 const BCRYPT_SALT_SIZE = 10
316 // ---------------------------------------------------------------------------
318 // Express static paths (router)
319 const STATIC_PATHS = {
320 PREVIEWS: '/static/previews/',
321 THUMBNAILS: '/static/thumbnails/',
322 TORRENTS: '/static/torrents/',
323 WEBSEED: '/static/webseed/'
327 let STATIC_MAX_AGE = '30d'
329 // Videos thumbnail size
330 const THUMBNAILS_SIZE = {
334 const PREVIEWS_SIZE = {
344 // Sub folders of cache directory
347 PREVIEWS: join(CONFIG.STORAGE.CACHE_DIR, 'previews')
351 // ---------------------------------------------------------------------------
353 const OPENGRAPH_AND_OEMBED_COMMENT = '<!-- open graph and oembed tags -->'
355 // ---------------------------------------------------------------------------
357 // Special constants for a test instance
358 if (isTestInstance() === true) {
359 CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14
360 FRIEND_SCORE.BASE = 20
361 REQUESTS_INTERVAL = 10000
362 JOBS_FETCHING_INTERVAL = 10000
363 REMOTE_SCHEME.HTTP = 'http'
364 REMOTE_SCHEME.WS = 'ws'
368 // ---------------------------------------------------------------------------
379 JOBS_FETCH_LIMIT_PER_CYCLE,
380 JOBS_FETCHING_INTERVAL,
382 LAST_MIGRATION_VERSION,
384 OPENGRAPH_AND_OEMBED_COMMENT,
385 PAGINATION_COUNT_DEFAULT,
389 REQUEST_ENDPOINT_ACTIONS,
391 REQUEST_VIDEO_EVENT_ENDPOINT,
392 REQUEST_VIDEO_EVENT_TYPES,
393 REQUEST_VIDEO_QADU_ENDPOINT,
394 REQUEST_VIDEO_QADU_TYPES,
395 REQUESTS_IN_PARALLEL,
397 REQUESTS_LIMIT_PER_POD,
399 REQUESTS_VIDEO_EVENT_LIMIT_PER_POD,
400 REQUESTS_VIDEO_EVENT_LIMIT_PODS,
401 REQUESTS_VIDEO_QADU_LIMIT_PER_POD,
402 REQUESTS_VIDEO_QADU_LIMIT_PODS,
405 PRIVATE_RSA_KEY_SIZE,