aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/plugins
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-04-12 10:10:48 +0200
committerChocobozzz <me@florianbigard.com>2021-04-12 10:10:48 +0200
commit8280d0c22797c72978f698dc2deaa8ef569a9d15 (patch)
tree8136abd28c9aa0c5050bb66e2f6f7451117b57f2 /server/lib/plugins
parent90aa0a74e95d390d62942aa72d481d5aa7b5ac23 (diff)
downloadPeerTube-8280d0c22797c72978f698dc2deaa8ef569a9d15.tar.gz
PeerTube-8280d0c22797c72978f698dc2deaa8ef569a9d15.tar.zst
PeerTube-8280d0c22797c72978f698dc2deaa8ef569a9d15.zip
Ensure to install supported plugins
Diffstat (limited to 'server/lib/plugins')
-rw-r--r--server/lib/plugins/plugin-index.ts12
-rw-r--r--server/lib/plugins/plugin-manager.ts9
-rw-r--r--server/lib/plugins/yarn.ts13
3 files changed, 28 insertions, 6 deletions
diff --git a/server/lib/plugins/plugin-index.ts b/server/lib/plugins/plugin-index.ts
index 624f5da1d..165bc91b3 100644
--- a/server/lib/plugins/plugin-index.ts
+++ b/server/lib/plugins/plugin-index.ts
@@ -67,7 +67,19 @@ async function getLatestPluginsVersion (npmNames: string[]): Promise<PeertubePlu
67 return body 67 return body
68} 68}
69 69
70async function getLatestPluginVersion (npmName: string) {
71 const results = await getLatestPluginsVersion([ npmName ])
72
73 if (Array.isArray(results) === false || results.length !== 1) {
74 logger.warn('Cannot get latest supported plugin version of %s.', npmName)
75 return undefined
76 }
77
78 return results[0].latestVersion
79}
80
70export { 81export {
71 listAvailablePluginsFromIndex, 82 listAvailablePluginsFromIndex,
83 getLatestPluginVersion,
72 getLatestPluginsVersion 84 getLatestPluginsVersion
73} 85}
diff --git a/server/lib/plugins/plugin-manager.ts b/server/lib/plugins/plugin-manager.ts
index e3226a950..03ea48416 100644
--- a/server/lib/plugins/plugin-manager.ts
+++ b/server/lib/plugins/plugin-manager.ts
@@ -328,11 +328,18 @@ export class PluginManager implements ServerHook {
328 return plugin 328 return plugin
329 } 329 }
330 330
331 async update (toUpdate: string, version?: string, fromDisk = false) { 331 async update (toUpdate: string, fromDisk = false) {
332 const npmName = fromDisk ? basename(toUpdate) : toUpdate 332 const npmName = fromDisk ? basename(toUpdate) : toUpdate
333 333
334 logger.info('Updating plugin %s.', npmName) 334 logger.info('Updating plugin %s.', npmName)
335 335
336 // Use the latest version from DB, to not upgrade to a version that does not support our PeerTube version
337 let version: string
338 if (!fromDisk) {
339 const plugin = await PluginModel.loadByNpmName(toUpdate)
340 version = plugin.latestVersion
341 }
342
336 // Unregister old hooks 343 // Unregister old hooks
337 await this.unregister(npmName) 344 await this.unregister(npmName)
338 345
diff --git a/server/lib/plugins/yarn.ts b/server/lib/plugins/yarn.ts
index e40351b6e..3f45681d3 100644
--- a/server/lib/plugins/yarn.ts
+++ b/server/lib/plugins/yarn.ts
@@ -1,14 +1,17 @@
1import { outputJSON, pathExists } from 'fs-extra'
2import { join } from 'path'
1import { execShell } from '../../helpers/core-utils' 3import { execShell } from '../../helpers/core-utils'
2import { logger } from '../../helpers/logger'
3import { isNpmPluginNameValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins' 4import { isNpmPluginNameValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins'
5import { logger } from '../../helpers/logger'
4import { CONFIG } from '../../initializers/config' 6import { CONFIG } from '../../initializers/config'
5import { outputJSON, pathExists } from 'fs-extra' 7import { getLatestPluginVersion } from './plugin-index'
6import { join } from 'path'
7 8
8async function installNpmPlugin (npmName: string, version?: string) { 9async function installNpmPlugin (npmName: string, versionArg?: string) {
9 // Security check 10 // Security check
10 checkNpmPluginNameOrThrow(npmName) 11 checkNpmPluginNameOrThrow(npmName)
11 if (version) checkPluginVersionOrThrow(version) 12 if (versionArg) checkPluginVersionOrThrow(versionArg)
13
14 const version = versionArg || await getLatestPluginVersion(npmName)
12 15
13 let toInstall = npmName 16 let toInstall = npmName
14 if (version) toInstall += `@${version}` 17 if (version) toInstall += `@${version}`