]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/initializers/constants.ts
Fetch outbox to grab old activities tests
[github/Chocobozzz/PeerTube.git] / server / initializers / constants.ts
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 = 95
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 SEARCHABLE_COLUMNS = {
29 VIDEOS: [ 'name', 'magnetUri', 'host', 'account', 'tags' ]
30 }
31
32 // Sortable columns per schema
33 const SORTABLE_COLUMNS = {
34 USERS: [ 'id', 'username', 'createdAt' ],
35 VIDEO_ABUSES: [ 'id', 'createdAt' ],
36 VIDEO_CHANNELS: [ 'id', 'name', 'updatedAt', 'createdAt' ],
37 VIDEOS: [ 'name', 'duration', 'createdAt', 'views', 'likes' ],
38 BLACKLISTS: [ 'id', 'name', 'duration', 'views', 'likes', 'dislikes', 'uuid', 'createdAt' ],
39 FOLLOWERS: [ 'createdAt' ],
40 FOLLOWING: [ 'createdAt' ]
41 }
42
43 const OAUTH_LIFETIME = {
44 ACCESS_TOKEN: 3600 * 4, // 4 hours
45 REFRESH_TOKEN: 1209600 // 2 weeks
46 }
47
48 // ---------------------------------------------------------------------------
49
50 const CONFIG = {
51 LISTEN: {
52 PORT: config.get<number>('listen.port')
53 },
54 DATABASE: {
55 DBNAME: 'peertube' + config.get<string>('database.suffix'),
56 HOSTNAME: config.get<string>('database.hostname'),
57 PORT: config.get<number>('database.port'),
58 USERNAME: config.get<string>('database.username'),
59 PASSWORD: config.get<string>('database.password')
60 },
61 STORAGE: {
62 LOG_DIR: join(root(), config.get<string>('storage.logs')),
63 VIDEOS_DIR: join(root(), config.get<string>('storage.videos')),
64 THUMBNAILS_DIR: join(root(), config.get<string>('storage.thumbnails')),
65 PREVIEWS_DIR: join(root(), config.get<string>('storage.previews')),
66 TORRENTS_DIR: join(root(), config.get<string>('storage.torrents')),
67 CACHE_DIR: join(root(), config.get<string>('storage.cache'))
68 },
69 WEBSERVER: {
70 SCHEME: config.get<boolean>('webserver.https') === true ? 'https' : 'http',
71 WS: config.get<boolean>('webserver.https') === true ? 'wss' : 'ws',
72 HOSTNAME: config.get<string>('webserver.hostname'),
73 PORT: config.get<number>('webserver.port'),
74 URL: '',
75 HOST: ''
76 },
77 ADMIN: {
78 EMAIL: config.get<string>('admin.email')
79 },
80 SIGNUP: {
81 ENABLED: config.get<boolean>('signup.enabled'),
82 LIMIT: config.get<number>('signup.limit')
83 },
84 USER: {
85 VIDEO_QUOTA: config.get<number>('user.video_quota')
86 },
87 TRANSCODING: {
88 ENABLED: config.get<boolean>('transcoding.enabled'),
89 THREADS: config.get<number>('transcoding.threads'),
90 RESOLUTIONS: {
91 '240' : config.get<boolean>('transcoding.resolutions.240p'),
92 '360': config.get<boolean>('transcoding.resolutions.360p'),
93 '480': config.get<boolean>('transcoding.resolutions.480p'),
94 '720': config.get<boolean>('transcoding.resolutions.720p'),
95 '1080': config.get<boolean>('transcoding.resolutions.1080p')
96 }
97 },
98 CACHE: {
99 PREVIEWS: {
100 SIZE: config.get<number>('cache.previews.size')
101 }
102 }
103 }
104 CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
105 CONFIG.WEBSERVER.HOST = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
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, max: 7200 }, // 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, max: 1024 * 1024 * 1024 * 10 /* 10Go */ },
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 // Score a server has when we create it as a friend
220 const FRIEND_SCORE = {
221 BASE: 100,
222 MAX: 1000
223 }
224
225 const SERVER_ACCOUNT_NAME = 'peertube'
226
227 const ACTIVITY_PUB = {
228 ACCEPT_HEADER: 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
229 PUBLIC: 'https://www.w3.org/ns/activitystreams#Public',
230 COLLECTION_ITEMS_PER_PAGE: 10,
231 FETCH_PAGE_LIMIT: 100,
232 URL_MIME_TYPES: {
233 VIDEO: [ 'video/mp4', 'video/webm', 'video/ogg' ], // TODO: Merge with VIDEO_MIMETYPE_EXT
234 TORRENT: [ 'application/x-bittorrent' ],
235 MAGNET: [ 'application/x-bittorrent;x-scheme-handler/magnet' ]
236 }
237 }
238
239 // ---------------------------------------------------------------------------
240
241 // Number of points we add/remove from a friend after a successful/bad request
242 const SERVERS_SCORE = {
243 PENALTY: -10,
244 BONUS: 10
245 }
246
247 const FOLLOW_STATES: { [ id: string ]: FollowState } = {
248 PENDING: 'pending',
249 ACCEPTED: 'accepted'
250 }
251
252 const REMOTE_SCHEME = {
253 HTTP: 'https',
254 WS: 'wss'
255 }
256
257 const JOB_STATES: { [ id: string ]: JobState } = {
258 PENDING: 'pending',
259 PROCESSING: 'processing',
260 ERROR: 'error',
261 SUCCESS: 'success'
262 }
263 const JOB_CATEGORIES: { [ id: string ]: JobCategory } = {
264 TRANSCODING: 'transcoding',
265 ACTIVITYPUB_HTTP: 'activitypub-http'
266 }
267 // How many maximum jobs we fetch from the database per cycle
268 const JOBS_FETCH_LIMIT_PER_CYCLE = {
269 transcoding: 10,
270 httpRequest: 20
271 }
272 // 1 minutes
273 let JOBS_FETCHING_INTERVAL = 60000
274
275 // ---------------------------------------------------------------------------
276
277 const PRIVATE_RSA_KEY_SIZE = 2048
278
279 // Password encryption
280 const BCRYPT_SALT_SIZE = 10
281
282 // ---------------------------------------------------------------------------
283
284 // Express static paths (router)
285 const STATIC_PATHS = {
286 PREVIEWS: '/static/previews/',
287 THUMBNAILS: '/static/thumbnails/',
288 TORRENTS: '/static/torrents/',
289 WEBSEED: '/static/webseed/'
290 }
291
292 // Cache control
293 let STATIC_MAX_AGE = '30d'
294
295 // Videos thumbnail size
296 const THUMBNAILS_SIZE = {
297 width: 200,
298 height: 110
299 }
300 const PREVIEWS_SIZE = {
301 width: 560,
302 height: 315
303 }
304
305 const EMBED_SIZE = {
306 width: 560,
307 height: 315
308 }
309
310 // Sub folders of cache directory
311 const CACHE = {
312 DIRECTORIES: {
313 PREVIEWS: join(CONFIG.STORAGE.CACHE_DIR, 'previews')
314 }
315 }
316
317 // ---------------------------------------------------------------------------
318
319 const OPENGRAPH_AND_OEMBED_COMMENT = '<!-- open graph and oembed tags -->'
320
321 // ---------------------------------------------------------------------------
322
323 // Special constants for a test instance
324 if (isTestInstance() === true) {
325 CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14
326 FRIEND_SCORE.BASE = 20
327 JOBS_FETCHING_INTERVAL = 1000
328 REMOTE_SCHEME.HTTP = 'http'
329 REMOTE_SCHEME.WS = 'ws'
330 STATIC_MAX_AGE = '0'
331 ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE = 2
332 }
333
334 // ---------------------------------------------------------------------------
335
336 export {
337 API_VERSION,
338 BCRYPT_SALT_SIZE,
339 CACHE,
340 CONFIG,
341 CONSTRAINTS_FIELDS,
342 EMBED_SIZE,
343 FRIEND_SCORE,
344 JOB_STATES,
345 JOBS_FETCH_LIMIT_PER_CYCLE,
346 JOBS_FETCHING_INTERVAL,
347 JOB_CATEGORIES,
348 LAST_MIGRATION_VERSION,
349 OAUTH_LIFETIME,
350 OPENGRAPH_AND_OEMBED_COMMENT,
351 PAGINATION_COUNT_DEFAULT,
352 SERVERS_SCORE,
353 PREVIEWS_SIZE,
354 REMOTE_SCHEME,
355 FOLLOW_STATES,
356 SEARCHABLE_COLUMNS,
357 SERVER_ACCOUNT_NAME,
358 PRIVATE_RSA_KEY_SIZE,
359 SORTABLE_COLUMNS,
360 STATIC_MAX_AGE,
361 STATIC_PATHS,
362 ACTIVITY_PUB,
363 THUMBNAILS_SIZE,
364 VIDEO_CATEGORIES,
365 VIDEO_LANGUAGES,
366 VIDEO_PRIVACIES,
367 VIDEO_LICENCES,
368 VIDEO_RATE_TYPES,
369 VIDEO_MIMETYPE_EXT
370 }