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 = 110
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 JOBS: [ 'id', 'createdAt' ],
36 VIDEO_ABUSES: [ 'id', 'createdAt' ],
37 VIDEO_CHANNELS: [ 'id', 'name', 'updatedAt', 'createdAt' ],
38 VIDEOS: [ 'name', 'duration', 'createdAt', 'views', 'likes' ],
39 BLACKLISTS: [ 'id', 'name', 'duration', 'views', 'likes', 'dislikes', 'uuid', 'createdAt' ],
40 FOLLOWERS: [ 'createdAt' ],
41 FOLLOWING: [ 'createdAt' ]
44 const OAUTH_LIFETIME = {
45 ACCESS_TOKEN: 3600 * 4, // 4 hours
46 REFRESH_TOKEN: 1209600 // 2 weeks
49 // ---------------------------------------------------------------------------
53 PORT: config.get<number>('listen.port')
56 DBNAME: 'peertube' + config.get<string>('database.suffix'),
57 HOSTNAME: config.get<string>('database.hostname'),
58 PORT: config.get<number>('database.port'),
59 USERNAME: config.get<string>('database.username'),
60 PASSWORD: config.get<string>('database.password')
63 LOG_DIR: join(root(), config.get<string>('storage.logs')),
64 VIDEOS_DIR: join(root(), config.get<string>('storage.videos')),
65 THUMBNAILS_DIR: join(root(), config.get<string>('storage.thumbnails')),
66 PREVIEWS_DIR: join(root(), config.get<string>('storage.previews')),
67 TORRENTS_DIR: join(root(), config.get<string>('storage.torrents')),
68 CACHE_DIR: join(root(), config.get<string>('storage.cache'))
71 SCHEME: config.get<boolean>('webserver.https') === true ? 'https' : 'http',
72 WS: config.get<boolean>('webserver.https') === true ? 'wss' : 'ws',
73 HOSTNAME: config.get<string>('webserver.hostname'),
74 PORT: config.get<number>('webserver.port'),
79 EMAIL: config.get<string>('admin.email')
82 ENABLED: config.get<boolean>('signup.enabled'),
83 LIMIT: config.get<number>('signup.limit')
86 VIDEO_QUOTA: config.get<number>('user.video_quota')
89 ENABLED: config.get<boolean>('transcoding.enabled'),
90 THREADS: config.get<number>('transcoding.threads'),
92 '240' : config.get<boolean>('transcoding.resolutions.240p'),
93 '360': config.get<boolean>('transcoding.resolutions.360p'),
94 '480': config.get<boolean>('transcoding.resolutions.480p'),
95 '720': config.get<boolean>('transcoding.resolutions.720p'),
96 '1080': config.get<boolean>('transcoding.resolutions.1080p')
101 SIZE: config.get<number>('cache.previews.size')
105 CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
106 CONFIG.WEBSERVER.HOST = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
108 // ---------------------------------------------------------------------------
110 const CONSTRAINTS_FIELDS = {
112 USERNAME: { min: 3, max: 20 }, // Length
113 PASSWORD: { min: 6, max: 255 }, // Length
114 VIDEO_QUOTA: { min: -1 }
117 REASON: { min: 2, max: 300 } // Length
120 NAME: { min: 3, max: 120 }, // Length
121 DESCRIPTION: { min: 3, max: 250 }, // Length
122 URL: { min: 3, max: 2000 } // Length
125 NAME: { min: 3, max: 120 }, // Length
126 TRUNCATED_DESCRIPTION: { min: 3, max: 250 }, // Length
127 DESCRIPTION: { min: 3, max: 3000 }, // Length
128 EXTNAME: [ '.mp4', '.ogv', '.webm' ],
129 INFO_HASH: { min: 40, max: 40 }, // Length, info hash is 20 bytes length but we represent it in hexadecimal so 20 * 2
130 DURATION: { min: 1 }, // Number
131 TAGS: { min: 0, max: 5 }, // Number of total tags
132 TAG: { min: 2, max: 30 }, // Length
133 THUMBNAIL: { min: 2, max: 30 },
134 THUMBNAIL_DATA: { min: 0, max: 20000 }, // Bytes
137 DISLIKES: { min: 0 },
138 FILE_SIZE: { min: 10 },
139 URL: { min: 3, max: 2000 } // Length
142 PUBLIC_KEY: { min: 10, max: 5000 }, // Length
143 PRIVATE_KEY: { min: 10, max: 5000 }, // Length
144 URL: { min: 3, max: 2000 } // Length
151 const VIDEO_RATE_TYPES: { [ id: string ]: VideoRateType } = {
156 const VIDEO_CATEGORIES = {
171 15: 'Science & Technology',
177 // See https://creativecommons.org/licenses/?lang=en
178 const VIDEO_LICENCES = {
180 2: 'Attribution - Share Alike',
181 3: 'Attribution - No Derivatives',
182 4: 'Attribution - Non Commercial',
183 5: 'Attribution - Non Commercial - Share Alike',
184 6: 'Attribution - Non Commercial - No Derivatives',
185 7: 'Public Domain Dedication'
188 // See https://en.wikipedia.org/wiki/List_of_languages_by_number_of_native_speakers#Nationalencyklopedin
189 const VIDEO_LANGUAGES = {
206 const VIDEO_PRIVACIES = {
207 [VideoPrivacy.PUBLIC]: 'Public',
208 [VideoPrivacy.UNLISTED]: 'Unlisted',
209 [VideoPrivacy.PRIVATE]: 'Private'
212 const VIDEO_MIMETYPE_EXT = {
213 'video/webm': '.webm',
218 // ---------------------------------------------------------------------------
220 const SERVER_ACCOUNT_NAME = 'peertube'
222 const ACTIVITY_PUB = {
223 POTENTIAL_ACCEPT_HEADERS: [
224 'application/activity+json',
225 'application/ld+json'
227 ACCEPT_HEADER: 'application/activity+json, application/ld+json',
228 PUBLIC: 'https://www.w3.org/ns/activitystreams#Public',
229 COLLECTION_ITEMS_PER_PAGE: 10,
230 FETCH_PAGE_LIMIT: 100,
233 VIDEO: [ 'video/mp4', 'video/webm', 'video/ogg' ], // TODO: Merge with VIDEO_MIMETYPE_EXT
234 TORRENT: [ 'application/x-bittorrent' ],
235 MAGNET: [ '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 = {
249 const FOLLOW_STATES: { [ id: string ]: FollowState } = {
254 const REMOTE_SCHEME = {
259 const JOB_STATES: { [ id: string ]: JobState } = {
261 PROCESSING: 'processing',
265 const JOB_CATEGORIES: { [ id: string ]: JobCategory } = {
266 TRANSCODING: 'transcoding',
267 ACTIVITYPUB_HTTP: 'activitypub-http'
269 // How many maximum jobs we fetch from the database per cycle
270 const JOBS_FETCH_LIMIT_PER_CYCLE = {
275 let JOBS_FETCHING_INTERVAL = 60000
277 // ---------------------------------------------------------------------------
279 const PRIVATE_RSA_KEY_SIZE = 2048
281 // Password encryption
282 const BCRYPT_SALT_SIZE = 10
284 // ---------------------------------------------------------------------------
286 // Express static paths (router)
287 const STATIC_PATHS = {
288 PREVIEWS: '/static/previews/',
289 THUMBNAILS: '/static/thumbnails/',
290 TORRENTS: '/static/torrents/',
291 WEBSEED: '/static/webseed/'
295 let STATIC_MAX_AGE = '30d'
297 // Videos thumbnail size
298 const THUMBNAILS_SIZE = {
302 const PREVIEWS_SIZE = {
312 // Sub folders of cache directory
315 PREVIEWS: join(CONFIG.STORAGE.CACHE_DIR, 'previews')
319 const ACCEPT_HEADERS = ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS.concat('html', 'application/json')
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 SERVERS_SCORE.BASE = 20
330 JOBS_FETCHING_INTERVAL = 1000
331 REMOTE_SCHEME.HTTP = 'http'
332 REMOTE_SCHEME.WS = 'ws'
334 ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE = 2
337 // ---------------------------------------------------------------------------
348 JOBS_FETCH_LIMIT_PER_CYCLE,
349 JOBS_FETCHING_INTERVAL,
351 LAST_MIGRATION_VERSION,
353 OPENGRAPH_AND_OEMBED_COMMENT,
354 PAGINATION_COUNT_DEFAULT,
361 PRIVATE_RSA_KEY_SIZE,