]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/initializers/config.ts
Support RTMPS
[github/Chocobozzz/PeerTube.git] / server / initializers / config.ts
index 5b402dd7432651216aedd92737325c10e834f641..1288768d82b08768739bb9f3b5790cf5654e043c 100644 (file)
@@ -1,12 +1,12 @@
+import bytes from 'bytes'
 import { IConfig } from 'config'
+import decache from 'decache'
 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 { 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'
+import { buildPath, parseBytes, parseDurationToMs, root } from '../helpers/core-utils'
 
 // Use a variable to reload the configuration if we need
 let config: IConfig = require('config')
@@ -20,9 +20,10 @@ const CONFIG = {
     HOSTNAME: config.get<string>('listen.hostname')
   },
   DATABASE: {
-    DBNAME: 'peertube' + config.get<string>('database.suffix'),
+    DBNAME: config.has('database.name') ? config.get<string>('database.name') : 'peertube' + config.get<string>('database.suffix'),
     HOSTNAME: config.get<string>('database.hostname'),
     PORT: config.get<number>('database.port'),
+    SSL: config.get<boolean>('database.ssl'),
     USERNAME: config.get<string>('database.username'),
     PASSWORD: config.get<string>('database.password'),
     POOL: {
@@ -56,9 +57,19 @@ const CONFIG = {
       PREFIX: config.get<string>('email.subject.prefix') + ' '
     }
   },
+
+  CLIENT: {
+    VIDEOS: {
+      MINIATURE: {
+        get PREFER_AUTHOR_DISPLAY_NAME () { return config.get<boolean>('client.videos.miniature.prefer_author_display_name') }
+      }
+    }
+  },
+
   STORAGE: {
     TMP_DIR: buildPath(config.get<string>('storage.tmp')),
-    AVATARS_DIR: buildPath(config.get<string>('storage.avatars')),
+    BIN_DIR: buildPath(config.get<string>('storage.bin')),
+    ACTOR_IMAGES: buildPath(config.get<string>('storage.avatars')),
     LOG_DIR: buildPath(config.get<string>('storage.logs')),
     VIDEOS_DIR: buildPath(config.get<string>('storage.videos')),
     STREAMING_PLAYLISTS_DIR: buildPath(config.get<string>('storage.streaming_playlists')),
@@ -68,7 +79,28 @@ const CONFIG = {
     CAPTIONS_DIR: buildPath(config.get<string>('storage.captions')),
     TORRENTS_DIR: buildPath(config.get<string>('storage.torrents')),
     CACHE_DIR: buildPath(config.get<string>('storage.cache')),
-    PLUGINS_DIR: buildPath(config.get<string>('storage.plugins'))
+    PLUGINS_DIR: buildPath(config.get<string>('storage.plugins')),
+    CLIENT_OVERRIDES_DIR: buildPath(config.get<string>('storage.client_overrides'))
+  },
+  OBJECT_STORAGE: {
+    ENABLED: config.get<boolean>('object_storage.enabled'),
+    MAX_UPLOAD_PART: bytes.parse(config.get<string>('object_storage.max_upload_part')),
+    ENDPOINT: config.get<string>('object_storage.endpoint'),
+    REGION: config.get<string>('object_storage.region'),
+    CREDENTIALS: {
+      ACCESS_KEY_ID: config.get<string>('object_storage.credentials.access_key_id'),
+      SECRET_ACCESS_KEY: config.get<string>('object_storage.credentials.secret_access_key')
+    },
+    VIDEOS: {
+      BUCKET_NAME: config.get<string>('object_storage.videos.bucket_name'),
+      PREFIX: config.get<string>('object_storage.videos.prefix'),
+      BASE_URL: config.get<string>('object_storage.videos.base_url')
+    },
+    STREAMING_PLAYLISTS: {
+      BUCKET_NAME: config.get<string>('object_storage.streaming_playlists.bucket_name'),
+      PREFIX: config.get<string>('object_storage.streaming_playlists.prefix'),
+      BASE_URL: config.get<string>('object_storage.streaming_playlists.base_url')
+    }
   },
   WEBSERVER: {
     SCHEME: config.get<boolean>('webserver.https') === true ? 'https' : 'http',
@@ -99,14 +131,20 @@ const CONFIG = {
     LEVEL: config.get<string>('log.level'),
     ROTATION: {
       ENABLED: config.get<boolean>('log.rotation.enabled'),
-      MAX_FILE_SIZE: bytes.parse(config.get<string>('log.rotation.maxFileSize')),
-      MAX_FILES: config.get<number>('log.rotation.maxFiles')
+      MAX_FILE_SIZE: bytes.parse(config.get<string>('log.rotation.max_file_size')),
+      MAX_FILES: config.get<number>('log.rotation.max_files')
     },
-    ANONYMIZE_IP: config.get<boolean>('log.anonymizeIP')
+    ANONYMIZE_IP: config.get<boolean>('log.anonymize_ip'),
+    LOG_PING_REQUESTS: config.get<boolean>('log.log_ping_requests'),
+    PRETTIFY_SQL: config.get<boolean>('log.prettify_sql')
   },
   TRENDING: {
     VIDEOS: {
-      INTERVAL_DAYS: config.get<number>('trending.videos.interval_days')
+      INTERVAL_DAYS: config.get<number>('trending.videos.interval_days'),
+      ALGORITHMS: {
+        get ENABLED () { return config.get<string[]>('trending.videos.algorithms.enabled') },
+        get DEFAULT () { return config.get<string>('trending.videos.algorithms.default') }
+      }
     }
   },
   REDUNDANCY: {
@@ -123,7 +161,12 @@ const CONFIG = {
   CSP: {
     ENABLED: config.get<boolean>('csp.enabled'),
     REPORT_ONLY: config.get<boolean>('csp.report_only'),
-    REPORT_URI: config.get<boolean>('csp.report_uri')
+    REPORT_URI: config.get<string>('csp.report_uri')
+  },
+  SECURITY: {
+    FRAMEGUARD: {
+      ENABLED: config.get<boolean>('security.frameguard.enabled')
+    }
   },
   TRACKER: {
     ENABLED: config.get<boolean>('tracker.enabled'),
@@ -151,7 +194,21 @@ const CONFIG = {
   },
   FEDERATION: {
     VIDEOS: {
-      FEDERATE_UNLISTED: config.get<boolean>('federation.videos.federate_unlisted')
+      FEDERATE_UNLISTED: config.get<boolean>('federation.videos.federate_unlisted'),
+      CLEANUP_REMOTE_INTERACTIONS: config.get<boolean>('federation.videos.cleanup_remote_interactions')
+    }
+  },
+  PEERTUBE: {
+    CHECK_LATEST_VERSION: {
+      ENABLED: config.get<boolean>('peertube.check_latest_version.enabled'),
+      URL: config.get<string>('peertube.check_latest_version.url')
+    }
+  },
+  WEBADMIN: {
+    CONFIGURATION: {
+      EDITION: {
+        ALLOWED: config.get<boolean>('webadmin.configuration.edition.allowed')
+      }
     }
   },
   ADMIN: {
@@ -164,6 +221,7 @@ const CONFIG = {
     get ENABLED () { return config.get<boolean>('signup.enabled') },
     get LIMIT () { return config.get<number>('signup.limit') },
     get REQUIRES_EMAIL_VERIFICATION () { return config.get<boolean>('signup.requires_email_verification') },
+    get MINIMUM_AGE () { return config.get<number>('signup.minimum_age') },
     FILTERS: {
       CIDR: {
         get WHITELIST () { return config.get<string[]>('signup.filters.cidr.whitelist') },
@@ -175,18 +233,25 @@ const CONFIG = {
     get VIDEO_QUOTA () { return parseBytes(config.get<number>('user.video_quota')) },
     get VIDEO_QUOTA_DAILY () { return parseBytes(config.get<number>('user.video_quota_daily')) }
   },
+  VIDEO_CHANNELS: {
+    get MAX_PER_USER () { return config.get<number>('video_channels.max_per_user') }
+  },
   TRANSCODING: {
     get ENABLED () { return config.get<boolean>('transcoding.enabled') },
     get ALLOW_ADDITIONAL_EXTENSIONS () { return config.get<boolean>('transcoding.allow_additional_extensions') },
     get ALLOW_AUDIO_FILES () { return config.get<boolean>('transcoding.allow_audio_files') },
     get THREADS () { return config.get<number>('transcoding.threads') },
+    get CONCURRENCY () { return config.get<number>('transcoding.concurrency') },
+    get PROFILE () { return config.get<string>('transcoding.profile') },
     RESOLUTIONS: {
       get '0p' () { return config.get<boolean>('transcoding.resolutions.0p') },
+      get '144p' () { return config.get<boolean>('transcoding.resolutions.144p') },
       get '240p' () { return config.get<boolean>('transcoding.resolutions.240p') },
       get '360p' () { return config.get<boolean>('transcoding.resolutions.360p') },
       get '480p' () { return config.get<boolean>('transcoding.resolutions.480p') },
       get '720p' () { return config.get<boolean>('transcoding.resolutions.720p') },
       get '1080p' () { return config.get<boolean>('transcoding.resolutions.1080p') },
+      get '1440p' () { return config.get<boolean>('transcoding.resolutions.1440p') },
       get '2160p' () { return config.get<boolean>('transcoding.resolutions.2160p') }
     },
     HLS: {
@@ -196,14 +261,57 @@ const CONFIG = {
       get ENABLED () { return config.get<boolean>('transcoding.webtorrent.enabled') }
     }
   },
+  LIVE: {
+    get ENABLED () { return config.get<boolean>('live.enabled') },
+
+    get MAX_DURATION () { return parseDurationToMs(config.get<string>('live.max_duration')) },
+    get MAX_INSTANCE_LIVES () { return config.get<number>('live.max_instance_lives') },
+    get MAX_USER_LIVES () { return config.get<number>('live.max_user_lives') },
+
+    get ALLOW_REPLAY () { return config.get<boolean>('live.allow_replay') },
+
+    RTMP: {
+      get ENABLED () { return config.get<boolean>('live.rtmp.enabled') },
+      get PORT () { return config.get<number>('live.rtmp.port') }
+    },
+
+    RTMPS: {
+      get ENABLED () { return config.get<boolean>('live.rtmps.enabled') },
+      get PORT () { return config.get<number>('live.rtmps.port') },
+      get KEY_FILE () { return config.get<string>('live.rtmps.key_file') },
+      get CERT_FILE () { return config.get<string>('live.rtmps.cert_file') }
+    },
+
+    TRANSCODING: {
+      get ENABLED () { return config.get<boolean>('live.transcoding.enabled') },
+      get THREADS () { return config.get<number>('live.transcoding.threads') },
+      get PROFILE () { return config.get<string>('live.transcoding.profile') },
+
+      RESOLUTIONS: {
+        get '144p' () { return config.get<boolean>('live.transcoding.resolutions.144p') },
+        get '240p' () { return config.get<boolean>('live.transcoding.resolutions.240p') },
+        get '360p' () { return config.get<boolean>('live.transcoding.resolutions.360p') },
+        get '480p' () { return config.get<boolean>('live.transcoding.resolutions.480p') },
+        get '720p' () { return config.get<boolean>('live.transcoding.resolutions.720p') },
+        get '1080p' () { return config.get<boolean>('live.transcoding.resolutions.1080p') },
+        get '1440p' () { return config.get<boolean>('live.transcoding.resolutions.1440p') },
+        get '2160p' () { return config.get<boolean>('live.transcoding.resolutions.2160p') }
+      }
+    }
+  },
   IMPORT: {
     VIDEOS: {
+      get CONCURRENCY () { return config.get<number>('import.videos.concurrency') },
+
       HTTP: {
         get ENABLED () { return config.get<boolean>('import.videos.http.enabled') },
-        PROXY: {
-          get ENABLED () { return config.get<boolean>('import.videos.http.proxy.enabled') },
-          get URL () { return config.get<string>('import.videos.http.proxy.url') }
-        }
+
+        YOUTUBE_DL_RELEASE: {
+          get URL () { return config.get<string>('import.videos.http.youtube_dl_release.url') },
+          get NAME () { return config.get<string>('import.videos.http.youtube_dl_release.name') }
+        },
+
+        get FORCE_IPV4 () { return config.get<boolean>('import.videos.http.force_ipv4') }
       },
       TORRENT: {
         get ENABLED () { return config.get<boolean>('import.videos.torrent.enabled') }
@@ -223,6 +331,9 @@ const CONFIG = {
     },
     VIDEO_CAPTIONS: {
       get SIZE () { return config.get<number>('cache.captions.size') }
+    },
+    TORRENTS: {
+      get SIZE () { return config.get<number>('cache.torrents.size') }
     }
   },
   INSTANCE: {
@@ -244,8 +355,10 @@ const CONFIG = {
     get CATEGORIES () { return config.get<number[]>('instance.categories') || [] },
 
     get IS_NSFW () { return config.get<boolean>('instance.is_nsfw') },
-    get DEFAULT_CLIENT_ROUTE () { return config.get<string>('instance.default_client_route') },
     get DEFAULT_NSFW_POLICY () { return config.get<NSFWPolicyType>('instance.default_nsfw_policy') },
+
+    get DEFAULT_CLIENT_ROUTE () { return config.get<string>('instance.default_client_route') },
+
     CUSTOMIZATIONS: {
       get JAVASCRIPT () { return config.get<string>('instance.customizations.javascript') },
       get CSS () { return config.get<string>('instance.customizations.css') }
@@ -294,8 +407,8 @@ const CONFIG = {
   },
   SEARCH: {
     REMOTE_URI: {
-      USERS: config.get<boolean>('search.remote_uri.users'),
-      ANONYMOUS: config.get<boolean>('search.remote_uri.anonymous')
+      get USERS () { return config.get<boolean>('search.remote_uri.users') },
+      get ANONYMOUS () { return config.get<boolean>('search.remote_uri.anonymous') }
     },
     SEARCH_INDEX: {
       get ENABLED () { return config.get<boolean>('search.search_index.enabled') },
@@ -311,7 +424,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
 }
 
 // ---------------------------------------------------------------------------
@@ -325,14 +442,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[] {
@@ -351,24 +476,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')]
+    decache('config')
   }
 
   purge()