]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/initializers/constants.js
Server: fix requests endpoints
[github/Chocobozzz/PeerTube.git] / server / initializers / constants.js
1 'use strict'
2
3 const config = require('config')
4 const path = require('path')
5
6 // ---------------------------------------------------------------------------
7
8 const LAST_MIGRATION_VERSION = 15
9
10 // ---------------------------------------------------------------------------
11
12 // API version
13 const API_VERSION = 'v1'
14
15 // Number of results by default for the pagination
16 const PAGINATION_COUNT_DEFAULT = 15
17
18 // Sortable columns per schema
19 const SEARCHABLE_COLUMNS = {
20 VIDEOS: [ 'name', 'magnetUri', 'host', 'author', 'tags' ]
21 }
22
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' ]
28 }
29
30 const OAUTH_LIFETIME = {
31 ACCESS_TOKEN: 3600 * 4, // 4 hours
32 REFRESH_TOKEN: 1209600 // 2 weeks
33 }
34
35 // ---------------------------------------------------------------------------
36
37 const CONFIG = {
38 LISTEN: {
39 PORT: config.get('listen.port')
40 },
41 DATABASE: {
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')
47 },
48 STORAGE: {
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'))
55 },
56 WEBSERVER: {
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')
61 },
62 ADMIN: {
63 EMAIL: config.get('admin.email')
64 }
65 }
66 CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
67 CONFIG.WEBSERVER.HOST = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
68
69 // ---------------------------------------------------------------------------
70
71 const CONSTRAINTS_FIELDS = {
72 USERS: {
73 USERNAME: { min: 3, max: 20 }, // Length
74 PASSWORD: { min: 6, max: 255 } // Length
75 },
76 VIDEO_ABUSES: {
77 REASON: { min: 2, max: 300 } // Length
78 },
79 VIDEOS: {
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
89 VIEWS: { min: 0 },
90 LIKES: { min: 0 },
91 DISLIKES: { min: 0 }
92 },
93 VIDEO_EVENTS: {
94 COUNT: { min: 0 }
95 }
96 }
97
98 // ---------------------------------------------------------------------------
99
100 // Score a pod has when we create it as a friend
101 const FRIEND_SCORE = {
102 BASE: 100,
103 MAX: 1000
104 }
105
106 // ---------------------------------------------------------------------------
107
108 // Number of points we add/remove from a friend after a successful/bad request
109 const PODS_SCORE = {
110 MALUS: -10,
111 BONUS: 10
112 }
113
114 // Time to wait between requests to the friends (10 min)
115 let REQUESTS_INTERVAL = 600000
116
117 // Number of requests in parallel we can make
118 const REQUESTS_IN_PARALLEL = 10
119
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
124
125 const REQUESTS_VIDEO_QADU_LIMIT_PODS = 10
126 // The QADU requests are not big
127 const REQUESTS_VIDEO_QADU_LIMIT_PER_POD = 50
128
129 const REQUESTS_VIDEO_EVENT_LIMIT_PODS = 10
130 // The EVENTS requests are not big
131 const REQUESTS_VIDEO_EVENT_LIMIT_PER_POD = 50
132
133 // Number of requests to retry for replay requests module
134 const RETRY_REQUESTS = 5
135
136 const REQUEST_ENDPOINTS = {
137 VIDEOS: 'videos'
138 }
139
140 const REQUEST_ENDPOINT_ACTIONS = {}
141 REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS] = {
142 ADD: 'add',
143 UPDATE: 'update',
144 REMOVE: 'remove',
145 REPORT_ABUSE: 'report-abuse'
146 }
147
148 const REQUEST_VIDEO_QADU_ENDPOINT = 'videos/qadu'
149 const REQUEST_VIDEO_EVENT_ENDPOINT = 'videos/events'
150
151 const REQUEST_VIDEO_QADU_TYPES = {
152 LIKES: 'likes',
153 DISLIKES: 'dislikes',
154 VIEWS: 'views'
155 }
156
157 const REQUEST_VIDEO_EVENT_TYPES = {
158 LIKES: 'likes',
159 DISLIKES: 'dislikes',
160 VIEWS: 'views'
161 }
162
163 const REMOTE_SCHEME = {
164 HTTP: 'https',
165 WS: 'wss'
166 }
167
168 // ---------------------------------------------------------------------------
169
170 const PRIVATE_CERT_NAME = 'peertube.key.pem'
171 const PUBLIC_CERT_NAME = 'peertube.pub'
172 const SIGNATURE_ALGORITHM = 'RSA-SHA256'
173 const SIGNATURE_ENCODING = 'hex'
174
175 // Password encryption
176 const BCRYPT_SALT_SIZE = 10
177
178 // ---------------------------------------------------------------------------
179
180 // Express static paths (router)
181 const STATIC_PATHS = {
182 PREVIEWS: '/static/previews/',
183 THUMBNAILS: '/static/thumbnails/',
184 TORRENTS: '/static/torrents/',
185 WEBSEED: '/static/webseed/'
186 }
187
188 // Cache control
189 let STATIC_MAX_AGE = '30d'
190
191 // Videos thumbnail size
192 const THUMBNAILS_SIZE = '200x110'
193 const PREVIEWS_SIZE = '640x480'
194
195 // ---------------------------------------------------------------------------
196
197 const USER_ROLES = {
198 ADMIN: 'admin',
199 USER: 'user'
200 }
201
202 // ---------------------------------------------------------------------------
203
204 // Special constants for a test instance
205 if (isTestInstance() === true) {
206 CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14
207 FRIEND_SCORE.BASE = 20
208 REQUESTS_INTERVAL = 10000
209 REMOTE_SCHEME.HTTP = 'http'
210 REMOTE_SCHEME.WS = 'ws'
211 STATIC_MAX_AGE = 0
212 }
213
214 // ---------------------------------------------------------------------------
215
216 module.exports = {
217 API_VERSION,
218 BCRYPT_SALT_SIZE,
219 CONFIG,
220 CONSTRAINTS_FIELDS,
221 FRIEND_SCORE,
222 LAST_MIGRATION_VERSION,
223 OAUTH_LIFETIME,
224 PAGINATION_COUNT_DEFAULT,
225 PODS_SCORE,
226 PREVIEWS_SIZE,
227 PRIVATE_CERT_NAME,
228 PUBLIC_CERT_NAME,
229 REMOTE_SCHEME,
230 REQUEST_ENDPOINT_ACTIONS,
231 REQUEST_ENDPOINTS,
232 REQUEST_VIDEO_EVENT_ENDPOINT,
233 REQUEST_VIDEO_EVENT_TYPES,
234 REQUEST_VIDEO_QADU_ENDPOINT,
235 REQUEST_VIDEO_QADU_TYPES,
236 REQUESTS_IN_PARALLEL,
237 REQUESTS_INTERVAL,
238 REQUESTS_LIMIT_PER_POD,
239 REQUESTS_LIMIT_PODS,
240 REQUESTS_VIDEO_EVENT_LIMIT_PER_POD,
241 REQUESTS_VIDEO_EVENT_LIMIT_PODS,
242 REQUESTS_VIDEO_QADU_LIMIT_PER_POD,
243 REQUESTS_VIDEO_QADU_LIMIT_PODS,
244 RETRY_REQUESTS,
245 SEARCHABLE_COLUMNS,
246 SIGNATURE_ALGORITHM,
247 SIGNATURE_ENCODING,
248 SORTABLE_COLUMNS,
249 STATIC_MAX_AGE,
250 STATIC_PATHS,
251 THUMBNAILS_SIZE,
252 USER_ROLES
253 }
254
255 // ---------------------------------------------------------------------------
256
257 // This method exists in utils module but we want to let the constants module independent
258 function isTestInstance () {
259 return (process.env.NODE_ENV === 'test')
260 }