X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Finitializers%2Fconfig.ts;h=d1bbbc9a773937504bf480c1e8129fda35b6e809;hb=677012b4ee53e5099e8c90445616644e1a6af9ef;hp=164d714d6b94ad7fd4edd10da4324334f087830f;hpb=00aab0666c6f772548c160fdfa871a8843b88f37;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/initializers/config.ts b/server/initializers/config.ts index 164d714d6..d1bbbc9a7 100644 --- a/server/initializers/config.ts +++ b/server/initializers/config.ts @@ -1,10 +1,12 @@ import { IConfig } from 'config' import { dirname, join } from 'path' -import { VideosRedundancy } from '../../shared/models' +import { VideosRedundancyStrategy } from '../../shared/models' // Do not use barrels, remain constants as independent as possible import { buildPath, parseBytes, parseDurationToMs, root } from '../helpers/core-utils' import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type' import * as bytes from 'bytes' +import { VideoRedundancyConfigFilter } from '@shared/models/redundancy/video-redundancy-config-filter.type' +import { BroadcastMessageLevel } from '@shared/models/server' // Use a variable to reload the configuration if we need let config: IConfig = require('config') @@ -18,9 +20,10 @@ const CONFIG = { HOSTNAME: config.get('listen.hostname') }, DATABASE: { - DBNAME: 'peertube' + config.get('database.suffix'), + DBNAME: config.has('database.name') ? config.get('database.name') : 'peertube' + config.get('database.suffix'), HOSTNAME: config.get('database.hostname'), PORT: config.get('database.port'), + SSL: config.get('database.ssl'), USERNAME: config.get('database.username'), PASSWORD: config.get('database.password'), POOL: { @@ -35,6 +38,8 @@ const CONFIG = { DB: config.has('redis.db') ? config.get('redis.db') : null }, SMTP: { + TRANSPORT: config.has('smtp.transport') ? config.get('smtp.transport') : 'smtp', + SENDMAIL: config.has('smtp.sendmail') ? config.get('smtp.sendmail') : null, HOSTNAME: config.get('smtp.hostname'), PORT: config.get('smtp.port'), USERNAME: config.get('smtp.username'), @@ -64,7 +69,8 @@ const CONFIG = { CAPTIONS_DIR: buildPath(config.get('storage.captions')), TORRENTS_DIR: buildPath(config.get('storage.torrents')), CACHE_DIR: buildPath(config.get('storage.cache')), - PLUGINS_DIR: buildPath(config.get('storage.plugins')) + PLUGINS_DIR: buildPath(config.get('storage.plugins')), + CLIENT_OVERRIDES_DIR: buildPath(config.get('storage.client_overrides')) }, WEBSERVER: { SCHEME: config.get('webserver.https') === true ? 'https' : 'http', @@ -93,13 +99,12 @@ const CONFIG = { TRUST_PROXY: config.get('trust_proxy'), LOG: { LEVEL: config.get('log.level'), - ROTATION: config.get('log.rotation.enabled') - }, - SEARCH: { - REMOTE_URI: { - USERS: config.get('search.remote_uri.users'), - ANONYMOUS: config.get('search.remote_uri.anonymous') - } + ROTATION: { + ENABLED: config.get('log.rotation.enabled'), + MAX_FILE_SIZE: bytes.parse(config.get('log.rotation.maxFileSize')), + MAX_FILES: config.get('log.rotation.maxFiles') + }, + ANONYMIZE_IP: config.get('log.anonymizeIP') }, TRENDING: { VIDEOS: { @@ -112,10 +117,15 @@ const CONFIG = { STRATEGIES: buildVideosRedundancy(config.get('redundancy.videos.strategies')) } }, + REMOTE_REDUNDANCY: { + VIDEOS: { + ACCEPT_FROM: config.get('remote_redundancy.videos.accept_from') + } + }, CSP: { ENABLED: config.get('csp.enabled'), REPORT_ONLY: config.get('csp.report_only'), - REPORT_URI: config.get('csp.report_uri') + REPORT_URI: config.get('csp.report_uri') }, TRACKER: { ENABLED: config.get('tracker.enabled'), @@ -141,6 +151,11 @@ const CONFIG = { URL: config.get('plugins.index.url') } }, + FEDERATION: { + VIDEOS: { + FEDERATE_UNLISTED: config.get('federation.videos.federate_unlisted') + } + }, ADMIN: { get EMAIL () { return config.get('admin.email') } }, @@ -168,6 +183,7 @@ const CONFIG = { get ALLOW_AUDIO_FILES () { return config.get('transcoding.allow_audio_files') }, get THREADS () { return config.get('transcoding.threads') }, RESOLUTIONS: { + get '0p' () { return config.get('transcoding.resolutions.0p') }, get '240p' () { return config.get('transcoding.resolutions.240p') }, get '360p' () { return config.get('transcoding.resolutions.360p') }, get '480p' () { return config.get('transcoding.resolutions.480p') }, @@ -177,12 +193,49 @@ const CONFIG = { }, HLS: { get ENABLED () { return config.get('transcoding.hls.enabled') } + }, + WEBTORRENT: { + get ENABLED () { return config.get('transcoding.webtorrent.enabled') } + } + }, + LIVE: { + get ENABLED () { return config.get('live.enabled') }, + + get MAX_DURATION () { return parseDurationToMs(config.get('live.max_duration')) }, + get MAX_INSTANCE_LIVES () { return config.get('live.max_instance_lives') }, + get MAX_USER_LIVES () { return config.get('live.max_user_lives') }, + + get ALLOW_REPLAY () { return config.get('live.allow_replay') }, + + RTMP: { + get PORT () { return config.get('live.rtmp.port') } + }, + + TRANSCODING: { + get ENABLED () { return config.get('live.transcoding.enabled') }, + get THREADS () { return config.get('live.transcoding.threads') }, + + RESOLUTIONS: { + get '240p' () { return config.get('live.transcoding.resolutions.240p') }, + get '360p' () { return config.get('live.transcoding.resolutions.360p') }, + get '480p' () { return config.get('live.transcoding.resolutions.480p') }, + get '720p' () { return config.get('live.transcoding.resolutions.720p') }, + get '1080p' () { return config.get('live.transcoding.resolutions.1080p') }, + get '2160p' () { return config.get('live.transcoding.resolutions.2160p') } + } } }, IMPORT: { VIDEOS: { HTTP: { - get ENABLED () { return config.get('import.videos.http.enabled') } + get ENABLED () { return config.get('import.videos.http.enabled') }, + FORCEIPV4: { + get ENABLED () { return config.get('import.videos.http.forceipv4.enabled') } + }, + PROXY: { + get ENABLED () { return config.get('import.videos.http.proxy.enabled') }, + get URL () { return config.get('import.videos.http.proxy.url') } + } }, TORRENT: { get ENABLED () { return config.get('import.videos.torrent.enabled') } @@ -264,6 +317,24 @@ const CONFIG = { }, THEME: { get DEFAULT () { return config.get('theme.default') } + }, + BROADCAST_MESSAGE: { + get ENABLED () { return config.get('broadcast_message.enabled') }, + get MESSAGE () { return config.get('broadcast_message.message') }, + get LEVEL () { return config.get('broadcast_message.level') }, + get DISMISSABLE () { return config.get('broadcast_message.dismissable') } + }, + SEARCH: { + REMOTE_URI: { + USERS: config.get('search.remote_uri.users'), + ANONYMOUS: config.get('search.remote_uri.anonymous') + }, + SEARCH_INDEX: { + get ENABLED () { return config.get('search.search_index.enabled') }, + get URL () { return config.get('search.search_index.url') }, + get DISABLE_LOCAL_SEARCH () { return config.get('search.search_index.disable_local_search') }, + get IS_DEFAULT_SEARCH () { return config.get('search.search_index.is_default_search') } + } } } @@ -271,11 +342,16 @@ function registerConfigChangedHandler (fun: Function) { configChangedHandlers.push(fun) } +function isEmailEnabled () { + return !!CONFIG.SMTP.HOSTNAME && !!CONFIG.SMTP.PORT +} + // --------------------------------------------------------------------------- export { CONFIG, - registerConfigChangedHandler + registerConfigChangedHandler, + isEmailEnabled } // --------------------------------------------------------------------------- @@ -288,10 +364,10 @@ function getLocalConfigFilePath () { if (process.env.NODE_ENV) filename += `-${process.env.NODE_ENV}` if (process.env.NODE_APP_INSTANCE) filename += `-${process.env.NODE_APP_INSTANCE}` - return join(dirname(configSources[ 0 ].name), filename + '.json') + return join(dirname(configSources[0].name), filename + '.json') } -function buildVideosRedundancy (objs: any[]): VideosRedundancy[] { +function buildVideosRedundancy (objs: any[]): VideosRedundancyStrategy[] { if (!objs) return [] if (!Array.isArray(objs)) return objs @@ -317,7 +393,7 @@ export function reloadConfig () { function purge () { for (const fileName in require.cache) { - if (-1 === fileName.indexOf(directory())) { + if (fileName.includes(directory()) === false) { continue }