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