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 = 140
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 JOBS: [ 'id', 'createdAt' ],
26 VIDEO_ABUSES: [ 'id', 'createdAt' ],
27 VIDEO_CHANNELS: [ 'id', 'name', 'updatedAt', 'createdAt' ],
28 VIDEOS: [ 'name', 'duration', 'createdAt', 'views', 'likes' ],
29 BLACKLISTS: [ 'id', 'name', 'duration', 'views', 'likes', 'dislikes', 'uuid', 'createdAt' ],
30 FOLLOWERS: [ 'createdAt' ],
31 FOLLOWING: [ 'createdAt' ]
34 const OAUTH_LIFETIME = {
35 ACCESS_TOKEN: 3600 * 4, // 4 hours
36 REFRESH_TOKEN: 1209600 // 2 weeks
39 // ---------------------------------------------------------------------------
41 // Number of points we add/remove from a friend after a successful/bad request
42 const SERVERS_SCORE = {
49 const FOLLOW_STATES: { [ id: string ]: FollowState } = {
54 const REMOTE_SCHEME = {
59 const JOB_STATES: { [ id: string ]: JobState } = {
61 PROCESSING: 'processing',
65 const JOB_CATEGORIES: { [ id: string ]: JobCategory } = {
66 TRANSCODING: 'transcoding',
67 ACTIVITYPUB_HTTP: 'activitypub-http'
69 // How many maximum jobs we fetch from the database per cycle
70 const JOBS_FETCH_LIMIT_PER_CYCLE = {
75 let JOBS_FETCHING_INTERVAL = 60000
77 // ---------------------------------------------------------------------------
81 PORT: config.get<number>('listen.port')
84 DBNAME: 'peertube' + config.get<string>('database.suffix'),
85 HOSTNAME: config.get<string>('database.hostname'),
86 PORT: config.get<number>('database.port'),
87 USERNAME: config.get<string>('database.username'),
88 PASSWORD: config.get<string>('database.password')
91 AVATARS_DIR: join(root(), config.get<string>('storage.avatars')),
92 LOG_DIR: join(root(), config.get<string>('storage.logs')),
93 VIDEOS_DIR: join(root(), config.get<string>('storage.videos')),
94 THUMBNAILS_DIR: join(root(), config.get<string>('storage.thumbnails')),
95 PREVIEWS_DIR: join(root(), config.get<string>('storage.previews')),
96 TORRENTS_DIR: join(root(), config.get<string>('storage.torrents')),
97 CACHE_DIR: join(root(), config.get<string>('storage.cache'))
100 SCHEME: config.get<boolean>('webserver.https') === true ? 'https' : 'http',
101 WS: config.get<boolean>('webserver.https') === true ? 'wss' : 'ws',
102 HOSTNAME: config.get<string>('webserver.hostname'),
103 PORT: config.get<number>('webserver.port'),
108 EMAIL: config.get<string>('admin.email')
111 ENABLED: config.get<boolean>('signup.enabled'),
112 LIMIT: config.get<number>('signup.limit')
115 VIDEO_QUOTA: config.get<number>('user.video_quota')
118 ENABLED: config.get<boolean>('transcoding.enabled'),
119 THREADS: config.get<number>('transcoding.threads'),
121 '240' : config.get<boolean>('transcoding.resolutions.240p'),
122 '360': config.get<boolean>('transcoding.resolutions.360p'),
123 '480': config.get<boolean>('transcoding.resolutions.480p'),
124 '720': config.get<boolean>('transcoding.resolutions.720p'),
125 '1080': config.get<boolean>('transcoding.resolutions.1080p')
130 SIZE: config.get<number>('cache.previews.size')
135 const AVATARS_DIR = {
136 ACCOUNT: join(CONFIG.STORAGE.AVATARS_DIR, 'account')
138 // ---------------------------------------------------------------------------
140 const CONSTRAINTS_FIELDS = {
142 USERNAME: { min: 3, max: 20 }, // Length
143 PASSWORD: { min: 6, max: 255 }, // Length
144 VIDEO_QUOTA: { min: -1 }
147 REASON: { min: 2, max: 300 } // Length
150 NAME: { min: 3, max: 120 }, // Length
151 DESCRIPTION: { min: 3, max: 250 }, // Length
152 URL: { min: 3, max: 2000 } // Length
155 NAME: { min: 3, max: 120 }, // Length
156 TRUNCATED_DESCRIPTION: { min: 3, max: 250 }, // Length
157 DESCRIPTION: { min: 3, max: 3000 }, // Length
158 EXTNAME: [ '.mp4', '.ogv', '.webm' ],
159 INFO_HASH: { min: 40, max: 40 }, // Length, info hash is 20 bytes length but we represent it in hexadecimal so 20 * 2
160 DURATION: { min: 1 }, // Number
161 TAGS: { min: 0, max: 5 }, // Number of total tags
162 TAG: { min: 2, max: 30 }, // Length
163 THUMBNAIL: { min: 2, max: 30 },
164 THUMBNAIL_DATA: { min: 0, max: 20000 }, // Bytes
167 DISLIKES: { min: 0 },
168 FILE_SIZE: { min: 10 },
169 URL: { min: 3, max: 2000 } // Length
172 PUBLIC_KEY: { min: 10, max: 5000 }, // Length
173 PRIVATE_KEY: { min: 10, max: 5000 }, // Length
174 URL: { min: 3, max: 2000 } // Length
181 const VIDEO_RATE_TYPES: { [ id: string ]: VideoRateType } = {
186 const VIDEO_CATEGORIES = {
201 15: 'Science & Technology',
207 // See https://creativecommons.org/licenses/?lang=en
208 const VIDEO_LICENCES = {
210 2: 'Attribution - Share Alike',
211 3: 'Attribution - No Derivatives',
212 4: 'Attribution - Non Commercial',
213 5: 'Attribution - Non Commercial - Share Alike',
214 6: 'Attribution - Non Commercial - No Derivatives',
215 7: 'Public Domain Dedication'
218 // See https://en.wikipedia.org/wiki/List_of_languages_by_number_of_native_speakers#Nationalencyklopedin
219 const VIDEO_LANGUAGES = {
236 const VIDEO_PRIVACIES = {
237 [VideoPrivacy.PUBLIC]: 'Public',
238 [VideoPrivacy.UNLISTED]: 'Unlisted',
239 [VideoPrivacy.PRIVATE]: 'Private'
242 const VIDEO_MIMETYPE_EXT = {
243 'video/webm': '.webm',
248 // ---------------------------------------------------------------------------
250 const SERVER_ACTOR_NAME = 'peertube'
252 const ACTIVITY_PUB = {
253 POTENTIAL_ACCEPT_HEADERS: [
254 'application/activity+json',
255 'application/ld+json'
257 ACCEPT_HEADER: 'application/activity+json, application/ld+json',
258 PUBLIC: 'https://www.w3.org/ns/activitystreams#Public',
259 COLLECTION_ITEMS_PER_PAGE: 10,
260 FETCH_PAGE_LIMIT: 100,
263 VIDEO: [ 'video/mp4', 'video/webm', 'video/ogg' ], // TODO: Merge with VIDEO_MIMETYPE_EXT
264 TORRENT: [ 'application/x-bittorrent' ],
265 MAGNET: [ 'application/x-bittorrent;x-scheme-handler/magnet' ]
269 const ACTIVITY_PUB_ACTOR_TYPES: { [ id: string ]: ActivityPubActorType } = {
272 APPLICATION: 'Application'
275 // ---------------------------------------------------------------------------
277 const PRIVATE_RSA_KEY_SIZE = 2048
279 // Password encryption
280 const BCRYPT_SALT_SIZE = 10
282 // ---------------------------------------------------------------------------
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/'
293 let STATIC_MAX_AGE = '30d'
295 // Videos thumbnail size
296 const THUMBNAILS_SIZE = {
300 const PREVIEWS_SIZE = {
310 // Sub folders of cache directory
313 PREVIEWS: join(CONFIG.STORAGE.CACHE_DIR, 'previews')
317 const ACCEPT_HEADERS = [ 'html', 'application/json' ].concat(ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS)
319 // ---------------------------------------------------------------------------
321 const OPENGRAPH_AND_OEMBED_COMMENT = '<!-- open graph and oembed tags -->'
323 // ---------------------------------------------------------------------------
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'
332 ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE = 2
335 CONFIG.WEBSERVER.URL = sanitizeUrl(CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT)
336 CONFIG.WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT, REMOTE_SCHEME.HTTP)
338 // ---------------------------------------------------------------------------
349 JOBS_FETCH_LIMIT_PER_CYCLE,
350 JOBS_FETCHING_INTERVAL,
352 LAST_MIGRATION_VERSION,
354 OPENGRAPH_AND_OEMBED_COMMENT,
355 PAGINATION_COUNT_DEFAULT,
362 PRIVATE_RSA_KEY_SIZE,
367 ACTIVITY_PUB_ACTOR_TYPES,