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
125 URL: { min: 3, max: 2000 } // Length
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
140 DISLIKES: { min: 0 },
141 FILE_SIZE: { min: 10, max: 1024 * 1024 * 1024 * 3 /* 3Go */ },
142 URL: { min: 3, max: 2000 } // Length
145 PUBLIC_KEY: { min: 10, max: 5000 }, // Length
146 PRIVATE_KEY: { min: 10, max: 5000 }, // Length
147 URL: { min: 3, max: 2000 } // Length
154 const VIDEO_RATE_TYPES: { [ id: string ]: VideoRateType } = {
159 const VIDEO_CATEGORIES = {
174 15: 'Science & Technology',
180 // See https://creativecommons.org/licenses/?lang=en
181 const VIDEO_LICENCES = {
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'
191 // See https://en.wikipedia.org/wiki/List_of_languages_by_number_of_native_speakers#Nationalencyklopedin
192 const VIDEO_LANGUAGES = {
209 const VIDEO_PRIVACIES = {
210 [VideoPrivacy.PUBLIC]: 'Public',
211 [VideoPrivacy.UNLISTED]: 'Unlisted',
212 [VideoPrivacy.PRIVATE]: 'Private'
215 const VIDEO_MIMETYPE_EXT = {
216 'video/webm': 'webm',
221 // ---------------------------------------------------------------------------
223 // Score a pod has when we create it as a friend
224 const FRIEND_SCORE = {
229 const SERVER_ACCOUNT_NAME = 'peertube'
230 const ACTIVITY_PUB_ACCEPT_HEADER = 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
232 const ACTIVITY_PUB = {
233 COLLECTION_ITEMS_PER_PAGE: 10,
234 VIDEO_URL_MIME_TYPES: [
238 'application/x-bittorrent',
239 'application/x-bittorrent;x-scheme-handler/magnet'
243 // ---------------------------------------------------------------------------
245 // Number of points we add/remove from a friend after a successful/bad request
251 const FOLLOW_STATES: { [ id: string ]: FollowState } = {
256 const REMOTE_SCHEME = {
261 const JOB_STATES: { [ id: string ]: JobState } = {
263 PROCESSING: 'processing',
267 const JOB_CATEGORIES: { [ id: string ]: JobCategory } = {
268 TRANSCODING: 'transcoding',
269 HTTP_REQUEST: 'http-request'
271 // How many maximum jobs we fetch from the database per cycle
272 const JOBS_FETCH_LIMIT_PER_CYCLE = {
277 let JOBS_FETCHING_INTERVAL = 60000
279 // ---------------------------------------------------------------------------
281 const PRIVATE_RSA_KEY_SIZE = 2048
283 // Password encryption
284 const BCRYPT_SALT_SIZE = 10
286 // ---------------------------------------------------------------------------
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/'
297 let STATIC_MAX_AGE = '30d'
299 // Videos thumbnail size
300 const THUMBNAILS_SIZE = {
304 const PREVIEWS_SIZE = {
314 // Sub folders of cache directory
317 PREVIEWS: join(CONFIG.STORAGE.CACHE_DIR, 'previews')
321 // ---------------------------------------------------------------------------
323 const OPENGRAPH_AND_OEMBED_COMMENT = '<!-- open graph and oembed tags -->'
325 // ---------------------------------------------------------------------------
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'
337 // ---------------------------------------------------------------------------
348 JOBS_FETCH_LIMIT_PER_CYCLE,
349 JOBS_FETCHING_INTERVAL,
351 LAST_MIGRATION_VERSION,
353 OPENGRAPH_AND_OEMBED_COMMENT,
354 PAGINATION_COUNT_DEFAULT,
358 ACTIVITY_PUB_ACCEPT_HEADER,
362 PRIVATE_RSA_KEY_SIZE,