]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/plugins.ts
More robust actor image lazy load
[github/Chocobozzz/PeerTube.git] / server / controllers / api / plugins.ts
index e18eed332765e7905b1efbcfc146dccb0c81a803..1e6a02c496f17503f49dad18ac8da0089a95c953 100644 (file)
@@ -8,6 +8,7 @@ import {
   authenticate,
   availablePluginsSortValidator,
   ensureUserHasRight,
+  openapiOperationDoc,
   paginationValidator,
   pluginsSortValidator,
   setDefaultPagination,
@@ -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,
@@ -144,7 +150,7 @@ async function installPlugin (req: express.Request, res: express.Response) {
     return res.json(plugin.toFormattedJSON())
   } catch (err) {
     logger.warn('Cannot install plugin %s.', toInstall, { err })
-    return res.sendStatus(HttpStatusCode.BAD_REQUEST_400)
+    return res.fail({ message: 'Cannot install plugin ' + toInstall })
   }
 }
 
@@ -159,7 +165,7 @@ async function updatePlugin (req: express.Request, res: express.Response) {
     return res.json(plugin.toFormattedJSON())
   } catch (err) {
     logger.warn('Cannot update plugin %s.', toUpdate, { err })
-    return res.sendStatus(HttpStatusCode.BAD_REQUEST_400)
+    return res.fail({ message: 'Cannot update plugin ' + toUpdate })
   }
 }
 
@@ -168,7 +174,7 @@ async function uninstallPlugin (req: express.Request, res: express.Response) {
 
   await PluginManager.Instance.uninstall(body.npmName)
 
-  return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+  return res.status(HttpStatusCode.NO_CONTENT_204).end()
 }
 
 function getPublicPluginSettings (req: express.Request, res: express.Response) {
@@ -197,7 +203,7 @@ async function updatePluginSettings (req: express.Request, res: express.Response
 
   await PluginManager.Instance.onSettingsChanged(plugin.name, plugin.settings)
 
-  return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+  return res.status(HttpStatusCode.NO_CONTENT_204).end()
 }
 
 async function listAvailablePlugins (req: express.Request, res: express.Response) {
@@ -206,8 +212,10 @@ async function listAvailablePlugins (req: express.Request, res: express.Response
   const resultList = await listAvailablePluginsFromIndex(query)
 
   if (!resultList) {
-    return res.status(HttpStatusCode.SERVICE_UNAVAILABLE_503)
-      .json({ error: 'Plugin index unavailable. Please retry later' })
+    return res.fail({
+      status: HttpStatusCode.SERVICE_UNAVAILABLE_503,
+      message: 'Plugin index unavailable. Please retry later'
+    })
   }
 
   return res.json(resultList)