]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/plugins.ts
Merge branch 'release/5.1.0' into develop
[github/Chocobozzz/PeerTube.git] / server / controllers / api / plugins.ts
index b64062287cdd0b59f206596bac6204eba3817544..de9e055dc0fe4b9bf7db4b7c0a5484237a44ebc9 100644 (file)
@@ -1,4 +1,4 @@
-import * as express from 'express'
+import express from 'express'
 import { logger } from '@server/helpers/logger'
 import { getFormattedObjects } from '@server/helpers/utils'
 import { listAvailablePluginsFromIndex } from '@server/lib/plugins/plugin-index'
@@ -8,6 +8,7 @@ import {
   authenticate,
   availablePluginsSortValidator,
   ensureUserHasRight,
+  openapiOperationDoc,
   paginationValidator,
   pluginsSortValidator,
   setDefaultPagination,
@@ -22,8 +23,8 @@ import {
   updatePluginSettingsValidator
 } from '@server/middlewares/validators/plugins'
 import { PluginModel } from '@server/models/server/plugin'
-import { HttpStatusCode } from '@shared/core-utils'
 import {
+  HttpStatusCode,
   InstallOrUpdatePlugin,
   ManagePlugin,
   PeertubePluginIndexList,
@@ -35,6 +36,7 @@ import {
 const pluginRouter = express.Router()
 
 pluginRouter.get('/available',
+  openapiOperationDoc({ operationId: 'getAvailablePlugins' }),
   authenticate,
   ensureUserHasRight(UserRight.MANAGE_PLUGINS),
   listAvailablePluginsValidator,
@@ -46,6 +48,7 @@ pluginRouter.get('/available',
 )
 
 pluginRouter.get('/',
+  openapiOperationDoc({ operationId: 'getPlugins' }),
   authenticate,
   ensureUserHasRight(UserRight.MANAGE_PLUGINS),
   listPluginsValidator,
@@ -84,6 +87,7 @@ pluginRouter.get('/:npmName',
 )
 
 pluginRouter.post('/install',
+  openapiOperationDoc({ operationId: 'addPlugin' }),
   authenticate,
   ensureUserHasRight(UserRight.MANAGE_PLUGINS),
   installOrUpdatePluginValidator,
@@ -91,6 +95,7 @@ pluginRouter.post('/install',
 )
 
 pluginRouter.post('/update',
+  openapiOperationDoc({ operationId: 'updatePlugin' }),
   authenticate,
   ensureUserHasRight(UserRight.MANAGE_PLUGINS),
   installOrUpdatePluginValidator,
@@ -98,6 +103,7 @@ pluginRouter.post('/update',
 )
 
 pluginRouter.post('/uninstall',
+  openapiOperationDoc({ operationId: 'uninstallPlugin' }),
   authenticate,
   ensureUserHasRight(UserRight.MANAGE_PLUGINS),
   uninstallPluginValidator,
@@ -138,8 +144,13 @@ async function installPlugin (req: express.Request, res: express.Response) {
 
   const fromDisk = !!body.path
   const toInstall = body.npmName || body.path
+
+  const pluginVersion = body.pluginVersion && body.npmName
+    ? body.pluginVersion
+    : undefined
+
   try {
-    const plugin = await PluginManager.Instance.install(toInstall, undefined, fromDisk)
+    const plugin = await PluginManager.Instance.install(toInstall, pluginVersion, fromDisk)
 
     return res.json(plugin.toFormattedJSON())
   } catch (err) {