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