X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Finitializers%2Fconfig.ts;h=44fd9045b48a82117307ab4673f1a2b7855c3114;hb=3092e9bbb05fe292fd13bc685b89069c3dda55d9;hp=2be300a57d66997a678280b6612993b00e3c4ffe;hpb=79ad1706f3cf009e04db9cd9e6a721801d93e64e;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/initializers/config.ts b/server/initializers/config.ts index 2be300a57..44fd9045b 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') @@ -35,6 +37,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'), @@ -48,8 +52,8 @@ const CONFIG = { BODY: { SIGNATURE: config.get('email.body.signature') }, - OBJECT: { - PREFIX: config.get('email.object.prefix') + ' ' + SUBJECT: { + PREFIX: config.get('email.subject.prefix') + ' ' } }, STORAGE: { @@ -63,7 +67,8 @@ const CONFIG = { PREVIEWS_DIR: buildPath(config.get('storage.previews')), CAPTIONS_DIR: buildPath(config.get('storage.captions')), TORRENTS_DIR: buildPath(config.get('storage.torrents')), - CACHE_DIR: buildPath(config.get('storage.cache')) + CACHE_DIR: buildPath(config.get('storage.cache')), + PLUGINS_DIR: buildPath(config.get('storage.plugins')) }, WEBSERVER: { SCHEME: config.get('webserver.https') === true ? 'https' : 'http', @@ -72,6 +77,14 @@ const CONFIG = { PORT: config.get('webserver.port') }, RATES_LIMIT: { + API: { + WINDOW_MS: parseDurationToMs(config.get('rates_limit.api.window')), + MAX: config.get('rates_limit.api.max') + }, + SIGNUP: { + WINDOW_MS: parseDurationToMs(config.get('rates_limit.signup.window')), + MAX: config.get('rates_limit.signup.max') + }, LOGIN: { WINDOW_MS: parseDurationToMs(config.get('rates_limit.login.window')), MAX: config.get('rates_limit.login.max') @@ -83,7 +96,13 @@ const CONFIG = { }, TRUST_PROXY: config.get('trust_proxy'), LOG: { - LEVEL: config.get('log.level') + LEVEL: config.get('log.level'), + 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') }, SEARCH: { REMOTE_URI: { @@ -102,6 +121,11 @@ 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'), @@ -124,6 +148,18 @@ const CONFIG = { } } }, + PLUGINS: { + INDEX: { + ENABLED: config.get('plugins.index.enabled'), + CHECK_LATEST_VERSIONS_INTERVAL: parseDurationToMs(config.get('plugins.index.check_latest_versions_interval')), + URL: config.get('plugins.index.url') + } + }, + FEDERATION: { + VIDEOS: { + FEDERATE_UNLISTED: config.get('federation.videos.federate_unlisted') + } + }, ADMIN: { get EMAIL () { return config.get('admin.email') } }, @@ -151,20 +187,29 @@ 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') }, get '720p' () { return config.get('transcoding.resolutions.720p') }, - get '1080p' () { return config.get('transcoding.resolutions.1080p') } + get '1080p' () { return config.get('transcoding.resolutions.1080p') }, + get '2160p' () { return config.get('transcoding.resolutions.2160p') } }, HLS: { get ENABLED () { return config.get('transcoding.hls.enabled') } + }, + WEBTORRENT: { + get ENABLED () { return config.get('transcoding.webtorrent.enabled') } } }, IMPORT: { VIDEOS: { HTTP: { - get ENABLED () { return config.get('import.videos.http.enabled') } + get ENABLED () { return config.get('import.videos.http.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') } @@ -191,6 +236,19 @@ const CONFIG = { get SHORT_DESCRIPTION () { return config.get('instance.short_description') }, get DESCRIPTION () { return config.get('instance.description') }, get TERMS () { return config.get('instance.terms') }, + get CODE_OF_CONDUCT () { return config.get('instance.code_of_conduct') }, + + get CREATION_REASON () { return config.get('instance.creation_reason') }, + + get MODERATION_INFORMATION () { return config.get('instance.moderation_information') }, + get ADMINISTRATOR () { return config.get('instance.administrator') }, + get MAINTENANCE_LIFETIME () { return config.get('instance.maintenance_lifetime') }, + get BUSINESS_MODEL () { return config.get('instance.business_model') }, + get HARDWARE_INFORMATION () { return config.get('instance.hardware_information') }, + + get LANGUAGES () { return config.get('instance.languages') || [] }, + 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') }, @@ -213,6 +271,32 @@ const CONFIG = { get ENABLED () { return config.get('followers.instance.enabled') }, get MANUAL_APPROVAL () { return config.get('followers.instance.manual_approval') } } + }, + FOLLOWINGS: { + INSTANCE: { + AUTO_FOLLOW_BACK: { + get ENABLED () { + return config.get('followings.instance.auto_follow_back.enabled') + } + }, + AUTO_FOLLOW_INDEX: { + get ENABLED () { + return config.get('followings.instance.auto_follow_index.enabled') + }, + get INDEX_URL () { + return config.get('followings.instance.auto_follow_index.index_url') + } + } + } + }, + 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') } } } @@ -220,11 +304,16 @@ function registerConfigChangedHandler (fun: Function) { configChangedHandlers.push(fun) } +function isEmailEnabled () { + return !!CONFIG.SMTP.HOSTNAME && !!CONFIG.SMTP.PORT +} + // --------------------------------------------------------------------------- export { CONFIG, - registerConfigChangedHandler + registerConfigChangedHandler, + isEmailEnabled } // --------------------------------------------------------------------------- @@ -237,10 +326,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 @@ -266,7 +355,7 @@ export function reloadConfig () { function purge () { for (const fileName in require.cache) { - if (-1 === fileName.indexOf(directory())) { + if (fileName.includes(directory()) === false) { continue }