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