aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/config.ts19
-rw-r--r--server/lib/plugins/plugin-manager.ts21
2 files changed, 39 insertions, 1 deletions
diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts
index 1d12f701b..8563b7437 100644
--- a/server/controllers/api/config.ts
+++ b/server/controllers/api/config.ts
@@ -1,6 +1,6 @@
1import * as express from 'express' 1import * as express from 'express'
2import { snakeCase } from 'lodash' 2import { snakeCase } from 'lodash'
3import { ServerConfig, UserRight } from '../../../shared' 3import { ServerConfig, ServerConfigPlugin, UserRight } from '../../../shared'
4import { About } from '../../../shared/models/server/about.model' 4import { About } from '../../../shared/models/server/about.model'
5import { CustomConfig } from '../../../shared/models/server/custom-config.model' 5import { CustomConfig } from '../../../shared/models/server/custom-config.model'
6import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/signup' 6import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/signup'
@@ -15,6 +15,8 @@ import { Emailer } from '../../lib/emailer'
15import { isNumeric } from 'validator' 15import { isNumeric } from 'validator'
16import { objectConverter } from '../../helpers/core-utils' 16import { objectConverter } from '../../helpers/core-utils'
17import { CONFIG, reloadConfig } from '../../initializers/config' 17import { CONFIG, reloadConfig } from '../../initializers/config'
18import { PluginManager } from '../../lib/plugins/plugin-manager'
19import { PluginType } from '../../../shared/models/plugins/plugin.type'
18 20
19const packageJSON = require('../../../../package.json') 21const packageJSON = require('../../../../package.json')
20const configRouter = express.Router() 22const configRouter = express.Router()
@@ -54,6 +56,20 @@ async function getConfig (req: express.Request, res: express.Response) {
54 .filter(key => CONFIG.TRANSCODING.ENABLED && CONFIG.TRANSCODING.RESOLUTIONS[key] === true) 56 .filter(key => CONFIG.TRANSCODING.ENABLED && CONFIG.TRANSCODING.RESOLUTIONS[key] === true)
55 .map(r => parseInt(r, 10)) 57 .map(r => parseInt(r, 10))
56 58
59 const plugins: ServerConfigPlugin[] = []
60 const registeredPlugins = PluginManager.Instance.getRegisteredPlugins()
61 for (const pluginName of Object.keys(registeredPlugins)) {
62 const plugin = registeredPlugins[ pluginName ]
63 if (plugin.type !== PluginType.PLUGIN) continue
64
65 plugins.push({
66 name: plugin.name,
67 version: plugin.version,
68 description: plugin.description,
69 clientScripts: plugin.clientScripts
70 })
71 }
72
57 const json: ServerConfig = { 73 const json: ServerConfig = {
58 instance: { 74 instance: {
59 name: CONFIG.INSTANCE.NAME, 75 name: CONFIG.INSTANCE.NAME,
@@ -66,6 +82,7 @@ async function getConfig (req: express.Request, res: express.Response) {
66 css: CONFIG.INSTANCE.CUSTOMIZATIONS.CSS 82 css: CONFIG.INSTANCE.CUSTOMIZATIONS.CSS
67 } 83 }
68 }, 84 },
85 plugins,
69 email: { 86 email: {
70 enabled: Emailer.isEnabled() 87 enabled: Emailer.isEnabled()
71 }, 88 },
diff --git a/server/lib/plugins/plugin-manager.ts b/server/lib/plugins/plugin-manager.ts
index b898e64fa..7cbfa8569 100644
--- a/server/lib/plugins/plugin-manager.ts
+++ b/server/lib/plugins/plugin-manager.ts
@@ -75,6 +75,27 @@ export class PluginManager {
75 return registered 75 return registered
76 } 76 }
77 77
78 getRegisteredPlugins () {
79 return this.registeredPlugins
80 }
81
82 async runHook (hookName: string, param?: any) {
83 let result = param
84
85 const wait = hookName.startsWith('static:')
86
87 for (const hook of this.hooks[hookName]) {
88 try {
89 if (wait) result = await hook.handler(param)
90 else result = hook.handler()
91 } catch (err) {
92 logger.error('Cannot run hook %s of plugin %s.', hookName, hook.pluginName, { err })
93 }
94 }
95
96 return result
97 }
98
78 async unregister (name: string) { 99 async unregister (name: string) {
79 const plugin = this.getRegisteredPlugin(name) 100 const plugin = this.getRegisteredPlugin(name)
80 101