WIP plugins: hook on client side
[oweals/peertube.git] / server / controllers / api / config.ts
index cdbccaa7dee4d0f8e4caa72f92b14332e0699791..8563b74370bd3f277d825f98d503e28605e83ac7 100644 (file)
@@ -1,10 +1,10 @@
 import * as express from 'express'
 import { snakeCase } from 'lodash'
-import { ServerConfig, UserRight } from '../../../shared'
+import { ServerConfig, ServerConfigPlugin, UserRight } from '../../../shared'
 import { About } from '../../../shared/models/server/about.model'
 import { CustomConfig } from '../../../shared/models/server/custom-config.model'
 import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/signup'
-import { CONSTRAINTS_FIELDS } from '../../initializers'
+import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
 import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares'
 import { customConfigUpdateValidator } from '../../middlewares/validators/config'
 import { ClientHtml } from '../../lib/client-html'
@@ -15,6 +15,8 @@ import { Emailer } from '../../lib/emailer'
 import { isNumeric } from 'validator'
 import { objectConverter } from '../../helpers/core-utils'
 import { CONFIG, reloadConfig } from '../../initializers/config'
+import { PluginManager } from '../../lib/plugins/plugin-manager'
+import { PluginType } from '../../../shared/models/plugins/plugin.type'
 
 const packageJSON = require('../../../../package.json')
 const configRouter = express.Router()
@@ -51,9 +53,23 @@ async function getConfig (req: express.Request, res: express.Response) {
   if (serverCommit === undefined) serverCommit = await getServerCommit()
 
   const enabledResolutions = Object.keys(CONFIG.TRANSCODING.RESOLUTIONS)
-   .filter(key => CONFIG.TRANSCODING.ENABLED === CONFIG.TRANSCODING.RESOLUTIONS[key] === true)
+   .filter(key => CONFIG.TRANSCODING.ENABLED && CONFIG.TRANSCODING.RESOLUTIONS[key] === true)
    .map(r => parseInt(r, 10))
 
+  const plugins: ServerConfigPlugin[] = []
+  const registeredPlugins = PluginManager.Instance.getRegisteredPlugins()
+  for (const pluginName of Object.keys(registeredPlugins)) {
+    const plugin = registeredPlugins[ pluginName ]
+    if (plugin.type !== PluginType.PLUGIN) continue
+
+    plugins.push({
+      name: plugin.name,
+      version: plugin.version,
+      description: plugin.description,
+      clientScripts: plugin.clientScripts
+    })
+  }
+
   const json: ServerConfig = {
     instance: {
       name: CONFIG.INSTANCE.NAME,
@@ -66,6 +82,7 @@ async function getConfig (req: express.Request, res: express.Response) {
         css: CONFIG.INSTANCE.CUSTOMIZATIONS.CSS
       }
     },
+    plugins,
     email: {
       enabled: Emailer.isEnabled()
     },
@@ -255,13 +272,15 @@ function customConfig (): CustomConfig {
     transcoding: {
       enabled: CONFIG.TRANSCODING.ENABLED,
       allowAdditionalExtensions: CONFIG.TRANSCODING.ALLOW_ADDITIONAL_EXTENSIONS,
+      allowAudioFiles: CONFIG.TRANSCODING.ALLOW_AUDIO_FILES,
       threads: CONFIG.TRANSCODING.THREADS,
       resolutions: {
         '240p': CONFIG.TRANSCODING.RESOLUTIONS[ '240p' ],
         '360p': CONFIG.TRANSCODING.RESOLUTIONS[ '360p' ],
         '480p': CONFIG.TRANSCODING.RESOLUTIONS[ '480p' ],
         '720p': CONFIG.TRANSCODING.RESOLUTIONS[ '720p' ],
-        '1080p': CONFIG.TRANSCODING.RESOLUTIONS[ '1080p' ]
+        '1080p': CONFIG.TRANSCODING.RESOLUTIONS[ '1080p' ],
+        '2160p': CONFIG.TRANSCODING.RESOLUTIONS[ '2160p' ]
       },
       hls: {
         enabled: CONFIG.TRANSCODING.HLS.ENABLED