|
1 | 1 | const downloadPdf = require('@/handlers/downloadHandler/downloadPdf');
|
2 | 2 | const express = require('express');
|
3 |
| - |
| 3 | +const path = require('path'); |
4 | 4 | const router = express.Router();
|
5 | 5 | const { hasPermission } = require('@/middlewares/permission');
|
6 | 6 |
|
7 |
| -router.route('/:subPath/:directory/:id').get(function (req, res) { |
8 |
| - const { subPath, directory, id } = req.params; |
| 7 | +// router.route('/:directory/:file').get(function (req, res) { |
| 8 | +// const { directory, file } = req.params; |
9 | 9 |
|
10 |
| - // Handle the /payment/* route |
11 |
| - if (subPath == 'payment' && directory == 'invoice') { |
12 |
| - downloadPdf(req, res, { directory: 'Payment', id }); |
13 |
| - } else { |
14 |
| - downloadPdf(req, res, { directory, id }); |
15 |
| - } |
16 |
| -}); |
| 10 | +// // Handle the /payment/* route |
17 | 11 |
|
18 |
| -// router.route('/:directory/:id').get(function (req, res) { |
19 |
| -// const { directory, id } = req.params; |
| 12 | +// const options = { |
| 13 | +// root: path.join(__dirname, `../../public/download/${directory}`), |
| 14 | +// dotfiles: 'deny', |
| 15 | +// headers: { |
| 16 | +// 'Content-type': 'application/pdf', |
| 17 | +// 'Content-disposition': 'inline; filename="' + file + '"', |
| 18 | +// }, |
| 19 | +// }; |
20 | 20 |
|
21 |
| -// downloadPdf(req, res, { directory, id }); |
| 21 | +// res.status(200).sendFile(file, options, function (err) { |
| 22 | +// if (err) { |
| 23 | +// const id = file.slice(directory.length + 1).slice(0, -4); // extract id from file name |
| 24 | +// downloadPdf(req, res, { directory, id }); |
| 25 | +// } |
| 26 | +// }); |
22 | 27 | // });
|
23 | 28 |
|
| 29 | +router.route('/:directory/:file').get(function (req, res) { |
| 30 | + const { directory, file } = req.params; |
| 31 | + |
| 32 | + const id = file.slice(directory.length + 1).slice(0, -4); // extract id from file name |
| 33 | + downloadPdf(req, res, { directory, id }); |
| 34 | +}); |
| 35 | + |
24 | 36 | module.exports = router;
|
0 commit comments