X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Finitializers%2Fconfig.ts;h=59a65d6a56cd6ef33583e2cd7684670b5090cb0c;hb=6348fb18840c912e107cfbc0f51d1c440b9c1cba;hp=48e7f7397be50e4d21f7e73a939b96e5b26bde9c;hpb=903353d67a8d0fdda8465ed6c57b77a9a5afbe92;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/initializers/config.ts b/server/initializers/config.ts index 48e7f7397..59a65d6a5 100644 --- a/server/initializers/config.ts +++ b/server/initializers/config.ts @@ -1,12 +1,13 @@ +import bytes from 'bytes' import { IConfig } from 'config' import { dirname, join } from 'path' -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 { decacheModule } from '@server/helpers/decache' import { VideoRedundancyConfigFilter } from '@shared/models/redundancy/video-redundancy-config-filter.type' import { BroadcastMessageLevel } from '@shared/models/server' +import { buildPath, root } from '../../shared/core-utils' +import { VideoPrivacy, VideosRedundancyStrategy } from '../../shared/models' +import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type' +import { parseBytes, parseDurationToMs } from '../helpers/core-utils' // Use a variable to reload the configuration if we need let config: IConfig = require('config') @@ -57,9 +58,45 @@ 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') }, + get DISPLAY_AUTHOR_AVATAR () { return config.get('client.videos.miniature.display_author_avatar') } + }, + RESUMABLE_UPLOAD: { + get MAX_CHUNK_SIZE () { return parseBytes(config.get('client.videos.resumable_upload.max_chunk_size') || 0) } + } + }, + MENU: { + LOGIN: { + get REDIRECT_ON_SINGLE_EXTERNAL_AUTH () { return config.get('client.menu.login.redirect_on_single_external_auth') } + } + } + }, + + DEFAULTS: { + PUBLISH: { + DOWNLOAD_ENABLED: config.get('defaults.publish.download_enabled'), + COMMENTS_ENABLED: config.get('defaults.publish.comments_enabled'), + PRIVACY: config.get('defaults.publish.privacy'), + LICENCE: config.get('defaults.publish.licence') + }, + P2P: { + WEBAPP: { + ENABLED: config.get('defaults.p2p.webapp.enabled') + }, + EMBED: { + ENABLED: config.get('defaults.p2p.embed.enabled') + } + } + }, + STORAGE: { TMP_DIR: buildPath(config.get('storage.tmp')), - AVATARS_DIR: buildPath(config.get('storage.avatars')), + BIN_DIR: buildPath(config.get('storage.bin')), + 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')), @@ -72,6 +109,27 @@ const CONFIG = { 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'), + UPLOAD_ACL: config.get('object_storage.upload_acl'), + 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', WS: config.get('webserver.https') === true ? 'wss' : 'ws', @@ -101,10 +159,10 @@ const CONFIG = { 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') + MAX_FILE_SIZE: bytes.parse(config.get('log.rotation.max_file_size')), + MAX_FILES: config.get('log.rotation.max_files') }, - ANONYMIZE_IP: config.get('log.anonymizeIP'), + ANONYMIZE_IP: config.get('log.anonymize_ip'), LOG_PING_REQUESTS: config.get('log.log_ping_requests'), PRETTIFY_SQL: config.get('log.prettify_sql') }, @@ -133,6 +191,11 @@ const CONFIG = { REPORT_ONLY: config.get('csp.report_only'), REPORT_URI: config.get('csp.report_uri') }, + SECURITY: { + FRAMEGUARD: { + ENABLED: config.get('security.frameguard.enabled') + } + }, TRACKER: { ENABLED: config.get('tracker.enabled'), PRIVATE: config.get('tracker.private'), @@ -147,7 +210,15 @@ const CONFIG = { VIDEOS: { REMOTE: { MAX_AGE: parseDurationToMs(config.get('views.videos.remote.max_age')) - } + }, + LOCAL_BUFFER_UPDATE_INTERVAL: parseDurationToMs(config.get('views.videos.local_buffer_update_interval')), + IP_VIEW_EXPIRATION: parseDurationToMs(config.get('views.videos.ip_view_expiration')) + } + }, + GEO_IP: { + ENABLED: config.get('geo_ip.enabled'), + COUNTRY: { + DATABASE_URL: config.get('geo_ip.country.database_url') } }, PLUGINS: { @@ -169,6 +240,13 @@ const CONFIG = { 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') } }, @@ -179,6 +257,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') }, @@ -190,6 +269,9 @@ const CONFIG = { get VIDEO_QUOTA () { return parseBytes(config.get('user.video_quota')) }, get VIDEO_QUOTA_DAILY () { return parseBytes(config.get('user.video_quota_daily')) } }, + VIDEO_CHANNELS: { + get MAX_PER_USER () { return config.get('video_channels.max_per_user') } + }, TRANSCODING: { get ENABLED () { return config.get('transcoding.enabled') }, get ALLOW_ADDITIONAL_EXTENSIONS () { return config.get('transcoding.allow_additional_extensions') }, @@ -199,6 +281,7 @@ const CONFIG = { get PROFILE () { return config.get('transcoding.profile') }, RESOLUTIONS: { get '0p' () { return config.get('transcoding.resolutions.0p') }, + get '144p' () { return config.get('transcoding.resolutions.144p') }, get '240p' () { return config.get('transcoding.resolutions.240p') }, get '360p' () { return config.get('transcoding.resolutions.360p') }, get '480p' () { return config.get('transcoding.resolutions.480p') }, @@ -223,8 +306,24 @@ const CONFIG = { get ALLOW_REPLAY () { return config.get('live.allow_replay') }, + LATENCY_SETTING: { + get ENABLED () { return config.get('live.latency_setting.enabled') } + }, + RTMP: { - get PORT () { return config.get('live.rtmp.port') } + get ENABLED () { return config.get('live.rtmp.enabled') }, + get PORT () { return config.get('live.rtmp.port') }, + get HOSTNAME () { return config.get('live.rtmp.hostname') }, + get PUBLIC_HOSTNAME () { return config.get('live.rtmp.public_hostname') } + }, + + RTMPS: { + get ENABLED () { return config.get('live.rtmps.enabled') }, + get PORT () { return config.get('live.rtmps.port') }, + get HOSTNAME () { return config.get('live.rtmps.hostname') }, + get PUBLIC_HOSTNAME () { return config.get('live.rtmps.public_hostname') }, + get KEY_FILE () { return config.get('live.rtmps.key_file') }, + get CERT_FILE () { return config.get('live.rtmps.cert_file') } }, TRANSCODING: { @@ -233,6 +332,7 @@ const CONFIG = { get PROFILE () { return config.get('live.transcoding.profile') }, RESOLUTIONS: { + get '144p' () { return config.get('live.transcoding.resolutions.144p') }, 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') }, @@ -243,17 +343,23 @@ const CONFIG = { } } }, + VIDEO_STUDIO: { + get ENABLED () { return config.get('video_studio.enabled') } + }, 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') } - } + + YOUTUBE_DL_RELEASE: { + get URL () { return config.get('import.videos.http.youtube_dl_release.url') }, + get NAME () { return config.get('import.videos.http.youtube_dl_release.name') }, + get PYTHON_PATH () { return config.get('import.videos.http.youtube_dl_release.python_path') } + }, + + get FORCE_IPV4 () { return config.get('import.videos.http.force_ipv4') } }, TORRENT: { get ENABLED () { return config.get('import.videos.torrent.enabled') } @@ -384,14 +490,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[] { @@ -410,24 +524,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.includes(directory()) === false) { + if (directories.some((dir) => fileName.includes(dir)) === false) { continue } delete require.cache[fileName] } - delete require.cache[require.resolve('config')] + decacheModule('config') } purge()