]>
Commit | Line | Data |
---|---|---|
1 | import * as config from 'config' | |
2 | import { join } from 'path' | |
3 | import { JobCategory, JobState, VideoRateType } from '../../shared/models' | |
4 | import { ActivityPubActorType } from '../../shared/models/activitypub' | |
5 | import { FollowState } from '../../shared/models/actors' | |
6 | import { VideoPrivacy } from '../../shared/models/videos' | |
7 | // Do not use barrels, remain constants as independent as possible | |
8 | import { isTestInstance, root, sanitizeHost, sanitizeUrl } from '../helpers/core-utils' | |
9 | ||
10 | // --------------------------------------------------------------------------- | |
11 | ||
12 | const LAST_MIGRATION_VERSION = 155 | |
13 | ||
14 | // --------------------------------------------------------------------------- | |
15 | ||
16 | // API version | |
17 | const API_VERSION = 'v1' | |
18 | ||
19 | // Number of results by default for the pagination | |
20 | const PAGINATION_COUNT_DEFAULT = 15 | |
21 | ||
22 | // Sortable columns per schema | |
23 | const SORTABLE_COLUMNS = { | |
24 | USERS: [ 'id', 'username', 'createdAt' ], | |
25 | ACCOUNTS: [ 'createdAt' ], | |
26 | JOBS: [ 'id', 'createdAt' ], | |
27 | VIDEO_ABUSES: [ 'id', 'createdAt' ], | |
28 | VIDEO_CHANNELS: [ 'id', 'name', 'updatedAt', 'createdAt' ], | |
29 | VIDEOS: [ 'name', 'duration', 'createdAt', 'views', 'likes' ], | |
30 | VIDEO_COMMENT_THREADS: [ 'createdAt' ], | |
31 | BLACKLISTS: [ 'id', 'name', 'duration', 'views', 'likes', 'dislikes', 'uuid', 'createdAt' ], | |
32 | FOLLOWERS: [ 'createdAt' ], | |
33 | FOLLOWING: [ 'createdAt' ] | |
34 | } | |
35 | ||
36 | const OAUTH_LIFETIME = { | |
37 | ACCESS_TOKEN: 3600 * 4, // 4 hours | |
38 | REFRESH_TOKEN: 1209600 // 2 weeks | |
39 | } | |
40 | ||
41 | // --------------------------------------------------------------------------- | |
42 | ||
43 | // Number of points we add/remove from a friend after a successful/bad request | |
44 | const SERVERS_SCORE = { | |
45 | PENALTY: -10, | |
46 | BONUS: 10, | |
47 | BASE: 100, | |
48 | MAX: 1000 | |
49 | } | |
50 | ||
51 | const FOLLOW_STATES: { [ id: string ]: FollowState } = { | |
52 | PENDING: 'pending', | |
53 | ACCEPTED: 'accepted' | |
54 | } | |
55 | ||
56 | const REMOTE_SCHEME = { | |
57 | HTTP: 'https', | |
58 | WS: 'wss' | |
59 | } | |
60 | ||
61 | const JOB_STATES: { [ id: string ]: JobState } = { | |
62 | PENDING: 'pending', | |
63 | PROCESSING: 'processing', | |
64 | ERROR: 'error', | |
65 | SUCCESS: 'success' | |
66 | } | |
67 | const JOB_CATEGORIES: { [ id: string ]: JobCategory } = { | |
68 | TRANSCODING: 'transcoding', | |
69 | ACTIVITYPUB_HTTP: 'activitypub-http' | |
70 | } | |
71 | // How many maximum jobs we fetch from the database per cycle | |
72 | const JOBS_FETCH_LIMIT_PER_CYCLE = { | |
73 | transcoding: 10, | |
74 | httpRequest: 20 | |
75 | } | |
76 | // 1 minutes | |
77 | let JOBS_FETCHING_INTERVAL = 60000 | |
78 | ||
79 | // --------------------------------------------------------------------------- | |
80 | ||
81 | const CONFIG = { | |
82 | LISTEN: { | |
83 | PORT: config.get<number>('listen.port') | |
84 | }, | |
85 | DATABASE: { | |
86 | DBNAME: 'peertube' + config.get<string>('database.suffix'), | |
87 | HOSTNAME: config.get<string>('database.hostname'), | |
88 | PORT: config.get<number>('database.port'), | |
89 | USERNAME: config.get<string>('database.username'), | |
90 | PASSWORD: config.get<string>('database.password') | |
91 | }, | |
92 | STORAGE: { | |
93 | AVATARS_DIR: join(root(), config.get<string>('storage.avatars')), | |
94 | LOG_DIR: join(root(), config.get<string>('storage.logs')), | |
95 | VIDEOS_DIR: join(root(), config.get<string>('storage.videos')), | |
96 | THUMBNAILS_DIR: join(root(), config.get<string>('storage.thumbnails')), | |
97 | PREVIEWS_DIR: join(root(), config.get<string>('storage.previews')), | |
98 | TORRENTS_DIR: join(root(), config.get<string>('storage.torrents')), | |
99 | CACHE_DIR: join(root(), config.get<string>('storage.cache')) | |
100 | }, | |
101 | WEBSERVER: { | |
102 | SCHEME: config.get<boolean>('webserver.https') === true ? 'https' : 'http', | |
103 | WS: config.get<boolean>('webserver.https') === true ? 'wss' : 'ws', | |
104 | HOSTNAME: config.get<string>('webserver.hostname'), | |
105 | PORT: config.get<number>('webserver.port'), | |
106 | URL: '', | |
107 | HOST: '' | |
108 | }, | |
109 | ADMIN: { | |
110 | EMAIL: config.get<string>('admin.email') | |
111 | }, | |
112 | SIGNUP: { | |
113 | ENABLED: config.get<boolean>('signup.enabled'), | |
114 | LIMIT: config.get<number>('signup.limit') | |
115 | }, | |
116 | USER: { | |
117 | VIDEO_QUOTA: config.get<number>('user.video_quota') | |
118 | }, | |
119 | TRANSCODING: { | |
120 | ENABLED: config.get<boolean>('transcoding.enabled'), | |
121 | THREADS: config.get<number>('transcoding.threads'), | |
122 | RESOLUTIONS: { | |
123 | '240' : config.get<boolean>('transcoding.resolutions.240p'), | |
124 | '360': config.get<boolean>('transcoding.resolutions.360p'), | |
125 | '480': config.get<boolean>('transcoding.resolutions.480p'), | |
126 | '720': config.get<boolean>('transcoding.resolutions.720p'), | |
127 | '1080': config.get<boolean>('transcoding.resolutions.1080p') | |
128 | } | |
129 | }, | |
130 | CACHE: { | |
131 | PREVIEWS: { | |
132 | SIZE: config.get<number>('cache.previews.size') | |
133 | } | |
134 | } | |
135 | } | |
136 | ||
137 | // --------------------------------------------------------------------------- | |
138 | ||
139 | const CONSTRAINTS_FIELDS = { | |
140 | USERS: { | |
141 | USERNAME: { min: 3, max: 20 }, // Length | |
142 | PASSWORD: { min: 6, max: 255 }, // Length | |
143 | VIDEO_QUOTA: { min: -1 } | |
144 | }, | |
145 | VIDEO_ABUSES: { | |
146 | REASON: { min: 2, max: 300 } // Length | |
147 | }, | |
148 | VIDEO_CHANNELS: { | |
149 | NAME: { min: 3, max: 120 }, // Length | |
150 | DESCRIPTION: { min: 3, max: 250 }, // Length | |
151 | URL: { min: 3, max: 2000 } // Length | |
152 | }, | |
153 | VIDEOS: { | |
154 | NAME: { min: 3, max: 120 }, // Length | |
155 | TRUNCATED_DESCRIPTION: { min: 3, max: 250 }, // Length | |
156 | DESCRIPTION: { min: 3, max: 3000 }, // Length | |
157 | EXTNAME: [ '.mp4', '.ogv', '.webm' ], | |
158 | INFO_HASH: { min: 40, max: 40 }, // Length, info hash is 20 bytes length but we represent it in hexadecimal so 20 * 2 | |
159 | DURATION: { min: 1 }, // Number | |
160 | TAGS: { min: 0, max: 5 }, // Number of total tags | |
161 | TAG: { min: 2, max: 30 }, // Length | |
162 | THUMBNAIL: { min: 2, max: 30 }, | |
163 | THUMBNAIL_DATA: { min: 0, max: 20000 }, // Bytes | |
164 | VIEWS: { min: 0 }, | |
165 | LIKES: { min: 0 }, | |
166 | DISLIKES: { min: 0 }, | |
167 | FILE_SIZE: { min: 10 }, | |
168 | URL: { min: 3, max: 2000 } // Length | |
169 | }, | |
170 | ACTORS: { | |
171 | PUBLIC_KEY: { min: 10, max: 5000 }, // Length | |
172 | PRIVATE_KEY: { min: 10, max: 5000 }, // Length | |
173 | URL: { min: 3, max: 2000 }, // Length | |
174 | AVATAR: { | |
175 | EXTNAME: [ '.png', '.jpeg', '.jpg' ], | |
176 | FILE_SIZE: { | |
177 | max: 2 * 1024 * 1024 // 2MB | |
178 | } | |
179 | } | |
180 | }, | |
181 | VIDEO_EVENTS: { | |
182 | COUNT: { min: 0 } | |
183 | }, | |
184 | VIDEO_COMMENTS: { | |
185 | TEXT: { min: 2, max: 3000 }, // Length | |
186 | URL: { min: 3, max: 2000 } // Length | |
187 | } | |
188 | } | |
189 | ||
190 | const VIDEO_RATE_TYPES: { [ id: string ]: VideoRateType } = { | |
191 | LIKE: 'like', | |
192 | DISLIKE: 'dislike' | |
193 | } | |
194 | ||
195 | const VIDEO_CATEGORIES = { | |
196 | 1: 'Music', | |
197 | 2: 'Films', | |
198 | 3: 'Vehicles', | |
199 | 4: 'Art', | |
200 | 5: 'Sports', | |
201 | 6: 'Travels', | |
202 | 7: 'Gaming', | |
203 | 8: 'People', | |
204 | 9: 'Comedy', | |
205 | 10: 'Entertainment', | |
206 | 11: 'News', | |
207 | 12: 'How To', | |
208 | 13: 'Education', | |
209 | 14: 'Activism', | |
210 | 15: 'Science & Technology', | |
211 | 16: 'Animals', | |
212 | 17: 'Kids', | |
213 | 18: 'Food' | |
214 | } | |
215 | ||
216 | // See https://creativecommons.org/licenses/?lang=en | |
217 | const VIDEO_LICENCES = { | |
218 | 1: 'Attribution', | |
219 | 2: 'Attribution - Share Alike', | |
220 | 3: 'Attribution - No Derivatives', | |
221 | 4: 'Attribution - Non Commercial', | |
222 | 5: 'Attribution - Non Commercial - Share Alike', | |
223 | 6: 'Attribution - Non Commercial - No Derivatives', | |
224 | 7: 'Public Domain Dedication' | |
225 | } | |
226 | ||
227 | // See https://en.wikipedia.org/wiki/List_of_languages_by_number_of_native_speakers#Nationalencyklopedin | |
228 | const VIDEO_LANGUAGES = { | |
229 | 1: 'English', | |
230 | 2: 'Spanish', | |
231 | 3: 'Mandarin', | |
232 | 4: 'Hindi', | |
233 | 5: 'Arabic', | |
234 | 6: 'Portuguese', | |
235 | 7: 'Bengali', | |
236 | 8: 'Russian', | |
237 | 9: 'Japanese', | |
238 | 10: 'Punjabi', | |
239 | 11: 'German', | |
240 | 12: 'Korean', | |
241 | 13: 'French', | |
242 | 14: 'Italian' | |
243 | } | |
244 | ||
245 | const VIDEO_PRIVACIES = { | |
246 | [VideoPrivacy.PUBLIC]: 'Public', | |
247 | [VideoPrivacy.UNLISTED]: 'Unlisted', | |
248 | [VideoPrivacy.PRIVATE]: 'Private' | |
249 | } | |
250 | ||
251 | const VIDEO_MIMETYPE_EXT = { | |
252 | 'video/webm': '.webm', | |
253 | 'video/ogg': '.ogv', | |
254 | 'video/mp4': '.mp4' | |
255 | } | |
256 | ||
257 | const AVATAR_MIMETYPE_EXT = { | |
258 | 'image/png': '.png', | |
259 | 'image/jpg': '.jpg', | |
260 | 'image/jpeg': '.jpg' | |
261 | } | |
262 | ||
263 | // --------------------------------------------------------------------------- | |
264 | ||
265 | const SERVER_ACTOR_NAME = 'peertube' | |
266 | ||
267 | const ACTIVITY_PUB = { | |
268 | POTENTIAL_ACCEPT_HEADERS: [ | |
269 | 'application/activity+json', | |
270 | 'application/ld+json' | |
271 | ], | |
272 | ACCEPT_HEADER: 'application/activity+json, application/ld+json', | |
273 | PUBLIC: 'https://www.w3.org/ns/activitystreams#Public', | |
274 | COLLECTION_ITEMS_PER_PAGE: 10, | |
275 | FETCH_PAGE_LIMIT: 100, | |
276 | MAX_HTTP_ATTEMPT: 5, | |
277 | URL_MIME_TYPES: { | |
278 | VIDEO: [ 'video/mp4', 'video/webm', 'video/ogg' ], // TODO: Merge with VIDEO_MIMETYPE_EXT | |
279 | TORRENT: [ 'application/x-bittorrent' ], | |
280 | MAGNET: [ 'application/x-bittorrent;x-scheme-handler/magnet' ] | |
281 | }, | |
282 | ACTOR_REFRESH_INTERVAL: 3600 * 24 // 1 day | |
283 | } | |
284 | ||
285 | const ACTIVITY_PUB_ACTOR_TYPES: { [ id: string ]: ActivityPubActorType } = { | |
286 | GROUP: 'Group', | |
287 | PERSON: 'Person', | |
288 | APPLICATION: 'Application' | |
289 | } | |
290 | ||
291 | // --------------------------------------------------------------------------- | |
292 | ||
293 | const PRIVATE_RSA_KEY_SIZE = 2048 | |
294 | ||
295 | // Password encryption | |
296 | const BCRYPT_SALT_SIZE = 10 | |
297 | ||
298 | // --------------------------------------------------------------------------- | |
299 | ||
300 | // Express static paths (router) | |
301 | const STATIC_PATHS = { | |
302 | PREVIEWS: '/static/previews/', | |
303 | THUMBNAILS: '/static/thumbnails/', | |
304 | TORRENTS: '/static/torrents/', | |
305 | WEBSEED: '/static/webseed/', | |
306 | AVATARS: '/static/avatars/' | |
307 | } | |
308 | ||
309 | // Cache control | |
310 | let STATIC_MAX_AGE = '30d' | |
311 | ||
312 | // Videos thumbnail size | |
313 | const THUMBNAILS_SIZE = { | |
314 | width: 200, | |
315 | height: 110 | |
316 | } | |
317 | const PREVIEWS_SIZE = { | |
318 | width: 560, | |
319 | height: 315 | |
320 | } | |
321 | const AVATARS_SIZE = { | |
322 | width: 120, | |
323 | height: 120 | |
324 | } | |
325 | ||
326 | const EMBED_SIZE = { | |
327 | width: 560, | |
328 | height: 315 | |
329 | } | |
330 | ||
331 | // Sub folders of cache directory | |
332 | const CACHE = { | |
333 | DIRECTORIES: { | |
334 | PREVIEWS: join(CONFIG.STORAGE.CACHE_DIR, 'previews') | |
335 | } | |
336 | } | |
337 | ||
338 | const ACCEPT_HEADERS = [ 'html', 'application/json' ].concat(ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS) | |
339 | ||
340 | // --------------------------------------------------------------------------- | |
341 | ||
342 | const OPENGRAPH_AND_OEMBED_COMMENT = '<!-- open graph and oembed tags -->' | |
343 | ||
344 | // --------------------------------------------------------------------------- | |
345 | ||
346 | // Special constants for a test instance | |
347 | if (isTestInstance() === true) { | |
348 | SERVERS_SCORE.BASE = 20 | |
349 | JOBS_FETCHING_INTERVAL = 1000 | |
350 | REMOTE_SCHEME.HTTP = 'http' | |
351 | REMOTE_SCHEME.WS = 'ws' | |
352 | STATIC_MAX_AGE = '0' | |
353 | ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE = 2 | |
354 | ACTIVITY_PUB.ACTOR_REFRESH_INTERVAL = 60 // 1 minute | |
355 | CONSTRAINTS_FIELDS.ACTORS.AVATAR.FILE_SIZE.max = 100 * 1024 // 100KB | |
356 | } | |
357 | ||
358 | CONFIG.WEBSERVER.URL = sanitizeUrl(CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT) | |
359 | CONFIG.WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT, REMOTE_SCHEME.HTTP) | |
360 | ||
361 | // --------------------------------------------------------------------------- | |
362 | ||
363 | export { | |
364 | API_VERSION, | |
365 | AVATARS_SIZE, | |
366 | ACCEPT_HEADERS, | |
367 | BCRYPT_SALT_SIZE, | |
368 | CACHE, | |
369 | CONFIG, | |
370 | CONSTRAINTS_FIELDS, | |
371 | EMBED_SIZE, | |
372 | JOB_STATES, | |
373 | JOBS_FETCH_LIMIT_PER_CYCLE, | |
374 | JOBS_FETCHING_INTERVAL, | |
375 | JOB_CATEGORIES, | |
376 | LAST_MIGRATION_VERSION, | |
377 | OAUTH_LIFETIME, | |
378 | OPENGRAPH_AND_OEMBED_COMMENT, | |
379 | PAGINATION_COUNT_DEFAULT, | |
380 | SERVERS_SCORE, | |
381 | PREVIEWS_SIZE, | |
382 | REMOTE_SCHEME, | |
383 | FOLLOW_STATES, | |
384 | SERVER_ACTOR_NAME, | |
385 | PRIVATE_RSA_KEY_SIZE, | |
386 | SORTABLE_COLUMNS, | |
387 | STATIC_MAX_AGE, | |
388 | STATIC_PATHS, | |
389 | ACTIVITY_PUB, | |
390 | ACTIVITY_PUB_ACTOR_TYPES, | |
391 | THUMBNAILS_SIZE, | |
392 | VIDEO_CATEGORIES, | |
393 | VIDEO_LANGUAGES, | |
394 | VIDEO_PRIVACIES, | |
395 | VIDEO_LICENCES, | |
396 | VIDEO_RATE_TYPES, | |
397 | VIDEO_MIMETYPE_EXT, | |
398 | AVATAR_MIMETYPE_EXT | |
399 | } |