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