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'),
80 LIMIT: config.get<number>('signup.limit')
83 ENABLED: config.get<boolean>('transcoding.enabled'),
84 THREADS: config.get<number>('transcoding.threads')
88 SIZE: config.get<number>('cache.previews.size')
92 CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
93 CONFIG.WEBSERVER.HOST = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
95 // ---------------------------------------------------------------------------
97 const CONSTRAINTS_FIELDS = {
99 USERNAME: { min: 3, max: 20 }, // Length
100 PASSWORD: { min: 6, max: 255 } // Length
103 REASON: { min: 2, max: 300 } // Length
106 NAME: { min: 3, max: 50 }, // Length
107 DESCRIPTION: { min: 3, max: 250 }, // Length
108 EXTNAME: [ '.mp4', '.ogv', '.webm' ],
109 INFO_HASH: { min: 40, max: 40 }, // Length, infohash is 20 bytes length but we represent it in hexa so 20 * 2
110 DURATION: { min: 1, max: 7200 }, // Number
111 TAGS: { min: 0, max: 3 }, // Number of total tags
112 TAG: { min: 2, max: 10 }, // Length
113 THUMBNAIL: { min: 2, max: 30 },
114 THUMBNAIL_DATA: { min: 0, max: 20000 }, // Bytes
124 const VIDEO_RATE_TYPES: { [ id: string ]: VideoRateType } = {
129 const VIDEO_CATEGORIES = {
144 15: 'Science & Technology',
150 // See https://creativecommons.org/licenses/?lang=en
151 const VIDEO_LICENCES = {
153 2: 'Attribution - Share Alike',
154 3: 'Attribution - No Derivatives',
155 4: 'Attribution - Non Commercial',
156 5: 'Attribution - Non Commercial - Share Alike',
157 6: 'Attribution - Non Commercial - No Derivatives',
158 7: 'Public Domain Dedication'
161 // See https://en.wikipedia.org/wiki/List_of_languages_by_number_of_native_speakers#Nationalencyklopedin
162 const VIDEO_LANGUAGES = {
179 // ---------------------------------------------------------------------------
181 // Score a pod has when we create it as a friend
182 const FRIEND_SCORE = {
187 // ---------------------------------------------------------------------------
189 // Number of points we add/remove from a friend after a successful/bad request
195 // Time to wait between requests to the friends (10 min)
196 let REQUESTS_INTERVAL = 600000
198 // Number of requests in parallel we can make
199 const REQUESTS_IN_PARALLEL = 10
201 // To how many pods we send requests
202 const REQUESTS_LIMIT_PODS = 10
203 // How many requests we send to a pod per interval
204 const REQUESTS_LIMIT_PER_POD = 5
206 const REQUESTS_VIDEO_QADU_LIMIT_PODS = 10
207 // The QADU requests are not big
208 const REQUESTS_VIDEO_QADU_LIMIT_PER_POD = 50
210 const REQUESTS_VIDEO_EVENT_LIMIT_PODS = 10
211 // The EVENTS requests are not big
212 const REQUESTS_VIDEO_EVENT_LIMIT_PER_POD = 50
214 // Number of requests to retry for replay requests module
215 const RETRY_REQUESTS = 5
217 const REQUEST_ENDPOINTS: { [ id: string ]: RequestEndpoint } = {
221 const REQUEST_ENDPOINT_ACTIONS: { [ id: string ]: any } = {}
222 REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS] = {
226 REPORT_ABUSE: 'report-abuse'
229 const REQUEST_VIDEO_QADU_ENDPOINT = 'videos/qadu'
230 const REQUEST_VIDEO_EVENT_ENDPOINT = 'videos/events'
232 const REQUEST_VIDEO_QADU_TYPES: { [ id: string ]: RequestVideoQaduType } = {
234 DISLIKES: 'dislikes',
238 const REQUEST_VIDEO_EVENT_TYPES: { [ id: string ]: RequestVideoEventType } = {
240 DISLIKES: 'dislikes',
244 const REMOTE_SCHEME = {
249 const JOB_STATES: { [ id: string ]: JobState } = {
251 PROCESSING: 'processing',
255 // How many maximum jobs we fetch from the database per cycle
256 const JOBS_FETCH_LIMIT_PER_CYCLE = 10
257 const JOBS_CONCURRENCY = 1
259 let JOBS_FETCHING_INTERVAL = 60000
261 // ---------------------------------------------------------------------------
263 const PRIVATE_CERT_NAME = 'peertube.key.pem'
264 const PUBLIC_CERT_NAME = 'peertube.pub'
265 const SIGNATURE_ALGORITHM = 'RSA-SHA256'
266 const SIGNATURE_ENCODING = 'hex'
268 // Password encryption
269 const BCRYPT_SALT_SIZE = 10
271 // ---------------------------------------------------------------------------
273 // Express static paths (router)
274 const STATIC_PATHS = {
275 PREVIEWS: '/static/previews/',
276 THUMBNAILS: '/static/thumbnails/',
277 TORRENTS: '/static/torrents/',
278 WEBSEED: '/static/webseed/'
282 let STATIC_MAX_AGE = '30d'
284 // Videos thumbnail size
285 const THUMBNAILS_SIZE = '200x110'
286 const PREVIEWS_SIZE = '640x480'
288 // Subfolders of cache directory
291 PREVIEWS: join(CONFIG.STORAGE.CACHE_DIR, 'previews')
295 // ---------------------------------------------------------------------------
297 const USER_ROLES: { [ id: string ]: UserRole } = {
302 // ---------------------------------------------------------------------------
304 const OPENGRAPH_COMMENT = '<!-- opengraph tags -->'
306 // ---------------------------------------------------------------------------
308 // Special constants for a test instance
309 if (isTestInstance() === true) {
310 CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14
311 FRIEND_SCORE.BASE = 20
312 REQUESTS_INTERVAL = 10000
313 JOBS_FETCHING_INTERVAL = 10000
314 REMOTE_SCHEME.HTTP = 'http'
315 REMOTE_SCHEME.WS = 'ws'
319 // ---------------------------------------------------------------------------
330 JOBS_FETCH_LIMIT_PER_CYCLE,
331 JOBS_FETCHING_INTERVAL,
332 LAST_MIGRATION_VERSION,
335 PAGINATION_COUNT_DEFAULT,
341 REQUEST_ENDPOINT_ACTIONS,
343 REQUEST_VIDEO_EVENT_ENDPOINT,
344 REQUEST_VIDEO_EVENT_TYPES,
345 REQUEST_VIDEO_QADU_ENDPOINT,
346 REQUEST_VIDEO_QADU_TYPES,
347 REQUESTS_IN_PARALLEL,
349 REQUESTS_LIMIT_PER_POD,
351 REQUESTS_VIDEO_EVENT_LIMIT_PER_POD,
352 REQUESTS_VIDEO_EVENT_LIMIT_PODS,
353 REQUESTS_VIDEO_QADU_LIMIT_PER_POD,
354 REQUESTS_VIDEO_QADU_LIMIT_PODS,