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 = 75
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 PODS: [ 'id', 'host', 'score', 'createdAt' ],
36 USERS: [ 'id', 'username', 'createdAt' ],
37 VIDEO_ABUSES: [ 'id', 'createdAt' ],
38 VIDEOS: [ 'name', 'duration', 'createdAt', 'views', 'likes' ],
39 BLACKLISTS: [ 'id', 'name', 'duration', 'views', 'likes', 'dislikes', 'uuid', 'createdAt' ]
42 const OAUTH_LIFETIME = {
43 ACCESS_TOKEN: 3600 * 4, // 4 hours
44 REFRESH_TOKEN: 1209600 // 2 weeks
47 // ---------------------------------------------------------------------------
51 PORT: config.get<number>('listen.port')
54 DBNAME: 'peertube' + config.get<string>('database.suffix'),
55 HOSTNAME: config.get<string>('database.hostname'),
56 PORT: config.get<number>('database.port'),
57 USERNAME: config.get<string>('database.username'),
58 PASSWORD: config.get<string>('database.password')
61 CERT_DIR: join(root(), config.get<string>('storage.certs')),
62 LOG_DIR: join(root(), config.get<string>('storage.logs')),
63 VIDEOS_DIR: join(root(), config.get<string>('storage.videos')),
64 THUMBNAILS_DIR: join(root(), config.get<string>('storage.thumbnails')),
65 PREVIEWS_DIR: join(root(), config.get<string>('storage.previews')),
66 TORRENTS_DIR: join(root(), config.get<string>('storage.torrents')),
67 CACHE_DIR: join(root(), config.get<string>('storage.cache'))
70 SCHEME: config.get<boolean>('webserver.https') === true ? 'https' : 'http',
71 WS: config.get<boolean>('webserver.https') === true ? 'wss' : 'ws',
72 HOSTNAME: config.get<string>('webserver.hostname'),
73 PORT: config.get<number>('webserver.port'),
78 EMAIL: config.get<string>('admin.email')
81 ENABLED: config.get<boolean>('signup.enabled'),
82 LIMIT: config.get<number>('signup.limit')
85 VIDEO_QUOTA: config.get<number>('user.video_quota')
88 ENABLED: config.get<boolean>('transcoding.enabled'),
89 THREADS: config.get<number>('transcoding.threads'),
91 '240' : config.get<boolean>('transcoding.resolutions.240p'),
92 '360': config.get<boolean>('transcoding.resolutions.360p'),
93 '480': config.get<boolean>('transcoding.resolutions.480p'),
94 '720': config.get<boolean>('transcoding.resolutions.720p'),
95 '1080': config.get<boolean>('transcoding.resolutions.1080p')
100 SIZE: config.get<number>('cache.previews.size')
104 CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
105 CONFIG.WEBSERVER.HOST = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
107 // ---------------------------------------------------------------------------
109 const CONSTRAINTS_FIELDS = {
111 USERNAME: { min: 3, max: 20 }, // Length
112 PASSWORD: { min: 6, max: 255 }, // Length
113 VIDEO_QUOTA: { min: -1 }
116 REASON: { min: 2, max: 300 } // Length
119 NAME: { min: 3, max: 50 }, // Length
120 DESCRIPTION: { min: 3, max: 250 }, // Length
121 EXTNAME: [ '.mp4', '.ogv', '.webm' ],
122 INFO_HASH: { min: 40, max: 40 }, // Length, info hash is 20 bytes length but we represent it in hexadecimal so 20 * 2
123 DURATION: { min: 1, max: 7200 }, // Number
124 TAGS: { min: 0, max: 3 }, // Number of total tags
125 TAG: { min: 2, max: 10 }, // Length
126 THUMBNAIL: { min: 2, max: 30 },
127 THUMBNAIL_DATA: { min: 0, max: 20000 }, // Bytes
130 DISLIKES: { min: 0 },
131 FILE_SIZE: { min: 10, max: 1024 * 1024 * 1024 * 3 /* 3Go */ }
138 const VIDEO_RATE_TYPES: { [ id: string ]: VideoRateType } = {
143 const VIDEO_CATEGORIES = {
158 15: 'Science & Technology',
164 // See https://creativecommons.org/licenses/?lang=en
165 const VIDEO_LICENCES = {
167 2: 'Attribution - Share Alike',
168 3: 'Attribution - No Derivatives',
169 4: 'Attribution - Non Commercial',
170 5: 'Attribution - Non Commercial - Share Alike',
171 6: 'Attribution - Non Commercial - No Derivatives',
172 7: 'Public Domain Dedication'
175 // See https://en.wikipedia.org/wiki/List_of_languages_by_number_of_native_speakers#Nationalencyklopedin
176 const VIDEO_LANGUAGES = {
193 // ---------------------------------------------------------------------------
195 // Score a pod has when we create it as a friend
196 const FRIEND_SCORE = {
201 // ---------------------------------------------------------------------------
203 // Number of points we add/remove from a friend after a successful/bad request
209 // Time to wait between requests to the friends (10 min)
210 let REQUESTS_INTERVAL = 600000
212 // Number of requests in parallel we can make
213 const REQUESTS_IN_PARALLEL = 10
215 // To how many pods we send requests
216 const REQUESTS_LIMIT_PODS = 10
217 // How many requests we send to a pod per interval
218 const REQUESTS_LIMIT_PER_POD = 5
220 const REQUESTS_VIDEO_QADU_LIMIT_PODS = 10
221 // The QADU requests are not big
222 const REQUESTS_VIDEO_QADU_LIMIT_PER_POD = 50
224 const REQUESTS_VIDEO_EVENT_LIMIT_PODS = 10
225 // The EVENTS requests are not big
226 const REQUESTS_VIDEO_EVENT_LIMIT_PER_POD = 50
228 // Number of requests to retry for replay requests module
229 const RETRY_REQUESTS = 5
231 const REQUEST_ENDPOINTS: { [ id: string ]: RequestEndpoint } = {
235 const REQUEST_ENDPOINT_ACTIONS: { [ id: string ]: any } = {}
236 REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS] = {
240 REPORT_ABUSE: 'report-abuse'
243 const REQUEST_VIDEO_QADU_ENDPOINT = 'videos/qadu'
244 const REQUEST_VIDEO_EVENT_ENDPOINT = 'videos/events'
246 const REQUEST_VIDEO_QADU_TYPES: { [ id: string ]: RequestVideoQaduType } = {
248 DISLIKES: 'dislikes',
252 const REQUEST_VIDEO_EVENT_TYPES: { [ id: string ]: RequestVideoEventType } = {
254 DISLIKES: 'dislikes',
258 const REMOTE_SCHEME = {
263 const JOB_STATES: { [ id: string ]: JobState } = {
265 PROCESSING: 'processing',
269 // How many maximum jobs we fetch from the database per cycle
270 const JOBS_FETCH_LIMIT_PER_CYCLE = 10
271 const JOBS_CONCURRENCY = 1
273 let JOBS_FETCHING_INTERVAL = 60000
275 // ---------------------------------------------------------------------------
277 const PRIVATE_CERT_NAME = 'peertube.key.pem'
278 const PUBLIC_CERT_NAME = 'peertube.pub'
279 const SIGNATURE_ALGORITHM = 'RSA-SHA256'
280 const SIGNATURE_ENCODING = 'hex'
282 // Password encryption
283 const BCRYPT_SALT_SIZE = 10
285 // ---------------------------------------------------------------------------
287 // Express static paths (router)
288 const STATIC_PATHS = {
289 PREVIEWS: '/static/previews/',
290 THUMBNAILS: '/static/thumbnails/',
291 TORRENTS: '/static/torrents/',
292 WEBSEED: '/static/webseed/'
296 let STATIC_MAX_AGE = '30d'
298 // Videos thumbnail size
299 const THUMBNAILS_SIZE = {
303 const PREVIEWS_SIZE = {
313 // Sub folders of cache directory
316 PREVIEWS: join(CONFIG.STORAGE.CACHE_DIR, 'previews')
320 // ---------------------------------------------------------------------------
322 const USER_ROLES: { [ id: string ]: UserRole } = {
327 // ---------------------------------------------------------------------------
329 const OPENGRAPH_AND_OEMBED_COMMENT = '<!-- open graph and oembed tags -->'
331 // ---------------------------------------------------------------------------
333 // Special constants for a test instance
334 if (isTestInstance() === true) {
335 CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14
336 FRIEND_SCORE.BASE = 20
337 REQUESTS_INTERVAL = 10000
338 JOBS_FETCHING_INTERVAL = 10000
339 REMOTE_SCHEME.HTTP = 'http'
340 REMOTE_SCHEME.WS = 'ws'
344 // ---------------------------------------------------------------------------
356 JOBS_FETCH_LIMIT_PER_CYCLE,
357 JOBS_FETCHING_INTERVAL,
358 LAST_MIGRATION_VERSION,
360 OPENGRAPH_AND_OEMBED_COMMENT,
361 PAGINATION_COUNT_DEFAULT,
367 REQUEST_ENDPOINT_ACTIONS,
369 REQUEST_VIDEO_EVENT_ENDPOINT,
370 REQUEST_VIDEO_EVENT_TYPES,
371 REQUEST_VIDEO_QADU_ENDPOINT,
372 REQUEST_VIDEO_QADU_TYPES,
373 REQUESTS_IN_PARALLEL,
375 REQUESTS_LIMIT_PER_POD,
377 REQUESTS_VIDEO_EVENT_LIMIT_PER_POD,
378 REQUESTS_VIDEO_EVENT_LIMIT_PODS,
379 REQUESTS_VIDEO_QADU_LIMIT_PER_POD,
380 REQUESTS_VIDEO_QADU_LIMIT_PODS,