1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-04 02:09:37 +02:00

WIP plugins: update plugin

This commit is contained in:
Chocobozzz 2019-07-12 11:39:58 +02:00 committed by Chocobozzz
parent 8d2be0ed7b
commit b5f919ac8e
24 changed files with 389 additions and 90 deletions

View file

@ -13,13 +13,13 @@ import { PluginModel } from '../../models/server/plugin'
import { UserRight } from '../../../shared/models/users'
import {
existingPluginValidator,
installPluginValidator,
installOrUpdatePluginValidator,
listPluginsValidator,
uninstallPluginValidator,
updatePluginSettingsValidator
} from '../../middlewares/validators/plugins'
import { PluginManager } from '../../lib/plugins/plugin-manager'
import { InstallPlugin } from '../../../shared/models/plugins/install-plugin.model'
import { InstallOrUpdatePlugin } from '../../../shared/models/plugins/install-plugin.model'
import { ManagePlugin } from '../../../shared/models/plugins/manage-plugin.model'
import { logger } from '../../helpers/logger'
@ -61,10 +61,17 @@ pluginRouter.put('/:npmName/settings',
pluginRouter.post('/install',
authenticate,
ensureUserHasRight(UserRight.MANAGE_PLUGINS),
installPluginValidator,
installOrUpdatePluginValidator,
asyncMiddleware(installPlugin)
)
pluginRouter.post('/update',
authenticate,
ensureUserHasRight(UserRight.MANAGE_PLUGINS),
installOrUpdatePluginValidator,
asyncMiddleware(updatePlugin)
)
pluginRouter.post('/uninstall',
authenticate,
ensureUserHasRight(UserRight.MANAGE_PLUGINS),
@ -100,18 +107,33 @@ function getPlugin (req: express.Request, res: express.Response) {
}
async function installPlugin (req: express.Request, res: express.Response) {
const body: InstallPlugin = req.body
const body: InstallOrUpdatePlugin = req.body
const fromDisk = !!body.path
const toInstall = body.npmName || body.path
try {
await PluginManager.Instance.install(toInstall, undefined, fromDisk)
const plugin = await PluginManager.Instance.install(toInstall, undefined, fromDisk)
return res.json(plugin.toFormattedJSON())
} catch (err) {
logger.warn('Cannot install plugin %s.', toInstall, { err })
return res.sendStatus(400)
}
}
return res.sendStatus(204)
async function updatePlugin (req: express.Request, res: express.Response) {
const body: InstallOrUpdatePlugin = req.body
const fromDisk = !!body.path
const toUpdate = body.npmName || body.path
try {
const plugin = await PluginManager.Instance.update(toUpdate, undefined, fromDisk)
return res.json(plugin.toFormattedJSON())
} catch (err) {
logger.warn('Cannot update plugin %s.', toUpdate, { err })
return res.sendStatus(400)
}
}
async function uninstallPlugin (req: express.Request, res: express.Response) {
@ -123,9 +145,7 @@ async function uninstallPlugin (req: express.Request, res: express.Response) {
}
function getPluginRegisteredSettings (req: express.Request, res: express.Response) {
const plugin = res.locals.plugin
const settings = PluginManager.Instance.getSettings(plugin.name)
const settings = PluginManager.Instance.getRegisteredSettings(req.params.npmName)
return res.json({
settings