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'
10 // ---------------------------------------------------------------------------
12 const LAST_MIGRATION_VERSION = 155
14 // ---------------------------------------------------------------------------
17 const API_VERSION = 'v1'
19 // Number of results by default for the pagination
20 const PAGINATION_COUNT_DEFAULT = 15
22 // Sortable columns per schema
23 const SORTABLE_COLUMNS = {
24 USERS: [ 'id', 'username', 'createdAt' ],
25 ACCOUNTS: [ 'createdAt' ],
26 JOBS: [ 'id', 'createdAt' ],
27 VIDEO_ABUSES: [ 'id', 'createdAt' ],
28 VIDEO_CHANNELS: [ 'id', 'name', 'updatedAt', 'createdAt' ],
29 VIDEOS: [ 'name', 'duration', 'createdAt', 'views', 'likes' ],
30 VIDEO_COMMENT_THREADS: [ 'createdAt' ],
31 BLACKLISTS: [ 'id', 'name', 'duration', 'views', 'likes', 'dislikes', 'uuid', 'createdAt' ],
32 FOLLOWERS: [ 'createdAt' ],
33 FOLLOWING: [ 'createdAt' ]
36 const OAUTH_LIFETIME = {
37 ACCESS_TOKEN: 3600 * 4, // 4 hours
38 REFRESH_TOKEN: 1209600 // 2 weeks
41 // ---------------------------------------------------------------------------
43 // Number of points we add/remove from a friend after a successful/bad request
44 const SERVERS_SCORE = {
51 const FOLLOW_STATES: { [ id: string ]: FollowState } = {
56 const REMOTE_SCHEME = {
61 const JOB_STATES: { [ id: string ]: JobState } = {
63 PROCESSING: 'processing',
67 const JOB_CATEGORIES: { [ id: string ]: JobCategory } = {
68 TRANSCODING: 'transcoding',
69 ACTIVITYPUB_HTTP: 'activitypub-http'
71 // How many maximum jobs we fetch from the database per cycle
72 const JOBS_FETCH_LIMIT_PER_CYCLE = {
77 let JOBS_FETCHING_INTERVAL = 60000
79 // ---------------------------------------------------------------------------
83 PORT: config.get<number>('listen.port')
86 DBNAME: 'peertube' + config.get<string>('database.suffix'),
87 HOSTNAME: config.get<string>('database.hostname'),
88 PORT: config.get<number>('database.port'),
89 USERNAME: config.get<string>('database.username'),
90 PASSWORD: config.get<string>('database.password')
93 AVATARS_DIR: join(root(), config.get<string>('storage.avatars')),
94 LOG_DIR: join(root(), config.get<string>('storage.logs')),
95 VIDEOS_DIR: join(root(), config.get<string>('storage.videos')),
96 THUMBNAILS_DIR: join(root(), config.get<string>('storage.thumbnails')),
97 PREVIEWS_DIR: join(root(), config.get<string>('storage.previews')),
98 TORRENTS_DIR: join(root(), config.get<string>('storage.torrents')),
99 CACHE_DIR: join(root(), config.get<string>('storage.cache'))
102 SCHEME: config.get<boolean>('webserver.https') === true ? 'https' : 'http',
103 WS: config.get<boolean>('webserver.https') === true ? 'wss' : 'ws',
104 HOSTNAME: config.get<string>('webserver.hostname'),
105 PORT: config.get<number>('webserver.port'),
110 EMAIL: config.get<string>('admin.email')
113 ENABLED: config.get<boolean>('signup.enabled'),
114 LIMIT: config.get<number>('signup.limit')
117 VIDEO_QUOTA: config.get<number>('user.video_quota')
120 ENABLED: config.get<boolean>('transcoding.enabled'),
121 THREADS: config.get<number>('transcoding.threads'),
123 '240' : config.get<boolean>('transcoding.resolutions.240p'),
124 '360': config.get<boolean>('transcoding.resolutions.360p'),
125 '480': config.get<boolean>('transcoding.resolutions.480p'),
126 '720': config.get<boolean>('transcoding.resolutions.720p'),
127 '1080': config.get<boolean>('transcoding.resolutions.1080p')
132 SIZE: config.get<number>('cache.previews.size')
137 // ---------------------------------------------------------------------------
139 const CONSTRAINTS_FIELDS = {
141 USERNAME: { min: 3, max: 20 }, // Length
142 PASSWORD: { min: 6, max: 255 }, // Length
143 VIDEO_QUOTA: { min: -1 }
146 REASON: { min: 2, max: 300 } // Length
149 NAME: { min: 3, max: 120 }, // Length
150 DESCRIPTION: { min: 3, max: 250 }, // Length
151 URL: { min: 3, max: 2000 } // Length
154 NAME: { min: 3, max: 120 }, // Length
155 TRUNCATED_DESCRIPTION: { min: 3, max: 250 }, // Length
156 DESCRIPTION: { min: 3, max: 3000 }, // Length
157 EXTNAME: [ '.mp4', '.ogv', '.webm' ],
158 INFO_HASH: { min: 40, max: 40 }, // Length, info hash is 20 bytes length but we represent it in hexadecimal so 20 * 2
159 DURATION: { min: 1 }, // Number
160 TAGS: { min: 0, max: 5 }, // Number of total tags
161 TAG: { min: 2, max: 30 }, // Length
162 THUMBNAIL: { min: 2, max: 30 },
163 THUMBNAIL_DATA: { min: 0, max: 20000 }, // Bytes
166 DISLIKES: { min: 0 },
167 FILE_SIZE: { min: 10 },
168 URL: { min: 3, max: 2000 } // Length
171 PUBLIC_KEY: { min: 10, max: 5000 }, // Length
172 PRIVATE_KEY: { min: 10, max: 5000 }, // Length
173 URL: { min: 3, max: 2000 }, // Length
175 EXTNAME: [ '.png', '.jpeg', '.jpg' ],
177 max: 2 * 1024 * 1024 // 2MB
185 TEXT: { min: 2, max: 3000 }, // Length
186 URL: { min: 3, max: 2000 } // Length
190 const VIDEO_RATE_TYPES: { [ id: string ]: VideoRateType } = {
195 const VIDEO_CATEGORIES = {
210 15: 'Science & Technology',
216 // See https://creativecommons.org/licenses/?lang=en
217 const VIDEO_LICENCES = {
219 2: 'Attribution - Share Alike',
220 3: 'Attribution - No Derivatives',
221 4: 'Attribution - Non Commercial',
222 5: 'Attribution - Non Commercial - Share Alike',
223 6: 'Attribution - Non Commercial - No Derivatives',
224 7: 'Public Domain Dedication'
227 // See https://en.wikipedia.org/wiki/List_of_languages_by_number_of_native_speakers#Nationalencyklopedin
228 const VIDEO_LANGUAGES = {
245 const VIDEO_PRIVACIES = {
246 [VideoPrivacy.PUBLIC]: 'Public',
247 [VideoPrivacy.UNLISTED]: 'Unlisted',
248 [VideoPrivacy.PRIVATE]: 'Private'
251 const VIDEO_MIMETYPE_EXT = {
252 'video/webm': '.webm',
257 const AVATAR_MIMETYPE_EXT = {
263 // ---------------------------------------------------------------------------
265 const SERVER_ACTOR_NAME = 'peertube'
267 const ACTIVITY_PUB = {
268 POTENTIAL_ACCEPT_HEADERS: [
269 'application/activity+json',
270 'application/ld+json'
272 ACCEPT_HEADER: 'application/activity+json, application/ld+json',
273 PUBLIC: 'https://www.w3.org/ns/activitystreams#Public',
274 COLLECTION_ITEMS_PER_PAGE: 10,
275 FETCH_PAGE_LIMIT: 100,
278 VIDEO: [ 'video/mp4', 'video/webm', 'video/ogg' ], // TODO: Merge with VIDEO_MIMETYPE_EXT
279 TORRENT: [ 'application/x-bittorrent' ],
280 MAGNET: [ 'application/x-bittorrent;x-scheme-handler/magnet' ]
282 ACTOR_REFRESH_INTERVAL: 3600 * 24 // 1 day
285 const ACTIVITY_PUB_ACTOR_TYPES: { [ id: string ]: ActivityPubActorType } = {
288 APPLICATION: 'Application'
291 // ---------------------------------------------------------------------------
293 const PRIVATE_RSA_KEY_SIZE = 2048
295 // Password encryption
296 const BCRYPT_SALT_SIZE = 10
298 // ---------------------------------------------------------------------------
300 // Express static paths (router)
301 const STATIC_PATHS = {
302 PREVIEWS: '/static/previews/',
303 THUMBNAILS: '/static/thumbnails/',
304 TORRENTS: '/static/torrents/',
305 WEBSEED: '/static/webseed/',
306 AVATARS: '/static/avatars/'
310 let STATIC_MAX_AGE = '30d'
312 // Videos thumbnail size
313 const THUMBNAILS_SIZE = {
317 const PREVIEWS_SIZE = {
321 const AVATARS_SIZE = {
331 // Sub folders of cache directory
334 PREVIEWS: join(CONFIG.STORAGE.CACHE_DIR, 'previews')
338 const ACCEPT_HEADERS = [ 'html', 'application/json' ].concat(ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS)
340 // ---------------------------------------------------------------------------
342 const OPENGRAPH_AND_OEMBED_COMMENT = '<!-- open graph and oembed tags -->'
344 // ---------------------------------------------------------------------------
346 // Special constants for a test instance
347 if (isTestInstance() === true) {
348 SERVERS_SCORE.BASE = 20
349 JOBS_FETCHING_INTERVAL = 1000
350 REMOTE_SCHEME.HTTP = 'http'
351 REMOTE_SCHEME.WS = 'ws'
353 ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE = 2
354 ACTIVITY_PUB.ACTOR_REFRESH_INTERVAL = 60 // 1 minute
355 CONSTRAINTS_FIELDS.ACTORS.AVATAR.FILE_SIZE.max = 100 * 1024 // 100KB
358 CONFIG.WEBSERVER.URL = sanitizeUrl(CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT)
359 CONFIG.WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT, REMOTE_SCHEME.HTTP)
361 // ---------------------------------------------------------------------------
373 JOBS_FETCH_LIMIT_PER_CYCLE,
374 JOBS_FETCHING_INTERVAL,
376 LAST_MIGRATION_VERSION,
378 OPENGRAPH_AND_OEMBED_COMMENT,
379 PAGINATION_COUNT_DEFAULT,
385 PRIVATE_RSA_KEY_SIZE,
390 ACTIVITY_PUB_ACTOR_TYPES,