Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Ensure to install supported plugins

Chocobozzz8280d0c22797
diff --git a/server/controllers/api/plugins.ts b/server/controllers/api/plugins.ts
index bb69f25a1e..a186de0102 100644
--- a/server/controllers/api/plugins.ts
+++ b/server/controllers/api/plugins.ts
@@ -151,7 +151,7 @@ async function updatePlugin (req: express.Request, res: express.Response) {
const fromDisk = !!body.path
const toUpdate = body.npmName || body.path
try {
- const plugin = await PluginManager.Instance.update(toUpdate, undefined, fromDisk)
+ const plugin = await PluginManager.Instance.update(toUpdate, fromDisk)
return res.json(plugin.toFormattedJSON())
} catch (err) {
diff --git a/server/lib/plugins/plugin-index.ts b/server/lib/plugins/plugin-index.ts
index 624f5da1df..165bc91b35 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
return body
}
+async function getLatestPluginVersion (npmName: string) {
+ const results = await getLatestPluginsVersion([ npmName ])
+
+ if (Array.isArray(results) === false || results.length !== 1) {
+ logger.warn('Cannot get latest supported plugin version of %s.', npmName)
+ return undefined
+ }
+
+ return results[0].latestVersion
+}
+
export {
listAvailablePluginsFromIndex,
+ getLatestPluginVersion,
getLatestPluginsVersion
}
diff --git a/server/lib/plugins/plugin-manager.ts b/server/lib/plugins/plugin-manager.ts
index e3226a9502..03ea48416b 100644
--- a/server/lib/plugins/plugin-manager.ts
+++ b/server/lib/plugins/plugin-manager.ts
@@ -328,11 +328,18 @@ export class PluginManager implements ServerHook {
return plugin
}
- async update (toUpdate: string, version?: string, fromDisk = false) {
+ async update (toUpdate: string, fromDisk = false) {
const npmName = fromDisk ? basename(toUpdate) : toUpdate
logger.info('Updating plugin %s.', npmName)
+ // Use the latest version from DB, to not upgrade to a version that does not support our PeerTube version
+ let version: string
+ if (!fromDisk) {
+ const plugin = await PluginModel.loadByNpmName(toUpdate)
+ version = plugin.latestVersion
+ }
+
// Unregister old hooks
await this.unregister(npmName)
diff --git a/server/lib/plugins/yarn.ts b/server/lib/plugins/yarn.ts
index e40351b6e3..3f45681d3f 100644
--- a/server/lib/plugins/yarn.ts
+++ b/server/lib/plugins/yarn.ts
@@ -1,14 +1,17 @@
+import { outputJSON, pathExists } from 'fs-extra'
+import { join } from 'path'
import { execShell } from '../../helpers/core-utils'
-import { logger } from '../../helpers/logger'
import { isNpmPluginNameValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins'
+import { logger } from '../../helpers/logger'
import { CONFIG } from '../../initializers/config'
-import { outputJSON, pathExists } from 'fs-extra'
-import { join } from 'path'
+import { getLatestPluginVersion } from './plugin-index'
-async function installNpmPlugin (npmName: string, version?: string) {
+async function installNpmPlugin (npmName: string, versionArg?: string) {
// Security check
checkNpmPluginNameOrThrow(npmName)
- if (version) checkPluginVersionOrThrow(version)
+ if (versionArg) checkPluginVersionOrThrow(versionArg)
+
+ const version = versionArg || await getLatestPluginVersion(npmName)
let toInstall = npmName
if (version) toInstall += `@${version}`
diff --git a/server/middlewares/validators/plugins.ts b/server/middlewares/validators/plugins.ts
index 1083e0afae..ab87fe720c 100644
--- a/server/middlewares/validators/plugins.ts
+++ b/server/middlewares/validators/plugins.ts
@@ -109,7 +109,6 @@ const installOrUpdatePluginValidator = [
if (!body.path && !body.npmName) {
return res.status(HttpStatusCode.BAD_REQUEST_400)
.json({ error: 'Should have either a npmName or a path' })
- .end()
}
return next()
@@ -140,7 +139,6 @@ const existingPluginValidator = [
if (!plugin) {
return res.status(HttpStatusCode.NOT_FOUND_404)
.json({ error: 'Plugin not found' })
- .end()
}
res.locals.plugin = plugin