+ private async regeneratePluginGlobalCSS () {
+ await this.resetCSSGlobalFile()
+
+ for (const key of Object.keys(this.getRegisteredPlugins())) {
+ const plugin = this.registeredPlugins[key]
+
+ await this.addCSSToGlobalFile(plugin.path, plugin.css)
+ }
+ }
+
+ // ###################### Utils ######################
+
+ private sortHooksByPriority () {
+ for (const hookName of Object.keys(this.hooks)) {
+ this.hooks[hookName].sort((a, b) => {
+ return b.priority - a.priority
+ })
+ }
+ }
+
+ private getPackageJSON (pluginName: string, pluginType: PluginType) {
+ const pluginPath = join(this.getPluginPath(pluginName, pluginType), 'package.json')
+
+ return readJSON(pluginPath) as Promise<PluginPackageJson>
+ }
+
+ private getPluginPath (pluginName: string, pluginType: PluginType) {
+ const npmName = PluginModel.buildNpmName(pluginName, pluginType)
+
+ return join(CONFIG.STORAGE.PLUGINS_DIR, 'node_modules', npmName)
+ }
+
+ // ###################### Private getters ######################
+
+ private getRegisteredPluginsOrThemes (type: PluginType) {
+ const plugins: RegisteredPlugin[] = []
+
+ for (const npmName of Object.keys(this.registeredPlugins)) {
+ const plugin = this.registeredPlugins[ npmName ]
+ if (plugin.type !== type) continue
+
+ plugins.push(plugin)
+ }
+
+ return plugins
+ }
+
+ // ###################### Generate register helpers ######################
+
+ private getRegisterHelpers (npmName: string, plugin: PluginModel): RegisterOptions {
+ const registerHook = (options: RegisterHookOptions) => {
+ if (serverHookObject[options.target] !== true) {
+ logger.warn('Unknown hook %s of plugin %s. Skipping.', options.target, npmName)
+ return
+ }
+
+ if (!this.hooks[options.target]) this.hooks[options.target] = []
+
+ this.hooks[options.target].push({
+ npmName,
+ pluginName: plugin.name,
+ handler: options.handler,
+ priority: options.priority || 0
+ })
+ }
+
+ const registerSetting = (options: RegisterSettingOptions) => {
+ if (!this.settings[npmName]) this.settings[npmName] = []
+
+ this.settings[npmName].push(options)
+ }
+
+ const settingsManager: PluginSettingsManager = {
+ getSetting: (name: string) => PluginModel.getSetting(plugin.name, plugin.type, name),
+
+ setSetting: (name: string, value: string) => PluginModel.setSetting(plugin.name, plugin.type, name, value)
+ }
+
+ const storageManager: PluginStorageManager = {
+ getData: (key: string) => PluginModel.getData(plugin.name, plugin.type, key),
+
+ storeData: (key: string, data: any) => PluginModel.storeData(plugin.name, plugin.type, key, data)
+ }
+
+ const peertubeHelpers = {
+ logger
+ }
+
+ return {
+ registerHook,
+ registerSetting,
+ settingsManager,
+ storageManager,
+ peertubeHelpers
+ }
+ }
+