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) {
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
}
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)
+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}`
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()
if (!plugin) {
return res.status(HttpStatusCode.NOT_FOUND_404)
.json({ error: 'Plugin not found' })
- .end()
}
res.locals.plugin = plugin