aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-07-08 14:02:03 +0200
committerChocobozzz <chocobozzz@cpy.re>2019-07-24 10:58:16 +0200
commit2c0539420d77339e6afe8d7920b44af4c0dcb1e6 (patch)
tree6728a1cec7e2688a42cc84466a8c978067f2c574 /server/controllers
parentf023a19c3eeeea2b014b47fae522a62eab320048 (diff)
downloadPeerTube-2c0539420d77339e6afe8d7920b44af4c0dcb1e6.tar.gz
PeerTube-2c0539420d77339e6afe8d7920b44af4c0dcb1e6.tar.zst
PeerTube-2c0539420d77339e6afe8d7920b44af4c0dcb1e6.zip
WIP plugins: static files
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/plugins.ts26
1 files changed, 19 insertions, 7 deletions
diff --git a/server/controllers/plugins.ts b/server/controllers/plugins.ts
index a6705d9c7..05f03324d 100644
--- a/server/controllers/plugins.ts
+++ b/server/controllers/plugins.ts
@@ -1,21 +1,21 @@
1import * as express from 'express' 1import * as express from 'express'
2import { PLUGIN_GLOBAL_CSS_PATH } from '../initializers/constants' 2import { PLUGIN_GLOBAL_CSS_PATH } from '../initializers/constants'
3import { join } from 'path' 3import { basename, join } from 'path'
4import { RegisteredPlugin } from '../lib/plugins/plugin-manager' 4import { RegisteredPlugin } from '../lib/plugins/plugin-manager'
5import { servePluginStaticDirectoryValidator } from '../middlewares/validators/plugins' 5import { servePluginStaticDirectoryValidator } from '../middlewares/validators/plugins'
6 6
7const pluginsRouter = express.Router() 7const pluginsRouter = express.Router()
8 8
9pluginsRouter.get('/global.css', 9pluginsRouter.get('/global.css',
10 express.static(PLUGIN_GLOBAL_CSS_PATH, { fallthrough: false }) 10 servePluginGlobalCSS
11) 11)
12 12
13pluginsRouter.get('/:pluginName/:pluginVersion/statics/:staticEndpoint', 13pluginsRouter.get('/:pluginName/:pluginVersion/static/:staticEndpoint(*)',
14 servePluginStaticDirectoryValidator, 14 servePluginStaticDirectoryValidator,
15 servePluginStaticDirectory 15 servePluginStaticDirectory
16) 16)
17 17
18pluginsRouter.get('/:pluginName/:pluginVersion/client-scripts/:staticEndpoint', 18pluginsRouter.get('/:pluginName/:pluginVersion/client-scripts/:staticEndpoint(*)',
19 servePluginStaticDirectoryValidator, 19 servePluginStaticDirectoryValidator,
20 servePluginClientScripts 20 servePluginClientScripts
21) 21)
@@ -28,21 +28,33 @@ export {
28 28
29// --------------------------------------------------------------------------- 29// ---------------------------------------------------------------------------
30 30
31function servePluginGlobalCSS (req: express.Request, res: express.Response) {
32 return res.sendFile(PLUGIN_GLOBAL_CSS_PATH)
33}
34
31function servePluginStaticDirectory (req: express.Request, res: express.Response) { 35function servePluginStaticDirectory (req: express.Request, res: express.Response) {
32 const plugin: RegisteredPlugin = res.locals.registeredPlugin 36 const plugin: RegisteredPlugin = res.locals.registeredPlugin
33 const staticEndpoint = req.params.staticEndpoint 37 const staticEndpoint = req.params.staticEndpoint
34 38
35 const staticPath = plugin.staticDirs[staticEndpoint] 39 const [ directory, ...file ] = staticEndpoint.split('/')
40
41 const staticPath = plugin.staticDirs[directory]
36 if (!staticPath) { 42 if (!staticPath) {
37 return res.sendStatus(404) 43 return res.sendStatus(404)
38 } 44 }
39 45
40 return express.static(join(plugin.path, staticPath), { fallthrough: false }) 46 const filepath = file.join('/')
47 return res.sendFile(join(plugin.path, staticPath, filepath))
41} 48}
42 49
43function servePluginClientScripts (req: express.Request, res: express.Response) { 50function servePluginClientScripts (req: express.Request, res: express.Response) {
44 const plugin: RegisteredPlugin = res.locals.registeredPlugin 51 const plugin: RegisteredPlugin = res.locals.registeredPlugin
45 const staticEndpoint = req.params.staticEndpoint 52 const staticEndpoint = req.params.staticEndpoint
46 53
47 return express.static(join(plugin.path, staticEndpoint), { fallthrough: false }) 54 const file = plugin.clientScripts[staticEndpoint]
55 if (!file) {
56 return res.sendStatus(404)
57 }
58
59 return res.sendFile(join(plugin.path, staticEndpoint))
48} 60}