aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/root-helpers/plugins.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/root-helpers/plugins.ts')
-rw-r--r--client/src/root-helpers/plugins.ts41
1 files changed, 37 insertions, 4 deletions
diff --git a/client/src/root-helpers/plugins.ts b/client/src/root-helpers/plugins.ts
index 011721761..4bc2c8eb2 100644
--- a/client/src/root-helpers/plugins.ts
+++ b/client/src/root-helpers/plugins.ts
@@ -1,6 +1,14 @@
1import { getHookType, internalRunHook } from '@shared/core-utils/plugins/hooks'
2import { ClientHookName, ClientScript, RegisterClientHookOptions, ServerConfigPlugin, PluginType, clientHookObject } from '../../../shared/models'
3import { RegisterClientHelpers } from 'src/types/register-client-option.model' 1import { RegisterClientHelpers } from 'src/types/register-client-option.model'
2import { getHookType, internalRunHook } from '@shared/core-utils/plugins/hooks'
3import { RegisterClientFormFieldOptions, RegisterClientVideoFieldOptions } from '@shared/models/plugins/register-client-form-field.model'
4import {
5 ClientHookName,
6 clientHookObject,
7 ClientScript,
8 PluginType,
9 RegisterClientHookOptions,
10 ServerConfigPlugin
11} from '../../../shared/models'
4import { ClientScript as ClientScriptModule } from '../types/client-script.model' 12import { ClientScript as ClientScriptModule } from '../types/client-script.model'
5import { importModule } from './utils' 13import { importModule } from './utils'
6 14
@@ -18,6 +26,13 @@ type PluginInfo = {
18 isTheme: boolean 26 isTheme: boolean
19} 27}
20 28
29type FormFields = {
30 video: {
31 commonOptions: RegisterClientFormFieldOptions
32 videoFormOptions: RegisterClientVideoFieldOptions
33 }[]
34}
35
21async function runHook<T> (hooks: Hooks, hookName: ClientHookName, result?: T, params?: any) { 36async function runHook<T> (hooks: Hooks, hookName: ClientHookName, result?: T, params?: any) {
22 if (!hooks[hookName]) return result 37 if (!hooks[hookName]) return result
23 38
@@ -34,7 +49,13 @@ async function runHook<T> (hooks: Hooks, hookName: ClientHookName, result?: T, p
34 return result 49 return result
35} 50}
36 51
37function loadPlugin (hooks: Hooks, pluginInfo: PluginInfo, peertubeHelpersFactory: (pluginInfo: PluginInfo) => RegisterClientHelpers) { 52function loadPlugin (options: {
53 hooks: Hooks
54 pluginInfo: PluginInfo
55 peertubeHelpersFactory: (pluginInfo: PluginInfo) => RegisterClientHelpers
56 formFields?: FormFields
57}) {
58 const { hooks, pluginInfo, peertubeHelpersFactory, formFields } = options
38 const { plugin, clientScript } = pluginInfo 59 const { plugin, clientScript } = pluginInfo
39 60
40 const registerHook = (options: RegisterClientHookOptions) => { 61 const registerHook = (options: RegisterClientHookOptions) => {
@@ -54,12 +75,23 @@ function loadPlugin (hooks: Hooks, pluginInfo: PluginInfo, peertubeHelpersFactor
54 }) 75 })
55 } 76 }
56 77
78 const registerVideoField = (commonOptions: RegisterClientFormFieldOptions, videoFormOptions: RegisterClientVideoFieldOptions) => {
79 if (!formFields) {
80 throw new Error('Video field registration is not supported')
81 }
82
83 formFields.video.push({
84 commonOptions,
85 videoFormOptions
86 })
87 }
88
57 const peertubeHelpers = peertubeHelpersFactory(pluginInfo) 89 const peertubeHelpers = peertubeHelpersFactory(pluginInfo)
58 90
59 console.log('Loading script %s of plugin %s.', clientScript.script, plugin.name) 91 console.log('Loading script %s of plugin %s.', clientScript.script, plugin.name)
60 92
61 return importModule(clientScript.script) 93 return importModule(clientScript.script)
62 .then((script: ClientScriptModule) => script.register({ registerHook, peertubeHelpers })) 94 .then((script: ClientScriptModule) => script.register({ registerHook, registerVideoField, peertubeHelpers }))
63 .then(() => sortHooksByPriority(hooks)) 95 .then(() => sortHooksByPriority(hooks))
64 .catch(err => console.error('Cannot import or register plugin %s.', pluginInfo.plugin.name, err)) 96 .catch(err => console.error('Cannot import or register plugin %s.', pluginInfo.plugin.name, err))
65} 97}
@@ -68,6 +100,7 @@ export {
68 HookStructValue, 100 HookStructValue,
69 Hooks, 101 Hooks,
70 PluginInfo, 102 PluginInfo,
103 FormFields,
71 loadPlugin, 104 loadPlugin,
72 runHook 105 runHook
73} 106}