3 const config
= require('config')
4 const maxBy
= require('lodash/maxBy')
5 const path
= require('path')
7 // ---------------------------------------------------------------------------
10 const API_VERSION
= 'v1'
12 // Number of results by default for the pagination
13 const PAGINATION_COUNT_DEFAULT
= 15
15 // Sortable columns per schema
16 const SEARCHABLE_COLUMNS
= {
17 VIDEOS: [ 'name', 'magnetUri', 'podUrl', 'author', 'tags' ]
20 // Sortable columns per schema
21 const SORTABLE_COLUMNS
= {
22 USERS: [ 'username', '-username', 'createdDate', '-createdDate' ],
23 VIDEOS: [ 'name', '-name', 'duration', '-duration', 'createdDate', '-createdDate' ]
26 const OAUTH_LIFETIME
= {
27 ACCESS_TOKEN: 3600 * 4, // 4 hours
28 REFRESH_TOKEN: 1209600 // 2 weeks
31 // ---------------------------------------------------------------------------
35 PORT: config
.get('listen.port')
38 DBNAME: 'peertube' + config
.get('database.suffix'),
39 HOSTNAME: config
.get('database.hostname'),
40 PORT: config
.get('database.port')
43 CERT_DIR: path
.join(__dirname
, '..', '..', config
.get('storage.certs')),
44 LOG_DIR: path
.join(__dirname
, '..', '..', config
.get('storage.logs')),
45 VIDEOS_DIR: path
.join(__dirname
, '..', '..', config
.get('storage.videos')),
46 THUMBNAILS_DIR: path
.join(__dirname
, '..', '..', config
.get('storage.thumbnails')),
47 PREVIEWS_DIR: path
.join(__dirname
, '..', '..', config
.get('storage.previews')),
48 TORRENTS_DIR: path
.join(__dirname
, '..', '..', config
.get('storage.torrents'))
51 SCHEME: config
.get('webserver.https') === true ? 'https' : 'http',
52 WS: config
.get('webserver.https') === true ? 'wss' : 'ws',
53 HOSTNAME: config
.get('webserver.hostname'),
54 PORT: config
.get('webserver.port')
57 CONFIG
.WEBSERVER
.URL
= CONFIG
.WEBSERVER
.SCHEME
+ '://' + CONFIG
.WEBSERVER
.HOSTNAME
+ ':' + CONFIG
.WEBSERVER
.PORT
59 // ---------------------------------------------------------------------------
61 const CONSTRAINTS_FIELDS
= {
63 USERNAME: { min: 3, max: 20 }, // Length
64 PASSWORD: { min: 6, max: 255 } // Length
67 NAME: { min: 3, max: 50 }, // Length
68 DESCRIPTION: { min: 3, max: 250 }, // Length
70 INFO_HASH: { min: 10, max: 50 } // Length
72 DURATION: { min: 1, max: 7200 }, // Number
73 TAGS: { min: 1, max: 3 }, // Number of total tags
74 TAG: { min: 2, max: 10 }, // Length
75 THUMBNAIL: { min: 2, max: 30 },
76 THUMBNAIL64: { min: 0, max: 20000 } // Bytes
80 // ---------------------------------------------------------------------------
82 // Score a pod has when we create it as a friend
83 const FRIEND_SCORE
= {
88 // ---------------------------------------------------------------------------
90 const MONGO_MIGRATION_SCRIPTS
= [
92 script: '0005-create-application',
96 script: '0010-users-password',
100 script: '0015-admin-role',
104 script: '0020-requests-endpoint',
108 const LAST_MONGO_SCHEMA_VERSION
= (maxBy(MONGO_MIGRATION_SCRIPTS
, 'version'))['version']
110 // ---------------------------------------------------------------------------
112 // Number of points we add/remove from a friend after a successful/bad request
118 // Time to wait between requests to the friends (10 min)
119 let REQUESTS_INTERVAL
= 600000
121 // Number of requests in parallel we can make
122 const REQUESTS_IN_PARALLEL
= 10
124 // How many requests we put in request
125 const REQUESTS_LIMIT
= 10
127 // Number of requests to retry for replay requests module
128 const RETRY_REQUESTS
= 5
130 const REQUEST_ENDPOINTS
= {
134 // ---------------------------------------------------------------------------
136 const REMOTE_SCHEME
= {
141 // Password encryption
142 const BCRYPT_SALT_SIZE
= 10
144 // Express static paths (router)
145 const STATIC_PATHS
= {
146 PREVIEWS: '/static/previews/',
147 THUMBNAILS: '/static/thumbnails/',
148 TORRENTS: '/static/torrents/',
149 WEBSEED: '/static/webseed/'
153 let STATIC_MAX_AGE
= '30d'
155 // Videos thumbnail size
156 const THUMBNAILS_SIZE
= '200x110'
157 const PREVIEWS_SIZE
= '640x480'
164 // ---------------------------------------------------------------------------
166 // Special constants for a test instance
167 if (isTestInstance() === true) {
168 CONSTRAINTS_FIELDS
.VIDEOS
.DURATION
.max
= 14
169 FRIEND_SCORE
.BASE
= 20
170 REQUESTS_INTERVAL
= 10000
171 REMOTE_SCHEME
.HTTP
= 'http'
172 REMOTE_SCHEME
.WS
= 'ws'
176 // ---------------------------------------------------------------------------
184 LAST_MONGO_SCHEMA_VERSION
,
185 MONGO_MIGRATION_SCRIPTS
,
187 PAGINATION_COUNT_DEFAULT
,
192 REQUESTS_IN_PARALLEL
,
204 // ---------------------------------------------------------------------------
206 function isTestInstance () {
207 return (process
.env
.NODE_ENV
=== 'test')