1 import config = require('config')
2 import { join } from 'path'
4 // ---------------------------------------------------------------------------
6 const LAST_MIGRATION_VERSION = 50
8 // ---------------------------------------------------------------------------
11 const API_VERSION = 'v1'
13 // Number of results by default for the pagination
14 const PAGINATION_COUNT_DEFAULT = 15
16 // Sortable columns per schema
17 const SEARCHABLE_COLUMNS = {
18 VIDEOS: [ 'name', 'magnetUri', 'host', 'author', 'tags' ]
21 // Sortable columns per schema
22 const SORTABLE_COLUMNS = {
23 USERS: [ 'id', 'username', 'createdAt' ],
24 VIDEO_ABUSES: [ 'id', 'createdAt' ],
25 VIDEOS: [ 'name', 'duration', 'createdAt', 'views', 'likes' ]
28 const OAUTH_LIFETIME = {
29 ACCESS_TOKEN: 3600 * 4, // 4 hours
30 REFRESH_TOKEN: 1209600 // 2 weeks
33 // ---------------------------------------------------------------------------
37 PORT: config.get<number>('listen.port')
40 DBNAME: 'peertube' + config.get<string>('database.suffix'),
41 HOSTNAME: config.get<string>('database.hostname'),
42 PORT: config.get<number>('database.port'),
43 USERNAME: config.get<string>('database.username'),
44 PASSWORD: config.get<string>('database.password')
47 CERT_DIR: join(__dirname, '..', '..', config.get<string>('storage.certs')),
48 LOG_DIR: join(__dirname, '..', '..', config.get<string>('storage.logs')),
49 VIDEOS_DIR: join(__dirname, '..', '..', config.get<string>('storage.videos')),
50 THUMBNAILS_DIR: join(__dirname, '..', '..', config.get<string>('storage.thumbnails')),
51 PREVIEWS_DIR: join(__dirname, '..', '..', config.get<string>('storage.previews')),
52 TORRENTS_DIR: join(__dirname, '..', '..', config.get<string>('storage.torrents'))
55 SCHEME: config.get<boolean>('webserver.https') === true ? 'https' : 'http',
56 WS: config.get<boolean>('webserver.https') === true ? 'wss' : 'ws',
57 HOSTNAME: config.get<string>('webserver.hostname'),
58 PORT: config.get<number>('webserver.port'),
63 EMAIL: config.get<string>('admin.email')
66 ENABLED: config.get<boolean>('signup.enabled')
69 ENABLED: config.get<boolean>('transcoding.enabled'),
70 THREADS: config.get<number>('transcoding.threads')
73 CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
74 CONFIG.WEBSERVER.HOST = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
76 // ---------------------------------------------------------------------------
78 const CONSTRAINTS_FIELDS = {
80 USERNAME: { min: 3, max: 20 }, // Length
81 PASSWORD: { min: 6, max: 255 } // Length
84 REASON: { min: 2, max: 300 } // Length
87 NAME: { min: 3, max: 50 }, // Length
88 DESCRIPTION: { min: 3, max: 250 }, // Length
89 EXTNAME: [ '.mp4', '.ogv', '.webm' ],
90 INFO_HASH: { min: 40, max: 40 }, // Length, infohash is 20 bytes length but we represent it in hexa so 20 * 2
91 DURATION: { min: 1, max: 7200 }, // Number
92 TAGS: { min: 0, max: 3 }, // Number of total tags
93 TAG: { min: 2, max: 10 }, // Length
94 THUMBNAIL: { min: 2, max: 30 },
95 THUMBNAIL_DATA: { min: 0, max: 20000 }, // Bytes
105 const VIDEO_RATE_TYPES = {
110 const VIDEO_CATEGORIES = {
125 15: 'Science & Technology',
131 // See https://creativecommons.org/licenses/?lang=en
132 const VIDEO_LICENCES = {
134 2: 'Attribution - Share Alike',
135 3: 'Attribution - No Derivatives',
136 4: 'Attribution - Non Commercial',
137 5: 'Attribution - Non Commercial - Share Alike',
138 6: 'Attribution - Non Commercial - No Derivatives',
139 7: 'Public Domain Dedication'
142 // See https://en.wikipedia.org/wiki/List_of_languages_by_number_of_native_speakers#Nationalencyklopedin
143 const VIDEO_LANGUAGES = {
160 // ---------------------------------------------------------------------------
162 // Score a pod has when we create it as a friend
163 const FRIEND_SCORE = {
168 // ---------------------------------------------------------------------------
170 // Number of points we add/remove from a friend after a successful/bad request
176 // Time to wait between requests to the friends (10 min)
177 let REQUESTS_INTERVAL = 600000
179 // Number of requests in parallel we can make
180 const REQUESTS_IN_PARALLEL = 10
182 // To how many pods we send requests
183 const REQUESTS_LIMIT_PODS = 10
184 // How many requests we send to a pod per interval
185 const REQUESTS_LIMIT_PER_POD = 5
187 const REQUESTS_VIDEO_QADU_LIMIT_PODS = 10
188 // The QADU requests are not big
189 const REQUESTS_VIDEO_QADU_LIMIT_PER_POD = 50
191 const REQUESTS_VIDEO_EVENT_LIMIT_PODS = 10
192 // The EVENTS requests are not big
193 const REQUESTS_VIDEO_EVENT_LIMIT_PER_POD = 50
195 // Number of requests to retry for replay requests module
196 const RETRY_REQUESTS = 5
198 const REQUEST_ENDPOINTS = {
202 const REQUEST_ENDPOINT_ACTIONS = {}
203 REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS] = {
207 REPORT_ABUSE: 'report-abuse'
210 const REQUEST_VIDEO_QADU_ENDPOINT = 'videos/qadu'
211 const REQUEST_VIDEO_EVENT_ENDPOINT = 'videos/events'
213 const REQUEST_VIDEO_QADU_TYPES = {
215 DISLIKES: 'dislikes',
219 const REQUEST_VIDEO_EVENT_TYPES = {
221 DISLIKES: 'dislikes',
225 const REMOTE_SCHEME = {
232 PROCESSING: 'processing',
236 // How many maximum jobs we fetch from the database per cycle
237 const JOBS_FETCH_LIMIT_PER_CYCLE = 10
238 const JOBS_CONCURRENCY = 1
240 let JOBS_FETCHING_INTERVAL = 60000
242 // ---------------------------------------------------------------------------
244 const PRIVATE_CERT_NAME = 'peertube.key.pem'
245 const PUBLIC_CERT_NAME = 'peertube.pub'
246 const SIGNATURE_ALGORITHM = 'RSA-SHA256'
247 const SIGNATURE_ENCODING = 'hex'
249 // Password encryption
250 const BCRYPT_SALT_SIZE = 10
252 // ---------------------------------------------------------------------------
254 // Express static paths (router)
255 const STATIC_PATHS = {
256 PREVIEWS: '/static/previews/',
257 THUMBNAILS: '/static/thumbnails/',
258 TORRENTS: '/static/torrents/',
259 WEBSEED: '/static/webseed/'
263 let STATIC_MAX_AGE = '30d'
265 // Videos thumbnail size
266 const THUMBNAILS_SIZE = '200x110'
267 const PREVIEWS_SIZE = '640x480'
269 // ---------------------------------------------------------------------------
276 // ---------------------------------------------------------------------------
278 // Special constants for a test instance
279 if (isTestInstance() === true) {
280 CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14
281 FRIEND_SCORE.BASE = 20
282 REQUESTS_INTERVAL = 10000
283 JOBS_FETCHING_INTERVAL = 10000
284 REMOTE_SCHEME.HTTP = 'http'
285 REMOTE_SCHEME.WS = 'ws'
289 // ---------------------------------------------------------------------------
297 JOBS_FETCHING_INTERVAL,
300 JOBS_FETCH_LIMIT_PER_CYCLE,
301 LAST_MIGRATION_VERSION,
303 PAGINATION_COUNT_DEFAULT,
309 REQUEST_ENDPOINT_ACTIONS,
311 REQUEST_VIDEO_EVENT_ENDPOINT,
312 REQUEST_VIDEO_EVENT_TYPES,
313 REQUEST_VIDEO_QADU_ENDPOINT,
314 REQUEST_VIDEO_QADU_TYPES,
315 REQUESTS_IN_PARALLEL,
317 REQUESTS_LIMIT_PER_POD,
319 REQUESTS_VIDEO_EVENT_LIMIT_PER_POD,
320 REQUESTS_VIDEO_EVENT_LIMIT_PODS,
321 REQUESTS_VIDEO_QADU_LIMIT_PER_POD,
322 REQUESTS_VIDEO_QADU_LIMIT_PODS,
338 // ---------------------------------------------------------------------------
340 // This method exists in utils module but we want to let the constants module independent
341 function isTestInstance () {
342 return (process.env.NODE_ENV === 'test')