]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/controllers/themes.ts
WIP plugins: load theme on client side
[github/Chocobozzz/PeerTube.git] / server / controllers / themes.ts
1 import * as express from 'express'
2 import { join } from 'path'
3 import { RegisteredPlugin } from '../lib/plugins/plugin-manager'
4 import { serveThemeCSSValidator } from '../middlewares/validators/themes'
5
6 const themesRouter = express.Router()
7
8 themesRouter.get('/:themeName/:themeVersion/css/:staticEndpoint(*)',
9 serveThemeCSSValidator,
10 serveThemeCSSDirectory
11 )
12
13 // ---------------------------------------------------------------------------
14
15 export {
16 themesRouter
17 }
18
19 // ---------------------------------------------------------------------------
20
21 function serveThemeCSSDirectory (req: express.Request, res: express.Response) {
22 const plugin: RegisteredPlugin = res.locals.registeredPlugin
23 const staticEndpoint = req.params.staticEndpoint
24
25 if (plugin.css.includes(staticEndpoint) === false) {
26 return res.sendStatus(404)
27 }
28
29 return res.sendFile(join(plugin.path, staticEndpoint))
30 }