UNPKG

1.03 kBJavaScriptView Raw
1module.exports = ({
2 Tools,
3 router,
4 authMiddleware,
5 permissionMiddleware,
6 asyncMiddleware,
7 getConfig,
8 handleResponse,
9 handleError,
10}) => {
11
12 router.get(
13 '/tools/export-db.:ext?',
14 authMiddleware,
15 permissionMiddleware.bind(null, 'tools'),
16 asyncMiddleware(async (req, res) => {
17 const tools = Tools(await getConfig(req.session.slug));
18
19 try {
20 const db = await tools.getDb();
21
22 res.setHeader('Content-Disposition', `attachment; filename=${req.session.slug}.json`);
23 res.setHeader('Content-Type', 'application/json');
24 res.status(200);
25 res.send(db);
26
27 } catch (error) {
28 handleError(req, res, error);
29 }
30 })
31 );
32
33 router.get(
34 '/tools/changes.:ext?',
35 authMiddleware,
36 asyncMiddleware(async (req, res) => {
37 const tools = Tools(await getConfig(req.session.slug));
38
39 try {
40 handleResponse(req, res, await tools.getChanges());
41 } catch (error) {
42 handleError(req, res, error);
43 }
44 })
45 );
46
47};