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