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