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,
14 } from '../../shared/models'
16 // ---------------------------------------------------------------------------
18 const LAST_MIGRATION_VERSION = 55
20 // ---------------------------------------------------------------------------
23 const API_VERSION = 'v1'
25 // Number of results by default for the pagination
26 const PAGINATION_COUNT_DEFAULT = 15
28 // Sortable columns per schema
29 const SEARCHABLE_COLUMNS = {
30 VIDEOS: [ 'name', 'magnetUri', 'host', 'author', 'tags' ]
33 // Sortable columns per schema
34 const SORTABLE_COLUMNS = {
35 USERS: [ 'id', 'username', 'createdAt' ],
36 VIDEO_ABUSES: [ 'id', 'createdAt' ],
37 VIDEOS: [ 'name', 'duration', 'createdAt', 'views', 'likes' ]
40 const OAUTH_LIFETIME = {
41 ACCESS_TOKEN: 3600 * 4, // 4 hours
42 REFRESH_TOKEN: 1209600 // 2 weeks
45 // ---------------------------------------------------------------------------
49 PORT: config.get<number>('listen.port')
52 DBNAME: 'peertube' + config.get<string>('database.suffix'),
53 HOSTNAME: config.get<string>('database.hostname'),
54 PORT: config.get<number>('database.port'),
55 USERNAME: config.get<string>('database.username'),
56 PASSWORD: config.get<string>('database.password')
59 CERT_DIR: join(root(), config.get<string>('storage.certs')),
60 LOG_DIR: join(root(), config.get<string>('storage.logs')),
61 VIDEOS_DIR: join(root(), config.get<string>('storage.videos')),
62 THUMBNAILS_DIR: join(root(), config.get<string>('storage.thumbnails')),
63 PREVIEWS_DIR: join(root(), config.get<string>('storage.previews')),
64 TORRENTS_DIR: join(root(), config.get<string>('storage.torrents')),
65 CACHE_DIR: join(root(), config.get<string>('storage.cache'))
68 SCHEME: config.get<boolean>('webserver.https') === true ? 'https' : 'http',
69 WS: config.get<boolean>('webserver.https') === true ? 'wss' : 'ws',
70 HOSTNAME: config.get<string>('webserver.hostname'),
71 PORT: config.get<number>('webserver.port'),
76 EMAIL: config.get<string>('admin.email')
79 ENABLED: config.get<boolean>('signup.enabled')
82 ENABLED: config.get<boolean>('transcoding.enabled'),
83 THREADS: config.get<number>('transcoding.threads')
87 SIZE: config.get<number>('cache.previews.size')
91 CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
92 CONFIG.WEBSERVER.HOST = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
94 // ---------------------------------------------------------------------------
96 const CONSTRAINTS_FIELDS = {
98 USERNAME: { min: 3, max: 20 }, // Length
99 PASSWORD: { min: 6, max: 255 } // Length
102 REASON: { min: 2, max: 300 } // Length
105 NAME: { min: 3, max: 50 }, // Length
106 DESCRIPTION: { min: 3, max: 250 }, // Length
107 EXTNAME: [ '.mp4', '.ogv', '.webm' ],
108 INFO_HASH: { min: 40, max: 40 }, // Length, infohash is 20 bytes length but we represent it in hexa so 20 * 2
109 DURATION: { min: 1, max: 7200 }, // Number
110 TAGS: { min: 0, max: 3 }, // Number of total tags
111 TAG: { min: 2, max: 10 }, // Length
112 THUMBNAIL: { min: 2, max: 30 },
113 THUMBNAIL_DATA: { min: 0, max: 20000 }, // Bytes
123 const VIDEO_RATE_TYPES: { [ id: string ]: VideoRateType } = {
128 const VIDEO_CATEGORIES = {
143 15: 'Science & Technology',
149 // See https://creativecommons.org/licenses/?lang=en
150 const VIDEO_LICENCES = {
152 2: 'Attribution - Share Alike',
153 3: 'Attribution - No Derivatives',
154 4: 'Attribution - Non Commercial',
155 5: 'Attribution - Non Commercial - Share Alike',
156 6: 'Attribution - Non Commercial - No Derivatives',
157 7: 'Public Domain Dedication'
160 // See https://en.wikipedia.org/wiki/List_of_languages_by_number_of_native_speakers#Nationalencyklopedin
161 const VIDEO_LANGUAGES = {
178 // ---------------------------------------------------------------------------
180 // Score a pod has when we create it as a friend
181 const FRIEND_SCORE = {
186 // ---------------------------------------------------------------------------
188 // Number of points we add/remove from a friend after a successful/bad request
194 // Time to wait between requests to the friends (10 min)
195 let REQUESTS_INTERVAL = 600000
197 // Number of requests in parallel we can make
198 const REQUESTS_IN_PARALLEL = 10
200 // To how many pods we send requests
201 const REQUESTS_LIMIT_PODS = 10
202 // How many requests we send to a pod per interval
203 const REQUESTS_LIMIT_PER_POD = 5
205 const REQUESTS_VIDEO_QADU_LIMIT_PODS = 10
206 // The QADU requests are not big
207 const REQUESTS_VIDEO_QADU_LIMIT_PER_POD = 50
209 const REQUESTS_VIDEO_EVENT_LIMIT_PODS = 10
210 // The EVENTS requests are not big
211 const REQUESTS_VIDEO_EVENT_LIMIT_PER_POD = 50
213 // Number of requests to retry for replay requests module
214 const RETRY_REQUESTS = 5
216 const REQUEST_ENDPOINTS: { [ id: string ]: RequestEndpoint } = {
220 const REQUEST_ENDPOINT_ACTIONS: { [ id: string ]: any } = {}
221 REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS] = {
225 REPORT_ABUSE: 'report-abuse'
228 const REQUEST_VIDEO_QADU_ENDPOINT = 'videos/qadu'
229 const REQUEST_VIDEO_EVENT_ENDPOINT = 'videos/events'
231 const REQUEST_VIDEO_QADU_TYPES: { [ id: string ]: RequestVideoQaduType } = {
233 DISLIKES: 'dislikes',
237 const REQUEST_VIDEO_EVENT_TYPES: { [ id: string ]: RequestVideoEventType } = {
239 DISLIKES: 'dislikes',
243 const REMOTE_SCHEME = {
248 const JOB_STATES: { [ id: string ]: JobState } = {
250 PROCESSING: 'processing',
254 // How many maximum jobs we fetch from the database per cycle
255 const JOBS_FETCH_LIMIT_PER_CYCLE = 10
256 const JOBS_CONCURRENCY = 1
258 let JOBS_FETCHING_INTERVAL = 60000
260 // ---------------------------------------------------------------------------
262 const PRIVATE_CERT_NAME = 'peertube.key.pem'
263 const PUBLIC_CERT_NAME = 'peertube.pub'
264 const SIGNATURE_ALGORITHM = 'RSA-SHA256'
265 const SIGNATURE_ENCODING = 'hex'
267 // Password encryption
268 const BCRYPT_SALT_SIZE = 10
270 // ---------------------------------------------------------------------------
272 // Express static paths (router)
273 const STATIC_PATHS = {
274 PREVIEWS: '/static/previews/',
275 THUMBNAILS: '/static/thumbnails/',
276 TORRENTS: '/static/torrents/',
277 WEBSEED: '/static/webseed/'
281 let STATIC_MAX_AGE = '30d'
283 // Videos thumbnail size
284 const THUMBNAILS_SIZE = '200x110'
285 const PREVIEWS_SIZE = '640x480'
287 // Subfolders of cache directory
290 PREVIEWS: join(CONFIG.STORAGE.CACHE_DIR, 'previews')
294 // ---------------------------------------------------------------------------
296 const USER_ROLES: { [ id: string ]: UserRole } = {
301 // ---------------------------------------------------------------------------
303 const OPENGRAPH_COMMENT = '<!-- opengraph tags -->'
305 // ---------------------------------------------------------------------------
307 // Special constants for a test instance
308 if (isTestInstance() === true) {
309 CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14
310 FRIEND_SCORE.BASE = 20
311 REQUESTS_INTERVAL = 10000
312 JOBS_FETCHING_INTERVAL = 10000
313 REMOTE_SCHEME.HTTP = 'http'
314 REMOTE_SCHEME.WS = 'ws'
318 // ---------------------------------------------------------------------------
329 JOBS_FETCH_LIMIT_PER_CYCLE,
330 JOBS_FETCHING_INTERVAL,
331 LAST_MIGRATION_VERSION,
334 PAGINATION_COUNT_DEFAULT,
340 REQUEST_ENDPOINT_ACTIONS,
342 REQUEST_VIDEO_EVENT_ENDPOINT,
343 REQUEST_VIDEO_EVENT_TYPES,
344 REQUEST_VIDEO_QADU_ENDPOINT,
345 REQUEST_VIDEO_QADU_TYPES,
346 REQUESTS_IN_PARALLEL,
348 REQUESTS_LIMIT_PER_POD,
350 REQUESTS_VIDEO_EVENT_LIMIT_PER_POD,
351 REQUESTS_VIDEO_EVENT_LIMIT_PODS,
352 REQUESTS_VIDEO_QADU_LIMIT_PER_POD,
353 REQUESTS_VIDEO_QADU_LIMIT_PODS,