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'
11 } from '../../shared/models'
12 import { VideoPrivacy } from '../../shared/models/videos/video-privacy.enum'
13 import { FollowState } from '../../shared/models/accounts/follow.model'
15 // ---------------------------------------------------------------------------
17 const LAST_MIGRATION_VERSION = 95
19 // ---------------------------------------------------------------------------
22 const API_VERSION = 'v1'
24 // Number of results by default for the pagination
25 const PAGINATION_COUNT_DEFAULT = 15
27 // Sortable columns per schema
28 const SEARCHABLE_COLUMNS = {
29 VIDEOS: [ 'name', 'magnetUri', 'host', 'account', 'tags' ]
32 // Sortable columns per schema
33 const SORTABLE_COLUMNS = {
34 USERS: [ 'id', 'username', 'createdAt' ],
35 VIDEO_ABUSES: [ 'id', 'createdAt' ],
36 VIDEO_CHANNELS: [ 'id', 'name', 'updatedAt', 'createdAt' ],
37 VIDEOS: [ 'name', 'duration', 'createdAt', 'views', 'likes' ],
38 BLACKLISTS: [ 'id', 'name', 'duration', 'views', 'likes', 'dislikes', 'uuid', 'createdAt' ],
39 FOLLOWERS: [ 'createdAt' ],
40 FOLLOWING: [ 'createdAt' ]
43 const OAUTH_LIFETIME = {
44 ACCESS_TOKEN: 3600 * 4, // 4 hours
45 REFRESH_TOKEN: 1209600 // 2 weeks
48 // ---------------------------------------------------------------------------
52 PORT: config.get<number>('listen.port')
55 DBNAME: 'peertube' + config.get<string>('database.suffix'),
56 HOSTNAME: config.get<string>('database.hostname'),
57 PORT: config.get<number>('database.port'),
58 USERNAME: config.get<string>('database.username'),
59 PASSWORD: config.get<string>('database.password')
62 LOG_DIR: join(root(), config.get<string>('storage.logs')),
63 VIDEOS_DIR: join(root(), config.get<string>('storage.videos')),
64 THUMBNAILS_DIR: join(root(), config.get<string>('storage.thumbnails')),
65 PREVIEWS_DIR: join(root(), config.get<string>('storage.previews')),
66 TORRENTS_DIR: join(root(), config.get<string>('storage.torrents')),
67 CACHE_DIR: join(root(), config.get<string>('storage.cache'))
70 SCHEME: config.get<boolean>('webserver.https') === true ? 'https' : 'http',
71 WS: config.get<boolean>('webserver.https') === true ? 'wss' : 'ws',
72 HOSTNAME: config.get<string>('webserver.hostname'),
73 PORT: config.get<number>('webserver.port'),
78 EMAIL: config.get<string>('admin.email')
81 ENABLED: config.get<boolean>('signup.enabled'),
82 LIMIT: config.get<number>('signup.limit')
85 VIDEO_QUOTA: config.get<number>('user.video_quota')
88 ENABLED: config.get<boolean>('transcoding.enabled'),
89 THREADS: config.get<number>('transcoding.threads'),
91 '240' : config.get<boolean>('transcoding.resolutions.240p'),
92 '360': config.get<boolean>('transcoding.resolutions.360p'),
93 '480': config.get<boolean>('transcoding.resolutions.480p'),
94 '720': config.get<boolean>('transcoding.resolutions.720p'),
95 '1080': config.get<boolean>('transcoding.resolutions.1080p')
100 SIZE: config.get<number>('cache.previews.size')
104 CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
105 CONFIG.WEBSERVER.HOST = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
107 // ---------------------------------------------------------------------------
109 const CONSTRAINTS_FIELDS = {
111 USERNAME: { min: 3, max: 20 }, // Length
112 PASSWORD: { min: 6, max: 255 }, // Length
113 VIDEO_QUOTA: { min: -1 }
116 REASON: { min: 2, max: 300 } // Length
119 NAME: { min: 3, max: 120 }, // Length
120 DESCRIPTION: { min: 3, max: 250 }, // Length
121 URL: { min: 3, max: 2000 } // Length
124 NAME: { min: 3, max: 120 }, // Length
125 TRUNCATED_DESCRIPTION: { min: 3, max: 250 }, // Length
126 DESCRIPTION: { min: 3, max: 3000 }, // Length
127 EXTNAME: [ '.mp4', '.ogv', '.webm' ],
128 INFO_HASH: { min: 40, max: 40 }, // Length, info hash is 20 bytes length but we represent it in hexadecimal so 20 * 2
129 DURATION: { min: 1, max: 7200 }, // Number
130 TAGS: { min: 0, max: 5 }, // Number of total tags
131 TAG: { min: 2, max: 30 }, // Length
132 THUMBNAIL: { min: 2, max: 30 },
133 THUMBNAIL_DATA: { min: 0, max: 20000 }, // Bytes
136 DISLIKES: { min: 0 },
137 FILE_SIZE: { min: 10, max: 1024 * 1024 * 1024 * 3 /* 3Go */ },
138 URL: { min: 3, max: 2000 } // Length
141 PUBLIC_KEY: { min: 10, max: 5000 }, // Length
142 PRIVATE_KEY: { min: 10, max: 5000 }, // Length
143 URL: { min: 3, max: 2000 } // Length
150 const VIDEO_RATE_TYPES: { [ id: string ]: VideoRateType } = {
155 const VIDEO_CATEGORIES = {
170 15: 'Science & Technology',
176 // See https://creativecommons.org/licenses/?lang=en
177 const VIDEO_LICENCES = {
179 2: 'Attribution - Share Alike',
180 3: 'Attribution - No Derivatives',
181 4: 'Attribution - Non Commercial',
182 5: 'Attribution - Non Commercial - Share Alike',
183 6: 'Attribution - Non Commercial - No Derivatives',
184 7: 'Public Domain Dedication'
187 // See https://en.wikipedia.org/wiki/List_of_languages_by_number_of_native_speakers#Nationalencyklopedin
188 const VIDEO_LANGUAGES = {
205 const VIDEO_PRIVACIES = {
206 [VideoPrivacy.PUBLIC]: 'Public',
207 [VideoPrivacy.UNLISTED]: 'Unlisted',
208 [VideoPrivacy.PRIVATE]: 'Private'
211 const VIDEO_MIMETYPE_EXT = {
212 'video/webm': 'webm',
217 // ---------------------------------------------------------------------------
219 // Score a server has when we create it as a friend
220 const FRIEND_SCORE = {
225 const SERVER_ACCOUNT_NAME = 'peertube'
226 const ACTIVITY_PUB_ACCEPT_HEADER = 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
228 const ACTIVITY_PUB = {
229 COLLECTION_ITEMS_PER_PAGE: 10,
230 VIDEO_URL_MIME_TYPES: [
234 'application/x-bittorrent',
235 'application/x-bittorrent;x-scheme-handler/magnet'
239 // ---------------------------------------------------------------------------
241 // Number of points we add/remove from a friend after a successful/bad request
242 const SERVERS_SCORE = {
247 const FOLLOW_STATES: { [ id: string ]: FollowState } = {
252 const REMOTE_SCHEME = {
257 const JOB_STATES: { [ id: string ]: JobState } = {
259 PROCESSING: 'processing',
263 const JOB_CATEGORIES: { [ id: string ]: JobCategory } = {
264 TRANSCODING: 'transcoding',
265 HTTP_REQUEST: 'http-request'
267 // How many maximum jobs we fetch from the database per cycle
268 const JOBS_FETCH_LIMIT_PER_CYCLE = {
273 let JOBS_FETCHING_INTERVAL = 60000
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 // ---------------------------------------------------------------------------
319 const OPENGRAPH_AND_OEMBED_COMMENT = '<!-- open graph and oembed tags -->'
321 // ---------------------------------------------------------------------------
323 // Special constants for a test instance
324 if (isTestInstance() === true) {
325 CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14
326 FRIEND_SCORE.BASE = 20
327 JOBS_FETCHING_INTERVAL = 10000
328 REMOTE_SCHEME.HTTP = 'http'
329 REMOTE_SCHEME.WS = 'ws'
333 // ---------------------------------------------------------------------------
344 JOBS_FETCH_LIMIT_PER_CYCLE,
345 JOBS_FETCHING_INTERVAL,
347 LAST_MIGRATION_VERSION,
349 OPENGRAPH_AND_OEMBED_COMMENT,
350 PAGINATION_COUNT_DEFAULT,
354 ACTIVITY_PUB_ACCEPT_HEADER,
358 PRIVATE_RSA_KEY_SIZE,