1 import * as config from 'config'
2 import { join } from 'path'
4 // Do not use barrels, remain constants as independent as possible
5 import { root, isTestInstance } from '../helpers/core-utils'
10 RequestVideoEventType,
12 RemoteVideoRequestType,
15 } from '../../shared/models'
16 import { VideoPrivacy } from '../../shared/models/videos/video-privacy.enum'
17 import { FollowState } from '../../shared/models/accounts/follow.model'
19 // ---------------------------------------------------------------------------
21 const LAST_MIGRATION_VERSION = 95
23 // ---------------------------------------------------------------------------
26 const API_VERSION = 'v1'
28 // Number of results by default for the pagination
29 const PAGINATION_COUNT_DEFAULT = 15
31 // Sortable columns per schema
32 const SEARCHABLE_COLUMNS = {
33 VIDEOS: [ 'name', 'magnetUri', 'host', 'account', 'tags' ]
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' ]
47 const OAUTH_LIFETIME = {
48 ACCESS_TOKEN: 3600 * 4, // 4 hours
49 REFRESH_TOKEN: 1209600 // 2 weeks
52 // ---------------------------------------------------------------------------
56 PORT: config.get<number>('listen.port')
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')
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'))
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'),
82 EMAIL: config.get<string>('admin.email')
85 ENABLED: config.get<boolean>('signup.enabled'),
86 LIMIT: config.get<number>('signup.limit')
89 VIDEO_QUOTA: config.get<number>('user.video_quota')
92 ENABLED: config.get<boolean>('transcoding.enabled'),
93 THREADS: config.get<number>('transcoding.threads'),
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')
104 SIZE: config.get<number>('cache.previews.size')
108 CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
109 CONFIG.WEBSERVER.HOST = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
111 // ---------------------------------------------------------------------------
113 const CONSTRAINTS_FIELDS = {
115 USERNAME: { min: 3, max: 20 }, // Length
116 PASSWORD: { min: 6, max: 255 }, // Length
117 VIDEO_QUOTA: { min: -1 }
120 REASON: { min: 2, max: 300 } // Length
123 NAME: { min: 3, max: 120 }, // Length
124 DESCRIPTION: { min: 3, max: 250 } // Length
127 NAME: { min: 3, max: 120 }, // Length
128 TRUNCATED_DESCRIPTION: { min: 3, max: 250 }, // Length
129 DESCRIPTION: { min: 3, max: 3000 }, // Length
130 EXTNAME: [ '.mp4', '.ogv', '.webm' ],
131 INFO_HASH: { min: 40, max: 40 }, // Length, info hash is 20 bytes length but we represent it in hexadecimal so 20 * 2
132 DURATION: { min: 1, max: 7200 }, // Number
133 TAGS: { min: 0, max: 5 }, // Number of total tags
134 TAG: { min: 2, max: 30 }, // Length
135 THUMBNAIL: { min: 2, max: 30 },
136 THUMBNAIL_DATA: { min: 0, max: 20000 }, // Bytes
139 DISLIKES: { min: 0 },
140 FILE_SIZE: { min: 10, max: 1024 * 1024 * 1024 * 3 /* 3Go */ }
147 const VIDEO_RATE_TYPES: { [ id: string ]: VideoRateType } = {
152 const VIDEO_CATEGORIES = {
167 15: 'Science & Technology',
173 // See https://creativecommons.org/licenses/?lang=en
174 const VIDEO_LICENCES = {
176 2: 'Attribution - Share Alike',
177 3: 'Attribution - No Derivatives',
178 4: 'Attribution - Non Commercial',
179 5: 'Attribution - Non Commercial - Share Alike',
180 6: 'Attribution - Non Commercial - No Derivatives',
181 7: 'Public Domain Dedication'
184 // See https://en.wikipedia.org/wiki/List_of_languages_by_number_of_native_speakers#Nationalencyklopedin
185 const VIDEO_LANGUAGES = {
202 const VIDEO_PRIVACIES = {
203 [VideoPrivacy.PUBLIC]: 'Public',
204 [VideoPrivacy.UNLISTED]: 'Unlisted',
205 [VideoPrivacy.PRIVATE]: 'Private'
208 const VIDEO_MIMETYPE_EXT = {
209 'video/webm': 'webm',
214 // ---------------------------------------------------------------------------
216 // Score a pod has when we create it as a friend
217 const FRIEND_SCORE = {
222 const ACTIVITY_PUB = {
223 COLLECTION_ITEMS_PER_PAGE: 10,
224 VIDEO_URL_MIME_TYPES: [
228 'application/x-bittorrent',
229 'application/x-bittorrent;x-scheme-handler/magnet'
233 // ---------------------------------------------------------------------------
235 // Number of points we add/remove from a friend after a successful/bad request
241 const FOLLOW_STATES: { [ id: string ]: FollowState } = {
246 const REMOTE_SCHEME = {
251 const JOB_STATES: { [ id: string ]: JobState } = {
253 PROCESSING: 'processing',
257 const JOB_CATEGORIES: { [ id: string ]: JobCategory } = {
258 TRANSCODING: 'transcoding',
259 HTTP_REQUEST: 'http-request'
261 // How many maximum jobs we fetch from the database per cycle
262 const JOBS_FETCH_LIMIT_PER_CYCLE = {
267 let JOBS_FETCHING_INTERVAL = 60000
269 // ---------------------------------------------------------------------------
271 const PRIVATE_RSA_KEY_SIZE = 2048
273 // Password encryption
274 const BCRYPT_SALT_SIZE = 10
276 // ---------------------------------------------------------------------------
278 // Express static paths (router)
279 const STATIC_PATHS = {
280 PREVIEWS: '/static/previews/',
281 THUMBNAILS: '/static/thumbnails/',
282 TORRENTS: '/static/torrents/',
283 WEBSEED: '/static/webseed/'
287 let STATIC_MAX_AGE = '30d'
289 // Videos thumbnail size
290 const THUMBNAILS_SIZE = {
294 const PREVIEWS_SIZE = {
304 // Sub folders of cache directory
307 PREVIEWS: join(CONFIG.STORAGE.CACHE_DIR, 'previews')
311 // ---------------------------------------------------------------------------
313 const OPENGRAPH_AND_OEMBED_COMMENT = '<!-- open graph and oembed tags -->'
315 // ---------------------------------------------------------------------------
317 // Special constants for a test instance
318 if (isTestInstance() === true) {
319 CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14
320 FRIEND_SCORE.BASE = 20
321 JOBS_FETCHING_INTERVAL = 10000
322 REMOTE_SCHEME.HTTP = 'http'
323 REMOTE_SCHEME.WS = 'ws'
327 // ---------------------------------------------------------------------------
338 JOBS_FETCH_LIMIT_PER_CYCLE,
339 JOBS_FETCHING_INTERVAL,
341 LAST_MIGRATION_VERSION,
343 OPENGRAPH_AND_OEMBED_COMMENT,
344 PAGINATION_COUNT_DEFAULT,
350 PRIVATE_RSA_KEY_SIZE,