aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/plugins.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-07-05 13:54:32 +0200
committerChocobozzz <chocobozzz@cpy.re>2019-07-24 10:58:16 +0200
commit345da516fae80f24c90c2196e96393b489af2243 (patch)
tree64d72d25a531626c1d4a6337460dae4e32386f2a /server/controllers/plugins.ts
parent297067399db2bf7505561d67667ca0d559a8e42b (diff)
downloadPeerTube-345da516fae80f24c90c2196e96393b489af2243.tar.gz
PeerTube-345da516fae80f24c90c2196e96393b489af2243.tar.zst
PeerTube-345da516fae80f24c90c2196e96393b489af2243.zip
WIP plugins: add ability to register plugins
Diffstat (limited to 'server/controllers/plugins.ts')
-rw-r--r--server/controllers/plugins.ts48
1 files changed, 48 insertions, 0 deletions
diff --git a/server/controllers/plugins.ts b/server/controllers/plugins.ts
new file mode 100644
index 000000000..a6705d9c7
--- /dev/null
+++ b/server/controllers/plugins.ts
@@ -0,0 +1,48 @@
1import * as express from 'express'
2import { PLUGIN_GLOBAL_CSS_PATH } from '../initializers/constants'
3import { join } from 'path'
4import { RegisteredPlugin } from '../lib/plugins/plugin-manager'
5import { servePluginStaticDirectoryValidator } from '../middlewares/validators/plugins'
6
7const pluginsRouter = express.Router()
8
9pluginsRouter.get('/global.css',
10 express.static(PLUGIN_GLOBAL_CSS_PATH, { fallthrough: false })
11)
12
13pluginsRouter.get('/:pluginName/:pluginVersion/statics/:staticEndpoint',
14 servePluginStaticDirectoryValidator,
15 servePluginStaticDirectory
16)
17
18pluginsRouter.get('/:pluginName/:pluginVersion/client-scripts/:staticEndpoint',
19 servePluginStaticDirectoryValidator,
20 servePluginClientScripts
21)
22
23// ---------------------------------------------------------------------------
24
25export {
26 pluginsRouter
27}
28
29// ---------------------------------------------------------------------------
30
31function servePluginStaticDirectory (req: express.Request, res: express.Response) {
32 const plugin: RegisteredPlugin = res.locals.registeredPlugin
33 const staticEndpoint = req.params.staticEndpoint
34
35 const staticPath = plugin.staticDirs[staticEndpoint]
36 if (!staticPath) {
37 return res.sendStatus(404)
38 }
39
40 return express.static(join(plugin.path, staticPath), { fallthrough: false })
41}
42
43function servePluginClientScripts (req: express.Request, res: express.Response) {
44 const plugin: RegisteredPlugin = res.locals.registeredPlugin
45 const staticEndpoint = req.params.staticEndpoint
46
47 return express.static(join(plugin.path, staticEndpoint), { fallthrough: false })
48}