X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=server%2Finitializers%2Fconfig.ts;h=48bb5ab8ee596124c86f1c0b8f1b1da5fc23b947;hb=cf0c8ee588e37809d85ec1deec1e4fdfa0f122a5;hp=950ca61bd336ed0034d8854571ccc483c053ef1c;hpb=4c1c17093461b58d3ee3f23f239e340d8dac1149;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/initializers/config.ts b/server/initializers/config.ts index 950ca61bd..48bb5ab8e 100644 --- a/server/initializers/config.ts +++ b/server/initializers/config.ts @@ -1,10 +1,13 @@ +import bytes from 'bytes' import { IConfig } from 'config' +import decache from 'decache' import { dirname, join } from 'path' +import { VideoRedundancyConfigFilter } from '@shared/models/redundancy/video-redundancy-config-filter.type' +import { BroadcastMessageLevel } from '@shared/models/server' import { VideosRedundancyStrategy } from '../../shared/models' +import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type' // 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' // Use a variable to reload the configuration if we need let config: IConfig = require('config') @@ -18,9 +21,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 +39,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'), @@ -52,9 +58,18 @@ const CONFIG = { PREFIX: config.get('email.subject.prefix') + ' ' } }, + + CLIENT: { + VIDEOS: { + MINIATURE: { + get PREFER_AUTHOR_DISPLAY_NAME () { return config.get('client.videos.miniature.prefer_author_display_name') } + } + } + }, + STORAGE: { TMP_DIR: buildPath(config.get('storage.tmp')), - AVATARS_DIR: buildPath(config.get('storage.avatars')), + ACTOR_IMAGES: buildPath(config.get('storage.avatars')), LOG_DIR: buildPath(config.get('storage.logs')), VIDEOS_DIR: buildPath(config.get('storage.videos')), STREAMING_PLAYLISTS_DIR: buildPath(config.get('storage.streaming_playlists')), @@ -64,7 +79,28 @@ 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')) + }, + OBJECT_STORAGE: { + ENABLED: config.get('object_storage.enabled'), + MAX_UPLOAD_PART: bytes.parse(config.get('object_storage.max_upload_part')), + ENDPOINT: config.get('object_storage.endpoint'), + REGION: config.get('object_storage.region'), + CREDENTIALS: { + ACCESS_KEY_ID: config.get('object_storage.credentials.access_key_id'), + SECRET_ACCESS_KEY: config.get('object_storage.credentials.secret_access_key') + }, + VIDEOS: { + BUCKET_NAME: config.get('object_storage.videos.bucket_name'), + PREFIX: config.get('object_storage.videos.prefix'), + BASE_URL: config.get('object_storage.videos.base_url') + }, + STREAMING_PLAYLISTS: { + BUCKET_NAME: config.get('object_storage.streaming_playlists.bucket_name'), + PREFIX: config.get('object_storage.streaming_playlists.prefix'), + BASE_URL: config.get('object_storage.streaming_playlists.base_url') + } }, WEBSERVER: { SCHEME: config.get('webserver.https') === true ? 'https' : 'http', @@ -98,17 +134,17 @@ const CONFIG = { MAX_FILE_SIZE: bytes.parse(config.get('log.rotation.maxFileSize')), MAX_FILES: config.get('log.rotation.maxFiles') }, - ANONYMIZE_IP: config.get('log.anonymizeIP') - }, - SEARCH: { - REMOTE_URI: { - USERS: config.get('search.remote_uri.users'), - ANONYMOUS: config.get('search.remote_uri.anonymous') - } + ANONYMIZE_IP: config.get('log.anonymizeIP'), + LOG_PING_REQUESTS: config.get('log.log_ping_requests'), + PRETTIFY_SQL: config.get('log.prettify_sql') }, TRENDING: { VIDEOS: { - INTERVAL_DAYS: config.get('trending.videos.interval_days') + INTERVAL_DAYS: config.get('trending.videos.interval_days'), + ALGORITHMS: { + get ENABLED () { return config.get('trending.videos.algorithms.enabled') }, + get DEFAULT () { return config.get('trending.videos.algorithms.default') } + } } }, REDUNDANCY: { @@ -117,10 +153,20 @@ 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') + }, + SECURITY: { + FRAMEGUARD: { + ENABLED: config.get('security.frameguard.enabled') + } }, TRACKER: { ENABLED: config.get('tracker.enabled'), @@ -146,6 +192,25 @@ const CONFIG = { URL: config.get('plugins.index.url') } }, + FEDERATION: { + VIDEOS: { + FEDERATE_UNLISTED: config.get('federation.videos.federate_unlisted'), + CLEANUP_REMOTE_INTERACTIONS: config.get('federation.videos.cleanup_remote_interactions') + } + }, + PEERTUBE: { + CHECK_LATEST_VERSION: { + ENABLED: config.get('peertube.check_latest_version.enabled'), + URL: config.get('peertube.check_latest_version.url') + } + }, + WEBADMIN: { + CONFIGURATION: { + EDITION: { + ALLOWED: config.get('webadmin.configuration.edition.allowed') + } + } + }, ADMIN: { get EMAIL () { return config.get('admin.email') } }, @@ -156,6 +221,7 @@ const CONFIG = { get ENABLED () { return config.get('signup.enabled') }, get LIMIT () { return config.get('signup.limit') }, get REQUIRES_EMAIL_VERIFICATION () { return config.get('signup.requires_email_verification') }, + get MINIMUM_AGE () { return config.get('signup.minimum_age') }, FILTERS: { CIDR: { get WHITELIST () { return config.get('signup.filters.cidr.whitelist') }, @@ -172,6 +238,8 @@ const CONFIG = { get ALLOW_ADDITIONAL_EXTENSIONS () { return config.get('transcoding.allow_additional_extensions') }, get ALLOW_AUDIO_FILES () { return config.get('transcoding.allow_audio_files') }, get THREADS () { return config.get('transcoding.threads') }, + get CONCURRENCY () { return config.get('transcoding.concurrency') }, + get PROFILE () { return config.get('transcoding.profile') }, RESOLUTIONS: { get '0p' () { return config.get('transcoding.resolutions.0p') }, get '240p' () { return config.get('transcoding.resolutions.240p') }, @@ -179,6 +247,7 @@ const CONFIG = { get '480p' () { return config.get('transcoding.resolutions.480p') }, get '720p' () { return config.get('transcoding.resolutions.720p') }, get '1080p' () { return config.get('transcoding.resolutions.1080p') }, + get '1440p' () { return config.get('transcoding.resolutions.1440p') }, get '2160p' () { return config.get('transcoding.resolutions.2160p') } }, HLS: { @@ -188,10 +257,42 @@ const CONFIG = { 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') }, + get PROFILE () { return config.get('live.transcoding.profile') }, + + 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 '1440p' () { return config.get('live.transcoding.resolutions.1440p') }, + get '2160p' () { return config.get('live.transcoding.resolutions.2160p') } + } + } + }, IMPORT: { VIDEOS: { + get CONCURRENCY () { return config.get('import.videos.concurrency') }, + HTTP: { get ENABLED () { return config.get('import.videos.http.enabled') }, + get FORCE_IPV4 () { return config.get('import.videos.http.force_ipv4') }, PROXY: { get ENABLED () { return config.get('import.videos.http.proxy.enabled') }, get URL () { return config.get('import.videos.http.proxy.url') } @@ -215,6 +316,9 @@ const CONFIG = { }, VIDEO_CAPTIONS: { get SIZE () { return config.get('cache.captions.size') } + }, + TORRENTS: { + get SIZE () { return config.get('cache.torrents.size') } } }, INSTANCE: { @@ -236,8 +340,10 @@ const CONFIG = { get CATEGORIES () { return config.get('instance.categories') || [] }, get IS_NSFW () { return config.get('instance.is_nsfw') }, - get DEFAULT_CLIENT_ROUTE () { return config.get('instance.default_client_route') }, get DEFAULT_NSFW_POLICY () { return config.get('instance.default_nsfw_policy') }, + + get DEFAULT_CLIENT_ROUTE () { return config.get('instance.default_client_route') }, + CUSTOMIZATIONS: { get JAVASCRIPT () { return config.get('instance.customizations.javascript') }, get CSS () { return config.get('instance.customizations.css') } @@ -277,6 +383,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: { + get USERS () { return config.get('search.remote_uri.users') }, + get ANONYMOUS () { return 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') } + } } } @@ -285,7 +409,11 @@ function registerConfigChangedHandler (fun: Function) { } function isEmailEnabled () { - return !!CONFIG.SMTP.HOSTNAME && !!CONFIG.SMTP.PORT + if (CONFIG.SMTP.TRANSPORT === 'sendmail' && CONFIG.SMTP.SENDMAIL) return true + + if (CONFIG.SMTP.TRANSPORT === 'smtp' && CONFIG.SMTP.HOSTNAME && CONFIG.SMTP.PORT) return true + + return false } // --------------------------------------------------------------------------- @@ -299,14 +427,22 @@ export { // --------------------------------------------------------------------------- function getLocalConfigFilePath () { - const configSources = config.util.getConfigSources() - if (configSources.length === 0) throw new Error('Invalid config source.') + const localConfigDir = getLocalConfigDir() let filename = 'local' 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(localConfigDir, filename + '.json') +} + +function getLocalConfigDir () { + if (process.env.PEERTUBE_LOCAL_CONFIG) return process.env.PEERTUBE_LOCAL_CONFIG + + const configSources = config.util.getConfigSources() + if (configSources.length === 0) throw new Error('Invalid config source.') + + return dirname(configSources[0].name) } function buildVideosRedundancy (objs: any[]): VideosRedundancyStrategy[] { @@ -325,24 +461,26 @@ function buildVideosRedundancy (objs: any[]): VideosRedundancyStrategy[] { export function reloadConfig () { - function directory () { + function getConfigDirectories () { if (process.env.NODE_CONFIG_DIR) { - return process.env.NODE_CONFIG_DIR + return process.env.NODE_CONFIG_DIR.split(':') } - return join(root(), 'config') + return [ join(root(), 'config') ] } function purge () { + const directories = getConfigDirectories() + for (const fileName in require.cache) { - if (fileName.indexOf(directory()) === -1) { + if (directories.some((dir) => fileName.includes(dir)) === false) { continue } delete require.cache[fileName] } - delete require.cache[require.resolve('config')] + decache('config') } purge()