3 const config
= require('config')
4 const path
= require('path')
6 // ---------------------------------------------------------------------------
8 const LAST_MIGRATION_VERSION
= 50
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', 'likes' ]
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 ENABLED: config
.get('signup.enabled')
69 CONFIG
.WEBSERVER
.URL
= CONFIG
.WEBSERVER
.SCHEME
+ '://' + CONFIG
.WEBSERVER
.HOSTNAME
+ ':' + CONFIG
.WEBSERVER
.PORT
70 CONFIG
.WEBSERVER
.HOST
= CONFIG
.WEBSERVER
.HOSTNAME
+ ':' + CONFIG
.WEBSERVER
.PORT
72 // ---------------------------------------------------------------------------
74 const CONSTRAINTS_FIELDS
= {
76 USERNAME: { min: 3, max: 20 }, // Length
77 PASSWORD: { min: 6, max: 255 } // Length
80 REASON: { min: 2, max: 300 } // Length
83 NAME: { min: 3, max: 50 }, // Length
84 DESCRIPTION: { min: 3, max: 250 }, // Length
85 EXTNAME: [ '.mp4', '.ogv', '.webm' ],
86 INFO_HASH: { min: 40, max: 40 }, // Length, infohash is 20 bytes length but we represent it in hexa so 20 * 2
87 DURATION: { min: 1, max: 7200 }, // Number
88 TAGS: { min: 0, max: 3 }, // Number of total tags
89 TAG: { min: 2, max: 10 }, // Length
90 THUMBNAIL: { min: 2, max: 30 },
91 THUMBNAIL_DATA: { min: 0, max: 20000 }, // Bytes
101 const VIDEO_RATE_TYPES
= {
106 const VIDEO_CATEGORIES
= {
121 15: 'Science & Technology',
127 // See https://creativecommons.org/licenses/?lang=en
128 const VIDEO_LICENCES
= {
130 2: 'Attribution - Share Alike',
131 3: 'Attribution - No Derivatives',
132 4: 'Attribution - Non Commercial',
133 5: 'Attribution - Non Commercial - Share Alike',
134 6: 'Attribution - Non Commercial - No Derivatives',
135 7: 'Public Domain Dedication'
138 // See https://en.wikipedia.org/wiki/List_of_languages_by_number_of_native_speakers#Nationalencyklopedin
139 const VIDEO_LANGUAGES
= {
156 // ---------------------------------------------------------------------------
158 // Score a pod has when we create it as a friend
159 const FRIEND_SCORE
= {
164 // ---------------------------------------------------------------------------
166 // Number of points we add/remove from a friend after a successful/bad request
172 // Time to wait between requests to the friends (10 min)
173 let REQUESTS_INTERVAL
= 600000
175 // Number of requests in parallel we can make
176 const REQUESTS_IN_PARALLEL
= 10
178 // To how many pods we send requests
179 const REQUESTS_LIMIT_PODS
= 10
180 // How many requests we send to a pod per interval
181 const REQUESTS_LIMIT_PER_POD
= 5
183 const REQUESTS_VIDEO_QADU_LIMIT_PODS
= 10
184 // The QADU requests are not big
185 const REQUESTS_VIDEO_QADU_LIMIT_PER_POD
= 50
187 const REQUESTS_VIDEO_EVENT_LIMIT_PODS
= 10
188 // The EVENTS requests are not big
189 const REQUESTS_VIDEO_EVENT_LIMIT_PER_POD
= 50
191 // Number of requests to retry for replay requests module
192 const RETRY_REQUESTS
= 5
194 const REQUEST_ENDPOINTS
= {
198 const REQUEST_ENDPOINT_ACTIONS
= {}
199 REQUEST_ENDPOINT_ACTIONS
[REQUEST_ENDPOINTS
.VIDEOS
] = {
203 REPORT_ABUSE: 'report-abuse'
206 const REQUEST_VIDEO_QADU_ENDPOINT
= 'videos/qadu'
207 const REQUEST_VIDEO_EVENT_ENDPOINT
= 'videos/events'
209 const REQUEST_VIDEO_QADU_TYPES
= {
211 DISLIKES: 'dislikes',
215 const REQUEST_VIDEO_EVENT_TYPES
= {
217 DISLIKES: 'dislikes',
221 const REMOTE_SCHEME
= {
226 // ---------------------------------------------------------------------------
228 const PRIVATE_CERT_NAME
= 'peertube.key.pem'
229 const PUBLIC_CERT_NAME
= 'peertube.pub'
230 const SIGNATURE_ALGORITHM
= 'RSA-SHA256'
231 const SIGNATURE_ENCODING
= 'hex'
233 // Password encryption
234 const BCRYPT_SALT_SIZE
= 10
236 // ---------------------------------------------------------------------------
238 // Express static paths (router)
239 const STATIC_PATHS
= {
240 PREVIEWS: '/static/previews/',
241 THUMBNAILS: '/static/thumbnails/',
242 TORRENTS: '/static/torrents/',
243 WEBSEED: '/static/webseed/'
247 let STATIC_MAX_AGE
= '30d'
249 // Videos thumbnail size
250 const THUMBNAILS_SIZE
= '200x110'
251 const PREVIEWS_SIZE
= '640x480'
253 // ---------------------------------------------------------------------------
260 // ---------------------------------------------------------------------------
262 // Special constants for a test instance
263 if (isTestInstance() === true) {
264 CONSTRAINTS_FIELDS
.VIDEOS
.DURATION
.max
= 14
265 FRIEND_SCORE
.BASE
= 20
266 REQUESTS_INTERVAL
= 10000
267 REMOTE_SCHEME
.HTTP
= 'http'
268 REMOTE_SCHEME
.WS
= 'ws'
272 // ---------------------------------------------------------------------------
280 LAST_MIGRATION_VERSION
,
282 PAGINATION_COUNT_DEFAULT
,
288 REQUEST_ENDPOINT_ACTIONS
,
290 REQUEST_VIDEO_EVENT_ENDPOINT
,
291 REQUEST_VIDEO_EVENT_TYPES
,
292 REQUEST_VIDEO_QADU_ENDPOINT
,
293 REQUEST_VIDEO_QADU_TYPES
,
294 REQUESTS_IN_PARALLEL
,
296 REQUESTS_LIMIT_PER_POD
,
298 REQUESTS_VIDEO_EVENT_LIMIT_PER_POD
,
299 REQUESTS_VIDEO_EVENT_LIMIT_PODS
,
300 REQUESTS_VIDEO_QADU_LIMIT_PER_POD
,
301 REQUESTS_VIDEO_QADU_LIMIT_PODS
,
317 // ---------------------------------------------------------------------------
319 // This method exists in utils module but we want to let the constants module independent
320 function isTestInstance () {
321 return (process
.env
.NODE_ENV
=== 'test')