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