]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/config.ts
Update OpenAPI documentation to include basic playlists and new comment sorting
[github/Chocobozzz/PeerTube.git] / server / controllers / api / config.ts
index 39a124fc5382dd7efa08406a00885f0c6afb10c7..b2f23c1b00977abb39fe90b5832eb2760380666e 100644 (file)
@@ -17,6 +17,7 @@ import { objectConverter } from '../../helpers/core-utils'
 import { CONFIG, reloadConfig } from '../../initializers/config'
 import { PluginManager } from '../../lib/plugins/plugin-manager'
 import { getThemeOrDefault } from '../../lib/plugins/theme-utils'
+import { Hooks } from '@server/lib/plugins/hooks'
 
 const configRouter = express.Router()
 
@@ -47,7 +48,12 @@ configRouter.delete('/custom',
 let serverCommit: string
 
 async function getConfig (req: express.Request, res: express.Response) {
-  const allowed = await isSignupAllowed()
+  const { allowed } = await Hooks.wrapPromiseFun(
+    isSignupAllowed,
+    {},
+    'filter:api.user.signup.allowed.result'
+  )
+
   const allowedForCurrentIP = isSignupAllowedForCurrentIP(req.ip)
   const defaultTheme = getThemeOrDefault(CONFIG.THEME.DEFAULT, DEFAULT_THEME_NAME)
 
@@ -89,6 +95,9 @@ async function getConfig (req: express.Request, res: express.Response) {
       hls: {
         enabled: CONFIG.TRANSCODING.HLS.ENABLED
       },
+      webtorrent: {
+        enabled: CONFIG.TRANSCODING.WEBTORRENT.ENABLED
+      },
       enabledResolutions: getEnabledResolutions()
     },
     import: {
@@ -218,10 +227,40 @@ async function updateCustomConfig (req: express.Request, res: express.Response)
   return res.json(data).end()
 }
 
+function getRegisteredThemes () {
+  return PluginManager.Instance.getRegisteredThemes()
+                      .map(t => ({
+                        name: t.name,
+                        version: t.version,
+                        description: t.description,
+                        css: t.css,
+                        clientScripts: t.clientScripts
+                      }))
+}
+
+function getEnabledResolutions () {
+  return Object.keys(CONFIG.TRANSCODING.RESOLUTIONS)
+               .filter(key => CONFIG.TRANSCODING.ENABLED && CONFIG.TRANSCODING.RESOLUTIONS[ key ] === true)
+               .map(r => parseInt(r, 10))
+}
+
+function getRegisteredPlugins () {
+  return PluginManager.Instance.getRegisteredPlugins()
+                      .map(p => ({
+                        name: p.name,
+                        version: p.version,
+                        description: p.description,
+                        clientScripts: p.clientScripts
+                      }))
+}
+
 // ---------------------------------------------------------------------------
 
 export {
-  configRouter
+  configRouter,
+  getEnabledResolutions,
+  getRegisteredPlugins,
+  getRegisteredThemes
 }
 
 // ---------------------------------------------------------------------------
@@ -291,6 +330,7 @@ function customConfig (): CustomConfig {
       allowAudioFiles: CONFIG.TRANSCODING.ALLOW_AUDIO_FILES,
       threads: CONFIG.TRANSCODING.THREADS,
       resolutions: {
+        '0p': CONFIG.TRANSCODING.RESOLUTIONS[ '0p' ],
         '240p': CONFIG.TRANSCODING.RESOLUTIONS[ '240p' ],
         '360p': CONFIG.TRANSCODING.RESOLUTIONS[ '360p' ],
         '480p': CONFIG.TRANSCODING.RESOLUTIONS[ '480p' ],
@@ -298,6 +338,9 @@ function customConfig (): CustomConfig {
         '1080p': CONFIG.TRANSCODING.RESOLUTIONS[ '1080p' ],
         '2160p': CONFIG.TRANSCODING.RESOLUTIONS[ '2160p' ]
       },
+      webtorrent: {
+        enabled: CONFIG.TRANSCODING.WEBTORRENT.ENABLED
+      },
       hls: {
         enabled: CONFIG.TRANSCODING.HLS.ENABLED
       }
@@ -344,6 +387,7 @@ function convertCustomConfigBody (body: CustomConfig) {
   function keyConverter (k: string) {
     // Transcoding resolutions exception
     if (/^\d{3,4}p$/.exec(k)) return k
+    if (k === '0p') return k
 
     return snakeCase(k)
   }
@@ -356,30 +400,3 @@ function convertCustomConfigBody (body: CustomConfig) {
 
   return objectConverter(body, keyConverter, valueConverter)
 }
-
-function getRegisteredThemes () {
-  return PluginManager.Instance.getRegisteredThemes()
-                      .map(t => ({
-                        name: t.name,
-                        version: t.version,
-                        description: t.description,
-                        css: t.css,
-                        clientScripts: t.clientScripts
-                      }))
-}
-
-function getEnabledResolutions () {
-  return Object.keys(CONFIG.TRANSCODING.RESOLUTIONS)
-               .filter(key => CONFIG.TRANSCODING.ENABLED && CONFIG.TRANSCODING.RESOLUTIONS[ key ] === true)
-               .map(r => parseInt(r, 10))
-}
-
-function getRegisteredPlugins () {
-  return PluginManager.Instance.getRegisteredPlugins()
-                      .map(p => ({
-                        name: p.name,
-                        version: p.version,
-                        description: p.description,
-                        clientScripts: p.clientScripts
-                      }))
-}