aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/plugins/plugin-manager.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/plugins/plugin-manager.ts')
-rw-r--r--server/lib/plugins/plugin-manager.ts35
1 files changed, 18 insertions, 17 deletions
diff --git a/server/lib/plugins/plugin-manager.ts b/server/lib/plugins/plugin-manager.ts
index 8e7491257..c19b40135 100644
--- a/server/lib/plugins/plugin-manager.ts
+++ b/server/lib/plugins/plugin-manager.ts
@@ -20,7 +20,7 @@ import { PLUGIN_GLOBAL_CSS_PATH } from '../../initializers/constants'
20import { PluginModel } from '../../models/server/plugin' 20import { PluginModel } from '../../models/server/plugin'
21import { PluginLibrary, RegisterServerAuthExternalOptions, RegisterServerAuthPassOptions, RegisterServerOptions } from '../../types/plugins' 21import { PluginLibrary, RegisterServerAuthExternalOptions, RegisterServerAuthPassOptions, RegisterServerOptions } from '../../types/plugins'
22import { ClientHtml } from '../client-html' 22import { ClientHtml } from '../client-html'
23import { RegisterHelpersStore } from './register-helpers-store' 23import { RegisterHelpers } from './register-helpers'
24import { installNpmPlugin, installNpmPluginFromDisk, removeNpmPlugin } from './yarn' 24import { installNpmPlugin, installNpmPluginFromDisk, removeNpmPlugin } from './yarn'
25 25
26export interface RegisteredPlugin { 26export interface RegisteredPlugin {
@@ -40,7 +40,7 @@ export interface RegisteredPlugin {
40 css: string[] 40 css: string[]
41 41
42 // Only if this is a plugin 42 // Only if this is a plugin
43 registerHelpersStore?: RegisterHelpersStore 43 registerHelpers?: RegisterHelpers
44 unregister?: Function 44 unregister?: Function
45} 45}
46 46
@@ -109,7 +109,7 @@ export class PluginManager implements ServerHook {
109 npmName: p.npmName, 109 npmName: p.npmName,
110 name: p.name, 110 name: p.name,
111 version: p.version, 111 version: p.version,
112 idAndPassAuths: p.registerHelpersStore.getIdAndPassAuths() 112 idAndPassAuths: p.registerHelpers.getIdAndPassAuths()
113 })) 113 }))
114 .filter(v => v.idAndPassAuths.length !== 0) 114 .filter(v => v.idAndPassAuths.length !== 0)
115 } 115 }
@@ -120,7 +120,7 @@ export class PluginManager implements ServerHook {
120 npmName: p.npmName, 120 npmName: p.npmName,
121 name: p.name, 121 name: p.name,
122 version: p.version, 122 version: p.version,
123 externalAuths: p.registerHelpersStore.getExternalAuths() 123 externalAuths: p.registerHelpers.getExternalAuths()
124 })) 124 }))
125 .filter(v => v.externalAuths.length !== 0) 125 .filter(v => v.externalAuths.length !== 0)
126 } 126 }
@@ -129,14 +129,14 @@ export class PluginManager implements ServerHook {
129 const result = this.getRegisteredPluginOrTheme(npmName) 129 const result = this.getRegisteredPluginOrTheme(npmName)
130 if (!result || result.type !== PluginType.PLUGIN) return [] 130 if (!result || result.type !== PluginType.PLUGIN) return []
131 131
132 return result.registerHelpersStore.getSettings() 132 return result.registerHelpers.getSettings()
133 } 133 }
134 134
135 getRouter (npmName: string) { 135 getRouter (npmName: string) {
136 const result = this.getRegisteredPluginOrTheme(npmName) 136 const result = this.getRegisteredPluginOrTheme(npmName)
137 if (!result || result.type !== PluginType.PLUGIN) return null 137 if (!result || result.type !== PluginType.PLUGIN) return null
138 138
139 return result.registerHelpersStore.getRouter() 139 return result.registerHelpers.getRouter()
140 } 140 }
141 141
142 getTranslations (locale: string) { 142 getTranslations (locale: string) {
@@ -194,7 +194,7 @@ export class PluginManager implements ServerHook {
194 logger.error('Cannot find plugin %s to call on settings changed.', name) 194 logger.error('Cannot find plugin %s to call on settings changed.', name)
195 } 195 }
196 196
197 for (const cb of registered.registerHelpersStore.getOnSettingsChangedCallbacks()) { 197 for (const cb of registered.registerHelpers.getOnSettingsChangedCallbacks()) {
198 try { 198 try {
199 cb(settings) 199 cb(settings)
200 } catch (err) { 200 } catch (err) {
@@ -268,8 +268,9 @@ export class PluginManager implements ServerHook {
268 this.hooks[key] = this.hooks[key].filter(h => h.npmName !== npmName) 268 this.hooks[key] = this.hooks[key].filter(h => h.npmName !== npmName)
269 } 269 }
270 270
271 const store = plugin.registerHelpersStore 271 const store = plugin.registerHelpers
272 store.reinitVideoConstants(plugin.npmName) 272 store.reinitVideoConstants(plugin.npmName)
273 store.reinitTranscodingProfilesAndEncoders(plugin.npmName)
273 274
274 logger.info('Regenerating registered plugin CSS to global file.') 275 logger.info('Regenerating registered plugin CSS to global file.')
275 await this.regeneratePluginGlobalCSS() 276 await this.regeneratePluginGlobalCSS()
@@ -375,11 +376,11 @@ export class PluginManager implements ServerHook {
375 this.sanitizeAndCheckPackageJSONOrThrow(packageJSON, plugin.type) 376 this.sanitizeAndCheckPackageJSONOrThrow(packageJSON, plugin.type)
376 377
377 let library: PluginLibrary 378 let library: PluginLibrary
378 let registerHelpersStore: RegisterHelpersStore 379 let registerHelpers: RegisterHelpers
379 if (plugin.type === PluginType.PLUGIN) { 380 if (plugin.type === PluginType.PLUGIN) {
380 const result = await this.registerPlugin(plugin, pluginPath, packageJSON) 381 const result = await this.registerPlugin(plugin, pluginPath, packageJSON)
381 library = result.library 382 library = result.library
382 registerHelpersStore = result.registerStore 383 registerHelpers = result.registerStore
383 } 384 }
384 385
385 const clientScripts: { [id: string]: ClientScript } = {} 386 const clientScripts: { [id: string]: ClientScript } = {}
@@ -398,7 +399,7 @@ export class PluginManager implements ServerHook {
398 staticDirs: packageJSON.staticDirs, 399 staticDirs: packageJSON.staticDirs,
399 clientScripts, 400 clientScripts,
400 css: packageJSON.css, 401 css: packageJSON.css,
401 registerHelpersStore: registerHelpersStore || undefined, 402 registerHelpers: registerHelpers || undefined,
402 unregister: library ? library.unregister : undefined 403 unregister: library ? library.unregister : undefined
403 } 404 }
404 405
@@ -512,8 +513,8 @@ export class PluginManager implements ServerHook {
512 const plugin = this.getRegisteredPluginOrTheme(npmName) 513 const plugin = this.getRegisteredPluginOrTheme(npmName)
513 if (!plugin || plugin.type !== PluginType.PLUGIN) return null 514 if (!plugin || plugin.type !== PluginType.PLUGIN) return null
514 515
515 let auths: (RegisterServerAuthPassOptions | RegisterServerAuthExternalOptions)[] = plugin.registerHelpersStore.getIdAndPassAuths() 516 let auths: (RegisterServerAuthPassOptions | RegisterServerAuthExternalOptions)[] = plugin.registerHelpers.getIdAndPassAuths()
516 auths = auths.concat(plugin.registerHelpersStore.getExternalAuths()) 517 auths = auths.concat(plugin.registerHelpers.getExternalAuths())
517 518
518 return auths.find(a => a.authName === authName) 519 return auths.find(a => a.authName === authName)
519 } 520 }
@@ -538,7 +539,7 @@ export class PluginManager implements ServerHook {
538 private getRegisterHelpers ( 539 private getRegisterHelpers (
539 npmName: string, 540 npmName: string,
540 plugin: PluginModel 541 plugin: PluginModel
541 ): { registerStore: RegisterHelpersStore, registerOptions: RegisterServerOptions } { 542 ): { registerStore: RegisterHelpers, registerOptions: RegisterServerOptions } {
542 const onHookAdded = (options: RegisterServerHookOptions) => { 543 const onHookAdded = (options: RegisterServerHookOptions) => {
543 if (!this.hooks[options.target]) this.hooks[options.target] = [] 544 if (!this.hooks[options.target]) this.hooks[options.target] = []
544 545
@@ -550,11 +551,11 @@ export class PluginManager implements ServerHook {
550 }) 551 })
551 } 552 }
552 553
553 const registerHelpersStore = new RegisterHelpersStore(npmName, plugin, onHookAdded.bind(this)) 554 const registerHelpers = new RegisterHelpers(npmName, plugin, onHookAdded.bind(this))
554 555
555 return { 556 return {
556 registerStore: registerHelpersStore, 557 registerStore: registerHelpers,
557 registerOptions: registerHelpersStore.buildRegisterHelpers() 558 registerOptions: registerHelpers.buildRegisterHelpers()
558 } 559 }
559 } 560 }
560 561