UNPKG

886 BJavaScriptView Raw
1module.exports = ({
2 ClientConfig,
3 router,
4 authMiddleware,
5 permissionMiddleware,
6 asyncMiddleware,
7 getConfig,
8 handleResponse,
9 handleError,
10}) => {
11
12 router.get(
13 '/config.:ext?',
14 authMiddleware,
15 asyncMiddleware(async (req, res) => {
16 const clientConfig = ClientConfig(await getConfig(req.session.slug));
17
18 try {
19 handleResponse(req, res, await clientConfig.get());
20 } catch (error) {
21 handleError(req, res, error);
22 }
23 })
24 );
25
26 router.post(
27 '/config.:ext?',
28 authMiddleware,
29 permissionMiddleware.bind(null, 'config'),
30 asyncMiddleware(async (req, res) => {
31 const clientConfig = ClientConfig(await getConfig(req.session.slug));
32
33 try {
34 handleResponse(req, res, await clientConfig.set(req.body.config));
35 } catch (error) {
36 handleError(req, res, error);
37 }
38 })
39 );
40
41};