]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/initializers/constants.ts
Add migration to delete old Authors table
[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 = 145
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 },
177 VIDEO_EVENTS: {
178 COUNT: { min: 0 }
179 },
180 VIDEO_COMMENTS: {
181 TEXT: { min: 2, max: 3000 }, // Length
182 URL: { min: 3, max: 2000 } // Length
183 }
184 }
185
186 const VIDEO_RATE_TYPES: { [ id: string ]: VideoRateType } = {
187 LIKE: 'like',
188 DISLIKE: 'dislike'
189 }
190
191 const VIDEO_CATEGORIES = {
192 1: 'Music',
193 2: 'Films',
194 3: 'Vehicles',
195 4: 'Art',
196 5: 'Sports',
197 6: 'Travels',
198 7: 'Gaming',
199 8: 'People',
200 9: 'Comedy',
201 10: 'Entertainment',
202 11: 'News',
203 12: 'How To',
204 13: 'Education',
205 14: 'Activism',
206 15: 'Science & Technology',
207 16: 'Animals',
208 17: 'Kids',
209 18: 'Food'
210 }
211
212 // See https://creativecommons.org/licenses/?lang=en
213 const VIDEO_LICENCES = {
214 1: 'Attribution',
215 2: 'Attribution - Share Alike',
216 3: 'Attribution - No Derivatives',
217 4: 'Attribution - Non Commercial',
218 5: 'Attribution - Non Commercial - Share Alike',
219 6: 'Attribution - Non Commercial - No Derivatives',
220 7: 'Public Domain Dedication'
221 }
222
223 // See https://en.wikipedia.org/wiki/List_of_languages_by_number_of_native_speakers#Nationalencyklopedin
224 const VIDEO_LANGUAGES = {
225 1: 'English',
226 2: 'Spanish',
227 3: 'Mandarin',
228 4: 'Hindi',
229 5: 'Arabic',
230 6: 'Portuguese',
231 7: 'Bengali',
232 8: 'Russian',
233 9: 'Japanese',
234 10: 'Punjabi',
235 11: 'German',
236 12: 'Korean',
237 13: 'French',
238 14: 'Italian'
239 }
240
241 const VIDEO_PRIVACIES = {
242 [VideoPrivacy.PUBLIC]: 'Public',
243 [VideoPrivacy.UNLISTED]: 'Unlisted',
244 [VideoPrivacy.PRIVATE]: 'Private'
245 }
246
247 const VIDEO_MIMETYPE_EXT = {
248 'video/webm': '.webm',
249 'video/ogg': '.ogv',
250 'video/mp4': '.mp4'
251 }
252
253 // ---------------------------------------------------------------------------
254
255 const SERVER_ACTOR_NAME = 'peertube'
256
257 const ACTIVITY_PUB = {
258 POTENTIAL_ACCEPT_HEADERS: [
259 'application/activity+json',
260 'application/ld+json'
261 ],
262 ACCEPT_HEADER: 'application/activity+json, application/ld+json',
263 PUBLIC: 'https://www.w3.org/ns/activitystreams#Public',
264 COLLECTION_ITEMS_PER_PAGE: 10,
265 FETCH_PAGE_LIMIT: 100,
266 MAX_HTTP_ATTEMPT: 5,
267 URL_MIME_TYPES: {
268 VIDEO: [ 'video/mp4', 'video/webm', 'video/ogg' ], // TODO: Merge with VIDEO_MIMETYPE_EXT
269 TORRENT: [ 'application/x-bittorrent' ],
270 MAGNET: [ 'application/x-bittorrent;x-scheme-handler/magnet' ]
271 }
272 }
273
274 const ACTIVITY_PUB_ACTOR_TYPES: { [ id: string ]: ActivityPubActorType } = {
275 GROUP: 'Group',
276 PERSON: 'Person',
277 APPLICATION: 'Application'
278 }
279
280 // ---------------------------------------------------------------------------
281
282 const PRIVATE_RSA_KEY_SIZE = 2048
283
284 // Password encryption
285 const BCRYPT_SALT_SIZE = 10
286
287 // ---------------------------------------------------------------------------
288
289 // Express static paths (router)
290 const STATIC_PATHS = {
291 PREVIEWS: '/static/previews/',
292 THUMBNAILS: '/static/thumbnails/',
293 TORRENTS: '/static/torrents/',
294 WEBSEED: '/static/webseed/'
295 }
296
297 // Cache control
298 let STATIC_MAX_AGE = '30d'
299
300 // Videos thumbnail size
301 const THUMBNAILS_SIZE = {
302 width: 200,
303 height: 110
304 }
305 const PREVIEWS_SIZE = {
306 width: 560,
307 height: 315
308 }
309
310 const EMBED_SIZE = {
311 width: 560,
312 height: 315
313 }
314
315 // Sub folders of cache directory
316 const CACHE = {
317 DIRECTORIES: {
318 PREVIEWS: join(CONFIG.STORAGE.CACHE_DIR, 'previews')
319 }
320 }
321
322 const ACCEPT_HEADERS = [ 'html', 'application/json' ].concat(ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS)
323
324 // ---------------------------------------------------------------------------
325
326 const OPENGRAPH_AND_OEMBED_COMMENT = '<!-- open graph and oembed tags -->'
327
328 // ---------------------------------------------------------------------------
329
330 // Special constants for a test instance
331 if (isTestInstance() === true) {
332 SERVERS_SCORE.BASE = 20
333 JOBS_FETCHING_INTERVAL = 1000
334 REMOTE_SCHEME.HTTP = 'http'
335 REMOTE_SCHEME.WS = 'ws'
336 STATIC_MAX_AGE = '0'
337 ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE = 2
338 }
339
340 CONFIG.WEBSERVER.URL = sanitizeUrl(CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT)
341 CONFIG.WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT, REMOTE_SCHEME.HTTP)
342
343 // ---------------------------------------------------------------------------
344
345 export {
346 API_VERSION,
347 ACCEPT_HEADERS,
348 BCRYPT_SALT_SIZE,
349 CACHE,
350 CONFIG,
351 CONSTRAINTS_FIELDS,
352 EMBED_SIZE,
353 JOB_STATES,
354 JOBS_FETCH_LIMIT_PER_CYCLE,
355 JOBS_FETCHING_INTERVAL,
356 JOB_CATEGORIES,
357 LAST_MIGRATION_VERSION,
358 OAUTH_LIFETIME,
359 OPENGRAPH_AND_OEMBED_COMMENT,
360 PAGINATION_COUNT_DEFAULT,
361 SERVERS_SCORE,
362 PREVIEWS_SIZE,
363 REMOTE_SCHEME,
364 FOLLOW_STATES,
365 AVATARS_DIR,
366 SERVER_ACTOR_NAME,
367 PRIVATE_RSA_KEY_SIZE,
368 SORTABLE_COLUMNS,
369 STATIC_MAX_AGE,
370 STATIC_PATHS,
371 ACTIVITY_PUB,
372 ACTIVITY_PUB_ACTOR_TYPES,
373 THUMBNAILS_SIZE,
374 VIDEO_CATEGORIES,
375 VIDEO_LANGUAGES,
376 VIDEO_PRIVACIES,
377 VIDEO_LICENCES,
378 VIDEO_RATE_TYPES,
379 VIDEO_MIMETYPE_EXT
380 }