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 * 10 /* 10Go */ },
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'
227 const ACTIVITY_PUB = {
228 ACCEPT_HEADER: 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
229 PUBLIC: 'https://www.w3.org/ns/activitystreams#Public',
230 COLLECTION_ITEMS_PER_PAGE: 10,
231 FETCH_PAGE_LIMIT: 100,
234 VIDEO: [ 'video/mp4', 'video/webm', 'video/ogg' ], // TODO: Merge with VIDEO_MIMETYPE_EXT
235 TORRENT: [ 'application/x-bittorrent' ],
236 MAGNET: [ 'application/x-bittorrent;x-scheme-handler/magnet' ]
240 // ---------------------------------------------------------------------------
242 // Number of points we add/remove from a friend after a successful/bad request
243 const SERVERS_SCORE = {
248 const FOLLOW_STATES: { [ id: string ]: FollowState } = {
253 const REMOTE_SCHEME = {
258 const JOB_STATES: { [ id: string ]: JobState } = {
260 PROCESSING: 'processing',
264 const JOB_CATEGORIES: { [ id: string ]: JobCategory } = {
265 TRANSCODING: 'transcoding',
266 ACTIVITYPUB_HTTP: 'activitypub-http'
268 // How many maximum jobs we fetch from the database per cycle
269 const JOBS_FETCH_LIMIT_PER_CYCLE = {
274 let JOBS_FETCHING_INTERVAL = 60000
276 // ---------------------------------------------------------------------------
278 const PRIVATE_RSA_KEY_SIZE = 2048
280 // Password encryption
281 const BCRYPT_SALT_SIZE = 10
283 // ---------------------------------------------------------------------------
285 // Express static paths (router)
286 const STATIC_PATHS = {
287 PREVIEWS: '/static/previews/',
288 THUMBNAILS: '/static/thumbnails/',
289 TORRENTS: '/static/torrents/',
290 WEBSEED: '/static/webseed/'
294 let STATIC_MAX_AGE = '30d'
296 // Videos thumbnail size
297 const THUMBNAILS_SIZE = {
301 const PREVIEWS_SIZE = {
311 // Sub folders of cache directory
314 PREVIEWS: join(CONFIG.STORAGE.CACHE_DIR, 'previews')
318 // ---------------------------------------------------------------------------
320 const OPENGRAPH_AND_OEMBED_COMMENT = '<!-- open graph and oembed tags -->'
322 // ---------------------------------------------------------------------------
324 // Special constants for a test instance
325 if (isTestInstance() === true) {
326 CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14
327 FRIEND_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 // ---------------------------------------------------------------------------
346 JOBS_FETCH_LIMIT_PER_CYCLE,
347 JOBS_FETCHING_INTERVAL,
349 LAST_MIGRATION_VERSION,
351 OPENGRAPH_AND_OEMBED_COMMENT,
352 PAGINATION_COUNT_DEFAULT,
359 PRIVATE_RSA_KEY_SIZE,