]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/config.ts
Add plugin translation system
[github/Chocobozzz/PeerTube.git] / server / controllers / api / config.ts
index 8563b74370bd3f277d825f98d503e28605e83ac7..21fa85a085a3ece6acbd41bf74a433f2f0ddfdfd 100644 (file)
@@ -1,10 +1,10 @@
 import * as express from 'express'
 import { snakeCase } from 'lodash'
-import { ServerConfig, ServerConfigPlugin, UserRight } from '../../../shared'
+import { ServerConfig, 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/constants'
+import { CONSTRAINTS_FIELDS, DEFAULT_THEME_NAME, PEERTUBE_VERSION } from '../../initializers/constants'
 import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares'
 import { customConfigUpdateValidator } from '../../middlewares/validators/config'
 import { ClientHtml } from '../../lib/client-html'
@@ -16,9 +16,8 @@ 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'
+import { getThemeOrDefault } from '../../lib/plugins/theme-utils'
 
-const packageJSON = require('../../../../package.json')
 const configRouter = express.Router()
 
 const auditLogger = auditLoggerFactory('config')
@@ -46,30 +45,14 @@ configRouter.delete('/custom',
 )
 
 let serverCommit: string
+
 async function getConfig (req: express.Request, res: express.Response) {
   const allowed = await isSignupAllowed()
   const allowedForCurrentIP = isSignupAllowedForCurrentIP(req.ip)
+  const defaultTheme = getThemeOrDefault(CONFIG.THEME.DEFAULT, DEFAULT_THEME_NAME)
 
   if (serverCommit === undefined) serverCommit = await getServerCommit()
 
-  const enabledResolutions = Object.keys(CONFIG.TRANSCODING.RESOLUTIONS)
-   .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,
@@ -82,14 +65,20 @@ async function getConfig (req: express.Request, res: express.Response) {
         css: CONFIG.INSTANCE.CUSTOMIZATIONS.CSS
       }
     },
-    plugins,
+    plugin: {
+      registered: getRegisteredPlugins()
+    },
+    theme: {
+      registered: getRegisteredThemes(),
+      default: defaultTheme
+    },
     email: {
       enabled: Emailer.isEnabled()
     },
     contactForm: {
       enabled: CONFIG.CONTACT_FORM.ENABLED
     },
-    serverVersion: packageJSON.version,
+    serverVersion: PEERTUBE_VERSION,
     serverCommit,
     signup: {
       allowed,
@@ -100,7 +89,7 @@ async function getConfig (req: express.Request, res: express.Response) {
       hls: {
         enabled: CONFIG.TRANSCODING.HLS.ENABLED
       },
-      enabledResolutions
+      enabledResolutions: getEnabledResolutions()
     },
     import: {
       videos: {
@@ -240,6 +229,9 @@ function customConfig (): CustomConfig {
         javascript: CONFIG.INSTANCE.CUSTOMIZATIONS.JAVASCRIPT
       }
     },
+    theme: {
+      default: CONFIG.THEME.DEFAULT
+    },
     services: {
       twitter: {
         username: CONFIG.SERVICES.TWITTER.USERNAME,
@@ -328,3 +320,30 @@ 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
+                      }))
+}