Remove references to author
[oweals/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   VideoRateType,
9   RequestEndpoint,
10   RequestVideoEventType,
11   RequestVideoQaduType,
12   RemoteVideoRequestType,
13   JobState,
14   JobCategory
15 } from '../../shared/models'
16 import { VideoPrivacy } from '../../shared/models/videos/video-privacy.enum'
17
18 // ---------------------------------------------------------------------------
19
20 const LAST_MIGRATION_VERSION = 95
21
22 // ---------------------------------------------------------------------------
23
24 // API version
25 const API_VERSION = 'v1'
26
27 // Number of results by default for the pagination
28 const PAGINATION_COUNT_DEFAULT = 15
29
30 // Sortable columns per schema
31 const SEARCHABLE_COLUMNS = {
32   VIDEOS: [ 'name', 'magnetUri', 'host', 'account', 'tags' ]
33 }
34
35 // Sortable columns per schema
36 const SORTABLE_COLUMNS = {
37   PODS: [ 'id', 'host', 'score', 'createdAt' ],
38   USERS: [ 'id', 'username', 'createdAt' ],
39   VIDEO_ABUSES: [ 'id', 'createdAt' ],
40   VIDEO_CHANNELS: [ 'id', 'name', 'updatedAt', 'createdAt' ],
41   VIDEOS: [ 'name', 'duration', 'createdAt', 'views', 'likes' ],
42   BLACKLISTS: [ 'id', 'name', 'duration', 'views', 'likes', 'dislikes', 'uuid', 'createdAt' ]
43 }
44
45 const OAUTH_LIFETIME = {
46   ACCESS_TOKEN: 3600 * 4, // 4 hours
47   REFRESH_TOKEN: 1209600 // 2 weeks
48 }
49
50 // ---------------------------------------------------------------------------
51
52 const CONFIG = {
53   LISTEN: {
54     PORT: config.get<number>('listen.port')
55   },
56   DATABASE: {
57     DBNAME: 'peertube' + config.get<string>('database.suffix'),
58     HOSTNAME: config.get<string>('database.hostname'),
59     PORT: config.get<number>('database.port'),
60     USERNAME: config.get<string>('database.username'),
61     PASSWORD: config.get<string>('database.password')
62   },
63   STORAGE: {
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 }
106 CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
107 CONFIG.WEBSERVER.HOST = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
108
109 // ---------------------------------------------------------------------------
110
111 const 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: 120 }, // Length
122     DESCRIPTION: { min: 3, max: 250 } // Length
123   },
124   VIDEOS: {
125     NAME: { min: 3, max: 120 }, // Length
126     TRUNCATED_DESCRIPTION: { min: 3, max: 250 }, // Length
127     DESCRIPTION: { min: 3, max: 3000 }, // Length
128     EXTNAME: [ '.mp4', '.ogv', '.webm' ],
129     INFO_HASH: { min: 40, max: 40 }, // Length, info hash is 20 bytes length but we represent it in hexadecimal so 20 * 2
130     DURATION: { min: 1, max: 7200 }, // Number
131     TAGS: { min: 0, max: 5 }, // Number of total tags
132     TAG: { min: 2, max: 30 }, // Length
133     THUMBNAIL: { min: 2, max: 30 },
134     THUMBNAIL_DATA: { min: 0, max: 20000 }, // Bytes
135     VIEWS: { min: 0 },
136     LIKES: { min: 0 },
137     DISLIKES: { min: 0 },
138     FILE_SIZE: { min: 10, max: 1024 * 1024 * 1024 * 3 /* 3Go */ }
139   },
140   VIDEO_EVENTS: {
141     COUNT: { min: 0 }
142   }
143 }
144
145 const VIDEO_RATE_TYPES: { [ id: string ]: VideoRateType } = {
146   LIKE: 'like',
147   DISLIKE: 'dislike'
148 }
149
150 const VIDEO_CATEGORIES = {
151   1: 'Music',
152   2: 'Films',
153   3: 'Vehicles',
154   4: 'Art',
155   5: 'Sports',
156   6: 'Travels',
157   7: 'Gaming',
158   8: 'People',
159   9: 'Comedy',
160   10: 'Entertainment',
161   11: 'News',
162   12: 'How To',
163   13: 'Education',
164   14: 'Activism',
165   15: 'Science & Technology',
166   16: 'Animals',
167   17: 'Kids',
168   18: 'Food'
169 }
170
171 // See https://creativecommons.org/licenses/?lang=en
172 const VIDEO_LICENCES = {
173   1: 'Attribution',
174   2: 'Attribution - Share Alike',
175   3: 'Attribution - No Derivatives',
176   4: 'Attribution - Non Commercial',
177   5: 'Attribution - Non Commercial - Share Alike',
178   6: 'Attribution - Non Commercial - No Derivatives',
179   7: 'Public Domain Dedication'
180 }
181
182 // See https://en.wikipedia.org/wiki/List_of_languages_by_number_of_native_speakers#Nationalencyklopedin
183 const VIDEO_LANGUAGES = {
184   1: 'English',
185   2: 'Spanish',
186   3: 'Mandarin',
187   4: 'Hindi',
188   5: 'Arabic',
189   6: 'Portuguese',
190   7: 'Bengali',
191   8: 'Russian',
192   9: 'Japanese',
193   10: 'Punjabi',
194   11: 'German',
195   12: 'Korean',
196   13: 'French',
197   14: 'Italian'
198 }
199
200 const VIDEO_PRIVACIES = {
201   [VideoPrivacy.PUBLIC]: 'Public',
202   [VideoPrivacy.UNLISTED]: 'Unlisted',
203   [VideoPrivacy.PRIVATE]: 'Private'
204 }
205
206 const VIDEO_MIMETYPE_EXT = {
207   'video/webm': 'webm',
208   'video/ogg': 'ogv',
209   'video/mp4': 'mp4'
210 }
211
212 // ---------------------------------------------------------------------------
213
214 // Score a pod has when we create it as a friend
215 const FRIEND_SCORE = {
216   BASE: 100,
217   MAX: 1000
218 }
219
220 const ACTIVITY_PUB = {
221   COLLECTION_ITEMS_PER_PAGE: 10,
222   VIDEO_URL_MIME_TYPES: [
223     'video/mp4',
224     'video/webm',
225     'video/ogg',
226     'application/x-bittorrent',
227     'application/x-bittorrent;x-scheme-handler/magnet'
228   ]
229 }
230
231 // ---------------------------------------------------------------------------
232
233 // Number of points we add/remove from a friend after a successful/bad request
234 const PODS_SCORE = {
235   PENALTY: -10,
236   BONUS: 10
237 }
238
239 // Time to wait between requests to the friends (10 min)
240 let REQUESTS_INTERVAL = 600000
241
242 // Number of requests in parallel we can make
243 const REQUESTS_IN_PARALLEL = 10
244
245 // To how many pods we send requests
246 const REQUESTS_LIMIT_PODS = 10
247 // How many requests we send to a pod per interval
248 const REQUESTS_LIMIT_PER_POD = 5
249
250 const REQUESTS_VIDEO_QADU_LIMIT_PODS = 10
251 // The QADU requests are not big
252 const REQUESTS_VIDEO_QADU_LIMIT_PER_POD = 50
253
254 const REQUESTS_VIDEO_EVENT_LIMIT_PODS = 10
255 // The EVENTS requests are not big
256 const REQUESTS_VIDEO_EVENT_LIMIT_PER_POD = 50
257
258 // Number of requests to retry for replay requests module
259 const RETRY_REQUESTS = 5
260
261 const REMOTE_SCHEME = {
262   HTTP: 'https',
263   WS: 'wss'
264 }
265
266 const JOB_STATES: { [ id: string ]: JobState } = {
267   PENDING: 'pending',
268   PROCESSING: 'processing',
269   ERROR: 'error',
270   SUCCESS: 'success'
271 }
272 const JOB_CATEGORIES: { [ id: string ]: JobCategory } = {
273   TRANSCODING: 'transcoding',
274   HTTP_REQUEST: 'http-request'
275 }
276 // How many maximum jobs we fetch from the database per cycle
277 const JOBS_FETCH_LIMIT_PER_CYCLE = {
278   transcoding: 10,
279   httpRequest: 20
280 }
281 // 1 minutes
282 let JOBS_FETCHING_INTERVAL = 60000
283
284 // ---------------------------------------------------------------------------
285
286 const PRIVATE_RSA_KEY_SIZE = 2048
287
288 // Password encryption
289 const BCRYPT_SALT_SIZE = 10
290
291 // ---------------------------------------------------------------------------
292
293 // Express static paths (router)
294 const STATIC_PATHS = {
295   PREVIEWS: '/static/previews/',
296   THUMBNAILS: '/static/thumbnails/',
297   TORRENTS: '/static/torrents/',
298   WEBSEED: '/static/webseed/'
299 }
300
301 // Cache control
302 let STATIC_MAX_AGE = '30d'
303
304 // Videos thumbnail size
305 const THUMBNAILS_SIZE = {
306   width: 200,
307   height: 110
308 }
309 const PREVIEWS_SIZE = {
310   width: 560,
311   height: 315
312 }
313
314 const EMBED_SIZE = {
315   width: 560,
316   height: 315
317 }
318
319 // Sub folders of cache directory
320 const CACHE = {
321   DIRECTORIES: {
322     PREVIEWS: join(CONFIG.STORAGE.CACHE_DIR, 'previews')
323   }
324 }
325
326 // ---------------------------------------------------------------------------
327
328 const OPENGRAPH_AND_OEMBED_COMMENT = '<!-- open graph and oembed tags -->'
329
330 // ---------------------------------------------------------------------------
331
332 // Special constants for a test instance
333 if (isTestInstance() === true) {
334   CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14
335   FRIEND_SCORE.BASE = 20
336   REQUESTS_INTERVAL = 10000
337   JOBS_FETCHING_INTERVAL = 10000
338   REMOTE_SCHEME.HTTP = 'http'
339   REMOTE_SCHEME.WS = 'ws'
340   STATIC_MAX_AGE = '0'
341 }
342
343 // ---------------------------------------------------------------------------
344
345 export {
346   API_VERSION,
347   BCRYPT_SALT_SIZE,
348   CACHE,
349   CONFIG,
350   CONSTRAINTS_FIELDS,
351   EMBED_SIZE,
352   FRIEND_SCORE,
353   JOB_STATES,
354   JOBS_FETCH_LIMIT_PER_CYCLE,
355   JOBS_FETCHING_INTERVAL,
356   JOB_CATEGORIES,
357   LAST_MIGRATION_VERSION,
358   OAUTH_LIFETIME,
359   OPENGRAPH_AND_OEMBED_COMMENT,
360   PAGINATION_COUNT_DEFAULT,
361   PODS_SCORE,
362   PREVIEWS_SIZE,
363   REMOTE_SCHEME,
364   REQUEST_ENDPOINT_ACTIONS,
365   REQUEST_ENDPOINTS,
366   REQUEST_VIDEO_EVENT_ENDPOINT,
367   REQUEST_VIDEO_EVENT_TYPES,
368   REQUEST_VIDEO_QADU_ENDPOINT,
369   REQUEST_VIDEO_QADU_TYPES,
370   REQUESTS_IN_PARALLEL,
371   REQUESTS_INTERVAL,
372   REQUESTS_LIMIT_PER_POD,
373   REQUESTS_LIMIT_PODS,
374   REQUESTS_VIDEO_EVENT_LIMIT_PER_POD,
375   REQUESTS_VIDEO_EVENT_LIMIT_PODS,
376   REQUESTS_VIDEO_QADU_LIMIT_PER_POD,
377   REQUESTS_VIDEO_QADU_LIMIT_PODS,
378   RETRY_REQUESTS,
379   SEARCHABLE_COLUMNS,
380   PRIVATE_RSA_KEY_SIZE,
381   SORTABLE_COLUMNS,
382   STATIC_MAX_AGE,
383   STATIC_PATHS,
384   ACTIVITY_PUB,
385   THUMBNAILS_SIZE,
386   VIDEO_CATEGORIES,
387   VIDEO_LANGUAGES,
388   VIDEO_PRIVACIES,
389   VIDEO_LICENCES,
390   VIDEO_RATE_TYPES,
391   VIDEO_MIMETYPE_EXT
392 }