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