]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/initializers/constants.js
3 const config
= require('config')
4 const path
= require('path')
6 // ---------------------------------------------------------------------------
9 const API_VERSION
= 'v1'
11 // Number of results by default for the pagination
12 const PAGINATION_COUNT_DEFAULT
= 15
14 // Sortable columns per schema
15 const SEARCHABLE_COLUMNS
= {
16 VIDEOS: [ 'name', 'magnetUri', 'host', 'author', 'tags' ]
19 // Sortable columns per schema
20 const SORTABLE_COLUMNS
= {
21 USERS: [ 'username', '-username', 'createdAt', '-createdAt' ],
22 VIDEO_ABUSES: [ 'createdAt', '-createdAt' ],
23 VIDEOS: [ 'name', '-name', 'duration', '-duration', 'createdAt', '-createdAt' ]
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'),
41 USERNAME: config
.get('database.username'),
42 PASSWORD: config
.get('database.password')
45 CERT_DIR: path
.join(__dirname
, '..', '..', config
.get('storage.certs')),
46 LOG_DIR: path
.join(__dirname
, '..', '..', config
.get('storage.logs')),
47 VIDEOS_DIR: path
.join(__dirname
, '..', '..', config
.get('storage.videos')),
48 THUMBNAILS_DIR: path
.join(__dirname
, '..', '..', config
.get('storage.thumbnails')),
49 PREVIEWS_DIR: path
.join(__dirname
, '..', '..', config
.get('storage.previews')),
50 TORRENTS_DIR: path
.join(__dirname
, '..', '..', config
.get('storage.torrents'))
53 SCHEME: config
.get('webserver.https') === true ? 'https' : 'http',
54 WS: config
.get('webserver.https') === true ? 'wss' : 'ws',
55 HOSTNAME: config
.get('webserver.hostname'),
56 PORT: config
.get('webserver.port')
59 CONFIG
.WEBSERVER
.URL
= CONFIG
.WEBSERVER
.SCHEME
+ '://' + CONFIG
.WEBSERVER
.HOSTNAME
+ ':' + CONFIG
.WEBSERVER
.PORT
60 CONFIG
.WEBSERVER
.HOST
= CONFIG
.WEBSERVER
.HOSTNAME
+ ':' + CONFIG
.WEBSERVER
.PORT
62 // ---------------------------------------------------------------------------
64 const CONSTRAINTS_FIELDS
= {
66 USERNAME: { min: 3, max: 20 }, // Length
67 PASSWORD: { min: 6, max: 255 } // Length
70 REASON: { min: 2, max: 300 } // Length
73 NAME: { min: 3, max: 50 }, // Length
74 DESCRIPTION: { min: 3, max: 250 }, // Length
75 EXTNAME: [ '.mp4', '.ogv', '.webm' ],
76 INFO_HASH: { min: 40, max: 40 }, // Length, infohash is 20 bytes length but we represent it in hexa so 20 * 2
77 DURATION: { min: 1, max: 7200 }, // Number
78 TAGS: { min: 1, max: 3 }, // Number of total tags
79 TAG: { min: 2, max: 10 }, // Length
80 THUMBNAIL: { min: 2, max: 30 },
81 THUMBNAIL_DATA: { min: 0, max: 20000 } // Bytes
85 // ---------------------------------------------------------------------------
87 // Score a pod has when we create it as a friend
88 const FRIEND_SCORE
= {
93 // ---------------------------------------------------------------------------
95 const LAST_MIGRATION_VERSION
= 0
97 // ---------------------------------------------------------------------------
99 // Number of points we add/remove from a friend after a successful/bad request
105 // Time to wait between requests to the friends (10 min)
106 let REQUESTS_INTERVAL
= 600000
108 // Number of requests in parallel we can make
109 const REQUESTS_IN_PARALLEL
= 10
111 // To how many pods we send requests
112 const REQUESTS_LIMIT_PODS
= 10
113 // How many requests we send to a pod per interval
114 const REQUESTS_LIMIT_PER_POD
= 5
116 // Number of requests to retry for replay requests module
117 const RETRY_REQUESTS
= 5
119 const REQUEST_ENDPOINTS
= {
122 const REQUEST_ENDPOINT_ACTIONS
= {}
123 REQUEST_ENDPOINT_ACTIONS
[REQUEST_ENDPOINTS
.VIDEOS
] = {
127 REPORT_ABUSE: 'report-abuse'
130 const REMOTE_SCHEME
= {
135 // ---------------------------------------------------------------------------
137 const PRIVATE_CERT_NAME
= 'peertube.key.pem'
138 const PUBLIC_CERT_NAME
= 'peertube.pub'
139 const SIGNATURE_ALGORITHM
= 'RSA-SHA256'
140 const SIGNATURE_ENCODING
= 'hex'
142 // Password encryption
143 const BCRYPT_SALT_SIZE
= 10
145 // ---------------------------------------------------------------------------
147 // Express static paths (router)
148 const STATIC_PATHS
= {
149 PREVIEWS: '/static/previews/',
150 THUMBNAILS: '/static/thumbnails/',
151 TORRENTS: '/static/torrents/',
152 WEBSEED: '/static/webseed/'
156 let STATIC_MAX_AGE
= '30d'
158 // Videos thumbnail size
159 const THUMBNAILS_SIZE
= '200x110'
160 const PREVIEWS_SIZE
= '640x480'
162 // ---------------------------------------------------------------------------
169 // ---------------------------------------------------------------------------
171 // Special constants for a test instance
172 if (isTestInstance() === true) {
173 CONSTRAINTS_FIELDS
.VIDEOS
.DURATION
.max
= 14
174 FRIEND_SCORE
.BASE
= 20
175 REQUESTS_INTERVAL
= 10000
176 REMOTE_SCHEME
.HTTP
= 'http'
177 REMOTE_SCHEME
.WS
= 'ws'
181 // ---------------------------------------------------------------------------
189 LAST_MIGRATION_VERSION
,
191 PAGINATION_COUNT_DEFAULT
,
197 REQUEST_ENDPOINT_ACTIONS
,
199 REQUESTS_IN_PARALLEL
,
201 REQUESTS_LIMIT_PER_POD
,
214 // ---------------------------------------------------------------------------
216 // This method exists in utils module but we want to let the constants module independent
217 function isTestInstance () {
218 return (process
.env
.NODE_ENV
=== 'test')