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