diff options
author | Chocobozzz <me@florianbigard.com> | 2019-07-05 13:54:32 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-07-24 10:58:16 +0200 |
commit | 345da516fae80f24c90c2196e96393b489af2243 (patch) | |
tree | 64d72d25a531626c1d4a6337460dae4e32386f2a /server/controllers | |
parent | 297067399db2bf7505561d67667ca0d559a8e42b (diff) | |
download | PeerTube-345da516fae80f24c90c2196e96393b489af2243.tar.gz PeerTube-345da516fae80f24c90c2196e96393b489af2243.tar.zst PeerTube-345da516fae80f24c90c2196e96393b489af2243.zip |
WIP plugins: add ability to register plugins
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/index.ts | 2 | ||||
-rw-r--r-- | server/controllers/plugins.ts | 48 | ||||
-rw-r--r-- | server/controllers/themes.ts | 28 |
3 files changed, 78 insertions, 0 deletions
diff --git a/server/controllers/index.ts b/server/controllers/index.ts index a88a03c79..869546dc7 100644 --- a/server/controllers/index.ts +++ b/server/controllers/index.ts | |||
@@ -7,3 +7,5 @@ export * from './static' | |||
7 | export * from './webfinger' | 7 | export * from './webfinger' |
8 | export * from './tracker' | 8 | export * from './tracker' |
9 | export * from './bots' | 9 | export * from './bots' |
10 | export * from './plugins' | ||
11 | export * from './themes' | ||
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 @@ | |||
1 | import * as express from 'express' | ||
2 | import { PLUGIN_GLOBAL_CSS_PATH } from '../initializers/constants' | ||
3 | import { join } from 'path' | ||
4 | import { RegisteredPlugin } from '../lib/plugins/plugin-manager' | ||
5 | import { servePluginStaticDirectoryValidator } from '../middlewares/validators/plugins' | ||
6 | |||
7 | const pluginsRouter = express.Router() | ||
8 | |||
9 | pluginsRouter.get('/global.css', | ||
10 | express.static(PLUGIN_GLOBAL_CSS_PATH, { fallthrough: false }) | ||
11 | ) | ||
12 | |||
13 | pluginsRouter.get('/:pluginName/:pluginVersion/statics/:staticEndpoint', | ||
14 | servePluginStaticDirectoryValidator, | ||
15 | servePluginStaticDirectory | ||
16 | ) | ||
17 | |||
18 | pluginsRouter.get('/:pluginName/:pluginVersion/client-scripts/:staticEndpoint', | ||
19 | servePluginStaticDirectoryValidator, | ||
20 | servePluginClientScripts | ||
21 | ) | ||
22 | |||
23 | // --------------------------------------------------------------------------- | ||
24 | |||
25 | export { | ||
26 | pluginsRouter | ||
27 | } | ||
28 | |||
29 | // --------------------------------------------------------------------------- | ||
30 | |||
31 | function 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 | |||
43 | function 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 | } | ||
diff --git a/server/controllers/themes.ts b/server/controllers/themes.ts new file mode 100644 index 000000000..20e7062d0 --- /dev/null +++ b/server/controllers/themes.ts | |||
@@ -0,0 +1,28 @@ | |||
1 | import * as express from 'express' | ||
2 | import { PLUGIN_GLOBAL_CSS_PATH } from '../initializers/constants' | ||
3 | import { join } from 'path' | ||
4 | import { RegisteredPlugin } from '../lib/plugins/plugin-manager' | ||
5 | import { servePluginStaticDirectoryValidator } from '../middlewares/validators/plugins' | ||
6 | import { serveThemeCSSValidator } from '../middlewares/validators/themes' | ||
7 | |||
8 | const themesRouter = express.Router() | ||
9 | |||
10 | themesRouter.get('/:themeName/:themeVersion/css/:staticEndpoint', | ||
11 | serveThemeCSSValidator, | ||
12 | serveThemeCSSDirectory | ||
13 | ) | ||
14 | |||
15 | // --------------------------------------------------------------------------- | ||
16 | |||
17 | export { | ||
18 | themesRouter | ||
19 | } | ||
20 | |||
21 | // --------------------------------------------------------------------------- | ||
22 | |||
23 | function serveThemeCSSDirectory (req: express.Request, res: express.Response) { | ||
24 | const plugin: RegisteredPlugin = res.locals.registeredPlugin | ||
25 | const staticEndpoint = req.params.staticEndpoint | ||
26 | |||
27 | return express.static(join(plugin.path, staticEndpoint), { fallthrough: false }) | ||
28 | } | ||