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