aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/plugins.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/plugins.ts')
-rw-r--r--server/controllers/plugins.ts13
1 files changed, 7 insertions, 6 deletions
diff --git a/server/controllers/plugins.ts b/server/controllers/plugins.ts
index 7b947bb6e..18c6613e2 100644
--- a/server/controllers/plugins.ts
+++ b/server/controllers/plugins.ts
@@ -4,9 +4,10 @@ import { join } from 'path'
4import { PluginManager, RegisteredPlugin } from '../lib/plugins/plugin-manager' 4import { PluginManager, RegisteredPlugin } from '../lib/plugins/plugin-manager'
5import { getPluginValidator, pluginStaticDirectoryValidator, getExternalAuthValidator } from '../middlewares/validators/plugins' 5import { getPluginValidator, pluginStaticDirectoryValidator, getExternalAuthValidator } from '../middlewares/validators/plugins'
6import { serveThemeCSSValidator } from '../middlewares/validators/themes' 6import { serveThemeCSSValidator } from '../middlewares/validators/themes'
7import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes'
8import { getCompleteLocale, is18nLocale } from '../../shared/core-utils/i18n'
7import { PluginType } from '../../shared/models/plugins/plugin.type' 9import { PluginType } from '../../shared/models/plugins/plugin.type'
8import { isTestInstance } from '../helpers/core-utils' 10import { isTestInstance } from '../helpers/core-utils'
9import { getCompleteLocale, is18nLocale } from '../../shared/core-utils/i18n'
10import { logger } from '@server/helpers/logger' 11import { logger } from '@server/helpers/logger'
11 12
12const sendFileOptions = { 13const sendFileOptions = {
@@ -96,7 +97,7 @@ function getPluginTranslations (req: express.Request, res: express.Response) {
96 return res.json(json) 97 return res.json(json)
97 } 98 }
98 99
99 return res.sendStatus(404) 100 return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
100} 101}
101 102
102function servePluginStaticDirectory (req: express.Request, res: express.Response) { 103function servePluginStaticDirectory (req: express.Request, res: express.Response) {
@@ -106,7 +107,7 @@ function servePluginStaticDirectory (req: express.Request, res: express.Response
106 const [ directory, ...file ] = staticEndpoint.split('/') 107 const [ directory, ...file ] = staticEndpoint.split('/')
107 108
108 const staticPath = plugin.staticDirs[directory] 109 const staticPath = plugin.staticDirs[directory]
109 if (!staticPath) return res.sendStatus(404) 110 if (!staticPath) return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
110 111
111 const filepath = file.join('/') 112 const filepath = file.join('/')
112 return res.sendFile(join(plugin.path, staticPath, filepath), sendFileOptions) 113 return res.sendFile(join(plugin.path, staticPath, filepath), sendFileOptions)
@@ -116,7 +117,7 @@ function servePluginCustomRoutes (req: express.Request, res: express.Response, n
116 const plugin: RegisteredPlugin = res.locals.registeredPlugin 117 const plugin: RegisteredPlugin = res.locals.registeredPlugin
117 const router = PluginManager.Instance.getRouter(plugin.npmName) 118 const router = PluginManager.Instance.getRouter(plugin.npmName)
118 119
119 if (!router) return res.sendStatus(404) 120 if (!router) return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
120 121
121 return router(req, res, next) 122 return router(req, res, next)
122} 123}
@@ -126,7 +127,7 @@ function servePluginClientScripts (req: express.Request, res: express.Response)
126 const staticEndpoint = req.params.staticEndpoint 127 const staticEndpoint = req.params.staticEndpoint
127 128
128 const file = plugin.clientScripts[staticEndpoint] 129 const file = plugin.clientScripts[staticEndpoint]
129 if (!file) return res.sendStatus(404) 130 if (!file) return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
130 131
131 return res.sendFile(join(plugin.path, staticEndpoint), sendFileOptions) 132 return res.sendFile(join(plugin.path, staticEndpoint), sendFileOptions)
132} 133}
@@ -136,7 +137,7 @@ function serveThemeCSSDirectory (req: express.Request, res: express.Response) {
136 const staticEndpoint = req.params.staticEndpoint 137 const staticEndpoint = req.params.staticEndpoint
137 138
138 if (plugin.css.includes(staticEndpoint) === false) { 139 if (plugin.css.includes(staticEndpoint) === false) {
139 return res.sendStatus(404) 140 return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
140 } 141 }
141 142
142 return res.sendFile(join(plugin.path, staticEndpoint), sendFileOptions) 143 return res.sendFile(join(plugin.path, staticEndpoint), sendFileOptions)