]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/initializers/constants.ts
Make tslint happy
[github/Chocobozzz/PeerTube.git] / server / initializers / constants.ts
1 import * as config from 'config'
2 import { join } from 'path'
3
4 // Do not use barrels, remain constants as independent as possible
5 import { root, isTestInstance } from '../helpers/core-utils'
6
7 import {
8 UserRole,
9 VideoRateType,
10 RequestEndpoint,
11 RequestVideoEventType,
12 RequestVideoQaduType,
13 JobState
14 } from '../../shared/models'
15
16 // ---------------------------------------------------------------------------
17
18 const LAST_MIGRATION_VERSION = 70
19
20 // ---------------------------------------------------------------------------
21
22 // API version
23 const API_VERSION = 'v1'
24
25 // Number of results by default for the pagination
26 const PAGINATION_COUNT_DEFAULT = 15
27
28 // Sortable columns per schema
29 const SEARCHABLE_COLUMNS = {
30 VIDEOS: [ 'name', 'magnetUri', 'host', 'author', 'tags' ]
31 }
32
33 // Sortable columns per schema
34 const SORTABLE_COLUMNS = {
35 USERS: [ 'id', 'username', 'createdAt' ],
36 VIDEO_ABUSES: [ 'id', 'createdAt' ],
37 VIDEOS: [ 'name', 'duration', 'createdAt', 'views', 'likes' ]
38 }
39
40 const OAUTH_LIFETIME = {
41 ACCESS_TOKEN: 3600 * 4, // 4 hours
42 REFRESH_TOKEN: 1209600 // 2 weeks
43 }
44
45 // ---------------------------------------------------------------------------
46
47 const CONFIG = {
48 LISTEN: {
49 PORT: config.get<number>('listen.port')
50 },
51 DATABASE: {
52 DBNAME: 'peertube' + config.get<string>('database.suffix'),
53 HOSTNAME: config.get<string>('database.hostname'),
54 PORT: config.get<number>('database.port'),
55 USERNAME: config.get<string>('database.username'),
56 PASSWORD: config.get<string>('database.password')
57 },
58 STORAGE: {
59 CERT_DIR: join(root(), config.get<string>('storage.certs')),
60 LOG_DIR: join(root(), config.get<string>('storage.logs')),
61 VIDEOS_DIR: join(root(), config.get<string>('storage.videos')),
62 THUMBNAILS_DIR: join(root(), config.get<string>('storage.thumbnails')),
63 PREVIEWS_DIR: join(root(), config.get<string>('storage.previews')),
64 TORRENTS_DIR: join(root(), config.get<string>('storage.torrents')),
65 CACHE_DIR: join(root(), config.get<string>('storage.cache'))
66 },
67 WEBSERVER: {
68 SCHEME: config.get<boolean>('webserver.https') === true ? 'https' : 'http',
69 WS: config.get<boolean>('webserver.https') === true ? 'wss' : 'ws',
70 HOSTNAME: config.get<string>('webserver.hostname'),
71 PORT: config.get<number>('webserver.port'),
72 URL: '',
73 HOST: ''
74 },
75 ADMIN: {
76 EMAIL: config.get<string>('admin.email')
77 },
78 SIGNUP: {
79 ENABLED: config.get<boolean>('signup.enabled'),
80 LIMIT: config.get<number>('signup.limit')
81 },
82 USER: {
83 VIDEO_QUOTA: config.get<number>('user.video_quota')
84 },
85 TRANSCODING: {
86 ENABLED: config.get<boolean>('transcoding.enabled'),
87 THREADS: config.get<number>('transcoding.threads')
88 },
89 CACHE: {
90 PREVIEWS: {
91 SIZE: config.get<number>('cache.previews.size')
92 }
93 }
94 }
95 CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
96 CONFIG.WEBSERVER.HOST = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
97
98 // ---------------------------------------------------------------------------
99
100 const CONSTRAINTS_FIELDS = {
101 USERS: {
102 USERNAME: { min: 3, max: 20 }, // Length
103 PASSWORD: { min: 6, max: 255 }, // Length
104 VIDEO_QUOTA: { min: -1 }
105 },
106 VIDEO_ABUSES: {
107 REASON: { min: 2, max: 300 } // Length
108 },
109 VIDEOS: {
110 NAME: { min: 3, max: 50 }, // Length
111 DESCRIPTION: { min: 3, max: 250 }, // Length
112 EXTNAME: [ '.mp4', '.ogv', '.webm' ],
113 INFO_HASH: { min: 40, max: 40 }, // Length, info hash is 20 bytes length but we represent it in hexadecimal so 20 * 2
114 DURATION: { min: 1, max: 7200 }, // Number
115 TAGS: { min: 0, max: 3 }, // Number of total tags
116 TAG: { min: 2, max: 10 }, // Length
117 THUMBNAIL: { min: 2, max: 30 },
118 THUMBNAIL_DATA: { min: 0, max: 20000 }, // Bytes
119 VIEWS: { min: 0 },
120 LIKES: { min: 0 },
121 DISLIKES: { min: 0 },
122 FILE_SIZE: { min: 10, max: 1024 * 1024 * 1024 * 3 /* 3Go */ }
123 },
124 VIDEO_EVENTS: {
125 COUNT: { min: 0 }
126 }
127 }
128
129 const VIDEO_RATE_TYPES: { [ id: string ]: VideoRateType } = {
130 LIKE: 'like',
131 DISLIKE: 'dislike'
132 }
133
134 const VIDEO_CATEGORIES = {
135 1: 'Music',
136 2: 'Films',
137 3: 'Vehicles',
138 4: 'Art',
139 5: 'Sports',
140 6: 'Travels',
141 7: 'Gaming',
142 8: 'People',
143 9: 'Comedy',
144 10: 'Entertainment',
145 11: 'News',
146 12: 'Howto',
147 13: 'Education',
148 14: 'Activism',
149 15: 'Science & Technology',
150 16: 'Animals',
151 17: 'Kids',
152 18: 'Food'
153 }
154
155 // See https://creativecommons.org/licenses/?lang=en
156 const VIDEO_LICENCES = {
157 1: 'Attribution',
158 2: 'Attribution - Share Alike',
159 3: 'Attribution - No Derivatives',
160 4: 'Attribution - Non Commercial',
161 5: 'Attribution - Non Commercial - Share Alike',
162 6: 'Attribution - Non Commercial - No Derivatives',
163 7: 'Public Domain Dedication'
164 }
165
166 // See https://en.wikipedia.org/wiki/List_of_languages_by_number_of_native_speakers#Nationalencyklopedin
167 const VIDEO_LANGUAGES = {
168 1: 'English',
169 2: 'Spanish',
170 3: 'Mandarin',
171 4: 'Hindi',
172 5: 'Arabic',
173 6: 'Portuguese',
174 7: 'Bengali',
175 8: 'Russian',
176 9: 'Japanese',
177 10: 'Punjabi',
178 11: 'German',
179 12: 'Korean',
180 13: 'French',
181 14: 'Italien'
182 }
183
184 const VIDEO_FILE_RESOLUTIONS = {
185 0: 'original',
186 1: '360p',
187 2: '480p',
188 3: '720p',
189 4: '1080p'
190 }
191
192 // ---------------------------------------------------------------------------
193
194 // Score a pod has when we create it as a friend
195 const FRIEND_SCORE = {
196 BASE: 100,
197 MAX: 1000
198 }
199
200 // ---------------------------------------------------------------------------
201
202 // Number of points we add/remove from a friend after a successful/bad request
203 const PODS_SCORE = {
204 MALUS: -10,
205 BONUS: 10
206 }
207
208 // Time to wait between requests to the friends (10 min)
209 let REQUESTS_INTERVAL = 600000
210
211 // Number of requests in parallel we can make
212 const REQUESTS_IN_PARALLEL = 10
213
214 // To how many pods we send requests
215 const REQUESTS_LIMIT_PODS = 10
216 // How many requests we send to a pod per interval
217 const REQUESTS_LIMIT_PER_POD = 5
218
219 const REQUESTS_VIDEO_QADU_LIMIT_PODS = 10
220 // The QADU requests are not big
221 const REQUESTS_VIDEO_QADU_LIMIT_PER_POD = 50
222
223 const REQUESTS_VIDEO_EVENT_LIMIT_PODS = 10
224 // The EVENTS requests are not big
225 const REQUESTS_VIDEO_EVENT_LIMIT_PER_POD = 50
226
227 // Number of requests to retry for replay requests module
228 const RETRY_REQUESTS = 5
229
230 const REQUEST_ENDPOINTS: { [ id: string ]: RequestEndpoint } = {
231 VIDEOS: 'videos'
232 }
233
234 const REQUEST_ENDPOINT_ACTIONS: { [ id: string ]: any } = {}
235 REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS] = {
236 ADD: 'add',
237 UPDATE: 'update',
238 REMOVE: 'remove',
239 REPORT_ABUSE: 'report-abuse'
240 }
241
242 const REQUEST_VIDEO_QADU_ENDPOINT = 'videos/qadu'
243 const REQUEST_VIDEO_EVENT_ENDPOINT = 'videos/events'
244
245 const REQUEST_VIDEO_QADU_TYPES: { [ id: string ]: RequestVideoQaduType } = {
246 LIKES: 'likes',
247 DISLIKES: 'dislikes',
248 VIEWS: 'views'
249 }
250
251 const REQUEST_VIDEO_EVENT_TYPES: { [ id: string ]: RequestVideoEventType } = {
252 LIKES: 'likes',
253 DISLIKES: 'dislikes',
254 VIEWS: 'views'
255 }
256
257 const REMOTE_SCHEME = {
258 HTTP: 'https',
259 WS: 'wss'
260 }
261
262 const JOB_STATES: { [ id: string ]: JobState } = {
263 PENDING: 'pending',
264 PROCESSING: 'processing',
265 ERROR: 'error',
266 SUCCESS: 'success'
267 }
268 // How many maximum jobs we fetch from the database per cycle
269 const JOBS_FETCH_LIMIT_PER_CYCLE = 10
270 const JOBS_CONCURRENCY = 1
271 // 1 minutes
272 let JOBS_FETCHING_INTERVAL = 60000
273
274 // ---------------------------------------------------------------------------
275
276 const PRIVATE_CERT_NAME = 'peertube.key.pem'
277 const PUBLIC_CERT_NAME = 'peertube.pub'
278 const SIGNATURE_ALGORITHM = 'RSA-SHA256'
279 const SIGNATURE_ENCODING = 'hex'
280
281 // Password encryption
282 const BCRYPT_SALT_SIZE = 10
283
284 // ---------------------------------------------------------------------------
285
286 // Express static paths (router)
287 const STATIC_PATHS = {
288 PREVIEWS: '/static/previews/',
289 THUMBNAILS: '/static/thumbnails/',
290 TORRENTS: '/static/torrents/',
291 WEBSEED: '/static/webseed/'
292 }
293
294 // Cache control
295 let STATIC_MAX_AGE = '30d'
296
297 // Videos thumbnail size
298 const THUMBNAILS_SIZE = '200x110'
299 const PREVIEWS_SIZE = '640x480'
300
301 // Sub folders of cache directory
302 const CACHE = {
303 DIRECTORIES: {
304 PREVIEWS: join(CONFIG.STORAGE.CACHE_DIR, 'previews')
305 }
306 }
307
308 // ---------------------------------------------------------------------------
309
310 const USER_ROLES: { [ id: string ]: UserRole } = {
311 ADMIN: 'admin',
312 USER: 'user'
313 }
314
315 // ---------------------------------------------------------------------------
316
317 const OPENGRAPH_COMMENT = '<!-- opengraph tags -->'
318
319 // ---------------------------------------------------------------------------
320
321 // Special constants for a test instance
322 if (isTestInstance() === true) {
323 CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14
324 FRIEND_SCORE.BASE = 20
325 REQUESTS_INTERVAL = 10000
326 JOBS_FETCHING_INTERVAL = 10000
327 REMOTE_SCHEME.HTTP = 'http'
328 REMOTE_SCHEME.WS = 'ws'
329 STATIC_MAX_AGE = '0'
330 }
331
332 // ---------------------------------------------------------------------------
333
334 export {
335 API_VERSION,
336 BCRYPT_SALT_SIZE,
337 CACHE,
338 CONFIG,
339 CONSTRAINTS_FIELDS,
340 FRIEND_SCORE,
341 JOB_STATES,
342 JOBS_CONCURRENCY,
343 JOBS_FETCH_LIMIT_PER_CYCLE,
344 JOBS_FETCHING_INTERVAL,
345 LAST_MIGRATION_VERSION,
346 OAUTH_LIFETIME,
347 OPENGRAPH_COMMENT,
348 PAGINATION_COUNT_DEFAULT,
349 PODS_SCORE,
350 PREVIEWS_SIZE,
351 PRIVATE_CERT_NAME,
352 PUBLIC_CERT_NAME,
353 REMOTE_SCHEME,
354 REQUEST_ENDPOINT_ACTIONS,
355 REQUEST_ENDPOINTS,
356 REQUEST_VIDEO_EVENT_ENDPOINT,
357 REQUEST_VIDEO_EVENT_TYPES,
358 REQUEST_VIDEO_QADU_ENDPOINT,
359 REQUEST_VIDEO_QADU_TYPES,
360 REQUESTS_IN_PARALLEL,
361 REQUESTS_INTERVAL,
362 REQUESTS_LIMIT_PER_POD,
363 REQUESTS_LIMIT_PODS,
364 REQUESTS_VIDEO_EVENT_LIMIT_PER_POD,
365 REQUESTS_VIDEO_EVENT_LIMIT_PODS,
366 REQUESTS_VIDEO_QADU_LIMIT_PER_POD,
367 REQUESTS_VIDEO_QADU_LIMIT_PODS,
368 RETRY_REQUESTS,
369 SEARCHABLE_COLUMNS,
370 SIGNATURE_ALGORITHM,
371 SIGNATURE_ENCODING,
372 SORTABLE_COLUMNS,
373 STATIC_MAX_AGE,
374 STATIC_PATHS,
375 THUMBNAILS_SIZE,
376 USER_ROLES,
377 VIDEO_CATEGORIES,
378 VIDEO_FILE_RESOLUTIONS,
379 VIDEO_LANGUAGES,
380 VIDEO_LICENCES,
381 VIDEO_RATE_TYPES
382 }