Ensure to install supported plugins
This commit is contained in:
parent
90aa0a74e9
commit
8280d0c227
5 changed files with 30 additions and 10 deletions
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -1,14 +1,17 @@
|
|||
import { execShell } from '../../helpers/core-utils'
|
||||
import { logger } from '../../helpers/logger'
|
||||
import { isNpmPluginNameValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins'
|
||||
import { CONFIG } from '../../initializers/config'
|
||||
import { outputJSON, pathExists } from 'fs-extra'
|
||||
import { join } from 'path'
|
||||
import { execShell } from '../../helpers/core-utils'
|
||||
import { isNpmPluginNameValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins'
|
||||
import { logger } from '../../helpers/logger'
|
||||
import { CONFIG } from '../../initializers/config'
|
||||
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}`
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue