]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/plugins.ts
Add server API actors route
[github/Chocobozzz/PeerTube.git] / server / controllers / api / plugins.ts
index 6b7562fd3162439b5a15d122d84fb43bcf85120b..a186de0102fd9e9fa7254e601c467d7db8628486 100644 (file)
@@ -27,6 +27,7 @@ import { listAvailablePluginsFromIndex } from '../../lib/plugins/plugin-index'
 import { PeertubePluginIndexList } from '../../../shared/models/plugins/peertube-plugin-index-list.model'
 import { RegisteredServerSettings } from '../../../shared/models/plugins/register-server-setting.model'
 import { PublicServerSetting } from '../../../shared/models/plugins/public-server.setting'
+import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
 
 const pluginRouter = express.Router()
 
@@ -140,7 +141,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(400)
+    return res.sendStatus(HttpStatusCode.BAD_REQUEST_400)
   }
 }
 
@@ -150,12 +151,12 @@ 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) {
     logger.warn('Cannot update plugin %s.', toUpdate, { err })
-    return res.sendStatus(400)
+    return res.sendStatus(HttpStatusCode.BAD_REQUEST_400)
   }
 }
 
@@ -164,7 +165,7 @@ async function uninstallPlugin (req: express.Request, res: express.Response) {
 
   await PluginManager.Instance.uninstall(body.npmName)
 
-  return res.sendStatus(204)
+  return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
 }
 
 function getPublicPluginSettings (req: express.Request, res: express.Response) {
@@ -191,7 +192,9 @@ async function updatePluginSettings (req: express.Request, res: express.Response
   plugin.settings = req.body.settings
   await plugin.save()
 
-  return res.sendStatus(204)
+  await PluginManager.Instance.onSettingsChanged(plugin.name, plugin.settings)
+
+  return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
 }
 
 async function listAvailablePlugins (req: express.Request, res: express.Response) {
@@ -200,9 +203,8 @@ async function listAvailablePlugins (req: express.Request, res: express.Response
   const resultList = await listAvailablePluginsFromIndex(query)
 
   if (!resultList) {
-    return res.status(503)
+    return res.status(HttpStatusCode.SERVICE_UNAVAILABLE_503)
       .json({ error: 'Plugin index unavailable. Please retry later' })
-      .end()
   }
 
   return res.json(resultList)