Add video privacy setting
[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 } from '../../shared/models'
15 import { VideoPrivacy } from '../../shared/models/videos/video-privacy.enum'
16
17 // ---------------------------------------------------------------------------
18
19 const LAST_MIGRATION_VERSION = 95
20
21 // ---------------------------------------------------------------------------
22
23 // API version
24 const API_VERSION = 'v1'
25
26 // Number of results by default for the pagination
27 const PAGINATION_COUNT_DEFAULT = 15
28
29 // Sortable columns per schema
30 const SEARCHABLE_COLUMNS = {
31   VIDEOS: [ 'name', 'magnetUri', 'host', 'author', 'tags' ]
32 }
33
34 // Sortable columns per schema
35 const 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
44 const OAUTH_LIFETIME = {
45   ACCESS_TOKEN: 3600 * 4, // 4 hours
46   REFRESH_TOKEN: 1209600 // 2 weeks
47 }
48
49 // ---------------------------------------------------------------------------
50
51 const 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 }
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 // ---------------------------------------------------------------------------
207
208 // Score a pod has when we create it as a friend
209 const FRIEND_SCORE = {
210   BASE: 100,
211   MAX: 1000
212 }
213
214 // ---------------------------------------------------------------------------
215
216 // Number of points we add/remove from a friend after a successful/bad request
217 const PODS_SCORE = {
218   PENALTY: -10,
219   BONUS: 10
220 }
221
222 // Time to wait between requests to the friends (10 min)
223 let REQUESTS_INTERVAL = 600000
224
225 // Number of requests in parallel we can make
226 const REQUESTS_IN_PARALLEL = 10
227
228 // To how many pods we send requests
229 const REQUESTS_LIMIT_PODS = 10
230 // How many requests we send to a pod per interval
231 const REQUESTS_LIMIT_PER_POD = 5
232
233 const REQUESTS_VIDEO_QADU_LIMIT_PODS = 10
234 // The QADU requests are not big
235 const REQUESTS_VIDEO_QADU_LIMIT_PER_POD = 50
236
237 const REQUESTS_VIDEO_EVENT_LIMIT_PODS = 10
238 // The EVENTS requests are not big
239 const REQUESTS_VIDEO_EVENT_LIMIT_PER_POD = 50
240
241 // Number of requests to retry for replay requests module
242 const RETRY_REQUESTS = 5
243
244 const REQUEST_ENDPOINTS: { [ id: string ]: RequestEndpoint } = {
245   VIDEOS: 'videos'
246 }
247
248 const REQUEST_ENDPOINT_ACTIONS: {
249   [ id: string ]: {
250     [ id: string ]: RemoteVideoRequestType
251   }
252 } = {}
253 REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS] = {
254   ADD_VIDEO: 'add-video',
255   UPDATE_VIDEO: 'update-video',
256   REMOVE_VIDEO: 'remove-video',
257   ADD_CHANNEL: 'add-channel',
258   UPDATE_CHANNEL: 'update-channel',
259   REMOVE_CHANNEL: 'remove-channel',
260   ADD_AUTHOR: 'add-author',
261   REMOVE_AUTHOR: 'remove-author',
262   REPORT_ABUSE: 'report-abuse'
263 }
264
265 const REQUEST_VIDEO_QADU_ENDPOINT = 'videos/qadu'
266 const REQUEST_VIDEO_EVENT_ENDPOINT = 'videos/events'
267
268 const REQUEST_VIDEO_QADU_TYPES: { [ id: string ]: RequestVideoQaduType } = {
269   LIKES: 'likes',
270   DISLIKES: 'dislikes',
271   VIEWS: 'views'
272 }
273
274 const REQUEST_VIDEO_EVENT_TYPES: { [ id: string ]: RequestVideoEventType } = {
275   LIKES: 'likes',
276   DISLIKES: 'dislikes',
277   VIEWS: 'views'
278 }
279
280 const REMOTE_SCHEME = {
281   HTTP: 'https',
282   WS: 'wss'
283 }
284
285 const JOB_STATES: { [ id: string ]: JobState } = {
286   PENDING: 'pending',
287   PROCESSING: 'processing',
288   ERROR: 'error',
289   SUCCESS: 'success'
290 }
291 // How many maximum jobs we fetch from the database per cycle
292 const JOBS_FETCH_LIMIT_PER_CYCLE = 10
293 // 1 minutes
294 let JOBS_FETCHING_INTERVAL = 60000
295
296 // ---------------------------------------------------------------------------
297
298 const PRIVATE_CERT_NAME = 'peertube.key.pem'
299 const PUBLIC_CERT_NAME = 'peertube.pub'
300 const SIGNATURE_ALGORITHM = 'RSA-SHA256'
301 const SIGNATURE_ENCODING = 'hex'
302
303 // Password encryption
304 const BCRYPT_SALT_SIZE = 10
305
306 // ---------------------------------------------------------------------------
307
308 // Express static paths (router)
309 const STATIC_PATHS = {
310   PREVIEWS: '/static/previews/',
311   THUMBNAILS: '/static/thumbnails/',
312   TORRENTS: '/static/torrents/',
313   WEBSEED: '/static/webseed/'
314 }
315
316 // Cache control
317 let STATIC_MAX_AGE = '30d'
318
319 // Videos thumbnail size
320 const THUMBNAILS_SIZE = {
321   width: 200,
322   height: 110
323 }
324 const PREVIEWS_SIZE = {
325   width: 560,
326   height: 315
327 }
328
329 const EMBED_SIZE = {
330   width: 560,
331   height: 315
332 }
333
334 // Sub folders of cache directory
335 const CACHE = {
336   DIRECTORIES: {
337     PREVIEWS: join(CONFIG.STORAGE.CACHE_DIR, 'previews')
338   }
339 }
340
341 // ---------------------------------------------------------------------------
342
343 const OPENGRAPH_AND_OEMBED_COMMENT = '<!-- open graph and oembed tags -->'
344
345 // ---------------------------------------------------------------------------
346
347 // Special constants for a test instance
348 if (isTestInstance() === true) {
349   CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14
350   FRIEND_SCORE.BASE = 20
351   REQUESTS_INTERVAL = 10000
352   JOBS_FETCHING_INTERVAL = 10000
353   REMOTE_SCHEME.HTTP = 'http'
354   REMOTE_SCHEME.WS = 'ws'
355   STATIC_MAX_AGE = '0'
356 }
357
358 // ---------------------------------------------------------------------------
359
360 export {
361   API_VERSION,
362   BCRYPT_SALT_SIZE,
363   CACHE,
364   CONFIG,
365   CONSTRAINTS_FIELDS,
366   EMBED_SIZE,
367   FRIEND_SCORE,
368   JOB_STATES,
369   JOBS_FETCH_LIMIT_PER_CYCLE,
370   JOBS_FETCHING_INTERVAL,
371   LAST_MIGRATION_VERSION,
372   OAUTH_LIFETIME,
373   OPENGRAPH_AND_OEMBED_COMMENT,
374   PAGINATION_COUNT_DEFAULT,
375   PODS_SCORE,
376   PREVIEWS_SIZE,
377   PRIVATE_CERT_NAME,
378   PUBLIC_CERT_NAME,
379   REMOTE_SCHEME,
380   REQUEST_ENDPOINT_ACTIONS,
381   REQUEST_ENDPOINTS,
382   REQUEST_VIDEO_EVENT_ENDPOINT,
383   REQUEST_VIDEO_EVENT_TYPES,
384   REQUEST_VIDEO_QADU_ENDPOINT,
385   REQUEST_VIDEO_QADU_TYPES,
386   REQUESTS_IN_PARALLEL,
387   REQUESTS_INTERVAL,
388   REQUESTS_LIMIT_PER_POD,
389   REQUESTS_LIMIT_PODS,
390   REQUESTS_VIDEO_EVENT_LIMIT_PER_POD,
391   REQUESTS_VIDEO_EVENT_LIMIT_PODS,
392   REQUESTS_VIDEO_QADU_LIMIT_PER_POD,
393   REQUESTS_VIDEO_QADU_LIMIT_PODS,
394   RETRY_REQUESTS,
395   SEARCHABLE_COLUMNS,
396   SIGNATURE_ALGORITHM,
397   SIGNATURE_ENCODING,
398   SORTABLE_COLUMNS,
399   STATIC_MAX_AGE,
400   STATIC_PATHS,
401   THUMBNAILS_SIZE,
402   VIDEO_CATEGORIES,
403   VIDEO_LANGUAGES,
404   VIDEO_PRIVACIES,
405   VIDEO_LICENCES,
406   VIDEO_RATE_TYPES
407 }