aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/plugins/plugin-manager.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-07-11 14:40:19 +0200
committerChocobozzz <chocobozzz@cpy.re>2019-07-24 10:58:16 +0200
commitdba85a1e9e9f603ba52e1ea42deaf3fdd799b1d8 (patch)
tree7695023d90b78f972abafc718346c50264587ff5 /server/lib/plugins/plugin-manager.ts
parentd00dc28dd73ad9dd419d5a5ac6ac747cefbc6e8b (diff)
downloadPeerTube-dba85a1e9e9f603ba52e1ea42deaf3fdd799b1d8.tar.gz
PeerTube-dba85a1e9e9f603ba52e1ea42deaf3fdd799b1d8.tar.zst
PeerTube-dba85a1e9e9f603ba52e1ea42deaf3fdd799b1d8.zip
WIP plugins: add plugin settings/uninstall in client
Diffstat (limited to 'server/lib/plugins/plugin-manager.ts')
-rw-r--r--server/lib/plugins/plugin-manager.ts25
1 files changed, 12 insertions, 13 deletions
diff --git a/server/lib/plugins/plugin-manager.ts b/server/lib/plugins/plugin-manager.ts
index 3d8375acd..8cdeff446 100644
--- a/server/lib/plugins/plugin-manager.ts
+++ b/server/lib/plugins/plugin-manager.ts
@@ -89,6 +89,8 @@ export class PluginManager {
89 async runHook (hookName: string, param?: any) { 89 async runHook (hookName: string, param?: any) {
90 let result = param 90 let result = param
91 91
92 if (!this.hooks[hookName]) return result
93
92 const wait = hookName.startsWith('static:') 94 const wait = hookName.startsWith('static:')
93 95
94 for (const hook of this.hooks[hookName]) { 96 for (const hook of this.hooks[hookName]) {
@@ -162,8 +164,8 @@ export class PluginManager {
162 : await installNpmPlugin(toInstall, version) 164 : await installNpmPlugin(toInstall, version)
163 165
164 name = fromDisk ? basename(toInstall) : toInstall 166 name = fromDisk ? basename(toInstall) : toInstall
165 const pluginType = name.startsWith('peertube-theme-') ? PluginType.THEME : PluginType.PLUGIN 167 const pluginType = PluginModel.getTypeFromNpmName(name)
166 const pluginName = this.normalizePluginName(name) 168 const pluginName = PluginModel.normalizePluginName(name)
167 169
168 const packageJSON = this.getPackageJSON(pluginName, pluginType) 170 const packageJSON = this.getPackageJSON(pluginName, pluginType)
169 if (!isPackageJSONValid(packageJSON, pluginType)) { 171 if (!isPackageJSONValid(packageJSON, pluginType)) {
@@ -173,6 +175,7 @@ export class PluginManager {
173 [ plugin ] = await PluginModel.upsert({ 175 [ plugin ] = await PluginModel.upsert({
174 name: pluginName, 176 name: pluginName,
175 description: packageJSON.description, 177 description: packageJSON.description,
178 homepage: packageJSON.homepage,
176 type: pluginType, 179 type: pluginType,
177 version: packageJSON.version, 180 version: packageJSON.version,
178 enabled: true, 181 enabled: true,
@@ -196,10 +199,10 @@ export class PluginManager {
196 await this.registerPluginOrTheme(plugin) 199 await this.registerPluginOrTheme(plugin)
197 } 200 }
198 201
199 async uninstall (packageName: string) { 202 async uninstall (npmName: string) {
200 logger.info('Uninstalling plugin %s.', packageName) 203 logger.info('Uninstalling plugin %s.', npmName)
201 204
202 const pluginName = this.normalizePluginName(packageName) 205 const pluginName = PluginModel.normalizePluginName(npmName)
203 206
204 try { 207 try {
205 await this.unregister(pluginName) 208 await this.unregister(pluginName)
@@ -207,9 +210,9 @@ export class PluginManager {
207 logger.warn('Cannot unregister plugin %s.', pluginName, { err }) 210 logger.warn('Cannot unregister plugin %s.', pluginName, { err })
208 } 211 }
209 212
210 const plugin = await PluginModel.load(pluginName) 213 const plugin = await PluginModel.loadByNpmName(npmName)
211 if (!plugin || plugin.uninstalled === true) { 214 if (!plugin || plugin.uninstalled === true) {
212 logger.error('Cannot uninstall plugin %s: it does not exist or is already uninstalled.', packageName) 215 logger.error('Cannot uninstall plugin %s: it does not exist or is already uninstalled.', npmName)
213 return 216 return
214 } 217 }
215 218
@@ -218,9 +221,9 @@ export class PluginManager {
218 221
219 await plugin.save() 222 await plugin.save()
220 223
221 await removeNpmPlugin(packageName) 224 await removeNpmPlugin(npmName)
222 225
223 logger.info('Plugin %s uninstalled.', packageName) 226 logger.info('Plugin %s uninstalled.', npmName)
224 } 227 }
225 228
226 // ###################### Private register ###################### 229 // ###################### Private register ######################
@@ -353,10 +356,6 @@ export class PluginManager {
353 return join(CONFIG.STORAGE.PLUGINS_DIR, 'node_modules', prefix + pluginName) 356 return join(CONFIG.STORAGE.PLUGINS_DIR, 'node_modules', prefix + pluginName)
354 } 357 }
355 358
356 private normalizePluginName (name: string) {
357 return name.replace(/^peertube-((theme)|(plugin))-/, '')
358 }
359
360 // ###################### Private getters ###################### 359 // ###################### Private getters ######################
361 360
362 private getRegisteredPluginsOrThemes (type: PluginType) { 361 private getRegisteredPluginsOrThemes (type: PluginType) {