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