3 const config
= require('config')
4 const path
= require('path')
6 // ---------------------------------------------------------------------------
8 const LAST_MIGRATION_VERSION
= 15
10 // ---------------------------------------------------------------------------
13 const API_VERSION
= 'v1'
15 // Number of results by default for the pagination
16 const PAGINATION_COUNT_DEFAULT
= 15
18 // Sortable columns per schema
19 const SEARCHABLE_COLUMNS
= {
20 VIDEOS: [ 'name', 'magnetUri', 'host', 'author', 'tags' ]
23 // Sortable columns per schema
24 const SORTABLE_COLUMNS
= {
25 USERS: [ 'id', 'username', 'createdAt' ],
26 VIDEO_ABUSES: [ 'id', 'createdAt' ],
27 VIDEOS: [ 'name', 'duration', 'createdAt', 'views' ]
30 const OAUTH_LIFETIME
= {
31 ACCESS_TOKEN: 3600 * 4, // 4 hours
32 REFRESH_TOKEN: 1209600 // 2 weeks
35 // ---------------------------------------------------------------------------
39 PORT: config
.get('listen.port')
42 DBNAME: 'peertube' + config
.get('database.suffix'),
43 HOSTNAME: config
.get('database.hostname'),
44 PORT: config
.get('database.port'),
45 USERNAME: config
.get('database.username'),
46 PASSWORD: config
.get('database.password')
49 CERT_DIR: path
.join(__dirname
, '..', '..', config
.get('storage.certs')),
50 LOG_DIR: path
.join(__dirname
, '..', '..', config
.get('storage.logs')),
51 VIDEOS_DIR: path
.join(__dirname
, '..', '..', config
.get('storage.videos')),
52 THUMBNAILS_DIR: path
.join(__dirname
, '..', '..', config
.get('storage.thumbnails')),
53 PREVIEWS_DIR: path
.join(__dirname
, '..', '..', config
.get('storage.previews')),
54 TORRENTS_DIR: path
.join(__dirname
, '..', '..', config
.get('storage.torrents'))
57 SCHEME: config
.get('webserver.https') === true ? 'https' : 'http',
58 WS: config
.get('webserver.https') === true ? 'wss' : 'ws',
59 HOSTNAME: config
.get('webserver.hostname'),
60 PORT: config
.get('webserver.port')
63 EMAIL: config
.get('admin.email')
66 CONFIG
.WEBSERVER
.URL
= CONFIG
.WEBSERVER
.SCHEME
+ '://' + CONFIG
.WEBSERVER
.HOSTNAME
+ ':' + CONFIG
.WEBSERVER
.PORT
67 CONFIG
.WEBSERVER
.HOST
= CONFIG
.WEBSERVER
.HOSTNAME
+ ':' + CONFIG
.WEBSERVER
.PORT
69 // ---------------------------------------------------------------------------
71 const CONSTRAINTS_FIELDS
= {
73 USERNAME: { min: 3, max: 20 }, // Length
74 PASSWORD: { min: 6, max: 255 } // Length
77 REASON: { min: 2, max: 300 } // Length
80 NAME: { min: 3, max: 50 }, // Length
81 DESCRIPTION: { min: 3, max: 250 }, // Length
82 EXTNAME: [ '.mp4', '.ogv', '.webm' ],
83 INFO_HASH: { min: 40, max: 40 }, // Length, infohash is 20 bytes length but we represent it in hexa so 20 * 2
84 DURATION: { min: 1, max: 7200 }, // Number
85 TAGS: { min: 1, max: 3 }, // Number of total tags
86 TAG: { min: 2, max: 10 }, // Length
87 THUMBNAIL: { min: 2, max: 30 },
88 THUMBNAIL_DATA: { min: 0, max: 20000 }, // Bytes
98 // ---------------------------------------------------------------------------
100 // Score a pod has when we create it as a friend
101 const FRIEND_SCORE
= {
106 // ---------------------------------------------------------------------------
108 // Number of points we add/remove from a friend after a successful/bad request
114 // Time to wait between requests to the friends (10 min)
115 let REQUESTS_INTERVAL
= 600000
117 // Number of requests in parallel we can make
118 const REQUESTS_IN_PARALLEL
= 10
120 // To how many pods we send requests
121 const REQUESTS_LIMIT_PODS
= 10
122 // How many requests we send to a pod per interval
123 const REQUESTS_LIMIT_PER_POD
= 5
125 const REQUESTS_VIDEO_QADU_LIMIT_PODS
= 10
126 // The QADU requests are not big
127 const REQUESTS_VIDEO_QADU_LIMIT_PER_POD
= 50
129 const REQUESTS_VIDEO_EVENT_LIMIT_PODS
= 10
130 // The EVENTS requests are not big
131 const REQUESTS_VIDEO_EVENT_LIMIT_PER_POD
= 50
133 // Number of requests to retry for replay requests module
134 const RETRY_REQUESTS
= 5
136 const REQUEST_ENDPOINTS
= {
139 EVENT: 'videos/events'
141 const REQUEST_ENDPOINT_ACTIONS
= {}
142 REQUEST_ENDPOINT_ACTIONS
[REQUEST_ENDPOINTS
.VIDEOS
] = {
146 REPORT_ABUSE: 'report-abuse'
149 const REQUEST_VIDEO_QADU_TYPES
= {
151 DISLIKES: 'dislikes',
155 const REQUEST_VIDEO_EVENT_TYPES
= {
157 DISLIKES: 'dislikes',
161 const REMOTE_SCHEME
= {
166 // ---------------------------------------------------------------------------
168 const PRIVATE_CERT_NAME
= 'peertube.key.pem'
169 const PUBLIC_CERT_NAME
= 'peertube.pub'
170 const SIGNATURE_ALGORITHM
= 'RSA-SHA256'
171 const SIGNATURE_ENCODING
= 'hex'
173 // Password encryption
174 const BCRYPT_SALT_SIZE
= 10
176 // ---------------------------------------------------------------------------
178 // Express static paths (router)
179 const STATIC_PATHS
= {
180 PREVIEWS: '/static/previews/',
181 THUMBNAILS: '/static/thumbnails/',
182 TORRENTS: '/static/torrents/',
183 WEBSEED: '/static/webseed/'
187 let STATIC_MAX_AGE
= '30d'
189 // Videos thumbnail size
190 const THUMBNAILS_SIZE
= '200x110'
191 const PREVIEWS_SIZE
= '640x480'
193 // ---------------------------------------------------------------------------
200 // ---------------------------------------------------------------------------
202 // Special constants for a test instance
203 if (isTestInstance() === true) {
204 CONSTRAINTS_FIELDS
.VIDEOS
.DURATION
.max
= 14
205 FRIEND_SCORE
.BASE
= 20
206 REQUESTS_INTERVAL
= 10000
207 REMOTE_SCHEME
.HTTP
= 'http'
208 REMOTE_SCHEME
.WS
= 'ws'
212 // ---------------------------------------------------------------------------
220 LAST_MIGRATION_VERSION
,
222 PAGINATION_COUNT_DEFAULT
,
228 REQUEST_ENDPOINT_ACTIONS
,
230 REQUEST_VIDEO_EVENT_TYPES
,
231 REQUEST_VIDEO_QADU_TYPES
,
232 REQUESTS_IN_PARALLEL
,
234 REQUESTS_LIMIT_PER_POD
,
236 REQUESTS_VIDEO_QADU_LIMIT_PER_POD
,
237 REQUESTS_VIDEO_QADU_LIMIT_PODS
,
238 REQUESTS_VIDEO_EVENT_LIMIT_PER_POD
,
239 REQUESTS_VIDEO_EVENT_LIMIT_PODS
,
251 // ---------------------------------------------------------------------------
253 // This method exists in utils module but we want to let the constants module independent
254 function isTestInstance () {
255 return (process
.env
.NODE_ENV
=== 'test')