mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 10:07:08 +00:00
Used to download files. It relies on `imports.paths` being set appropriately in `etc/config.yaml` to indicate which parts of the filesystem are accessible to users via Dougal.
30 lines
572 B
JavaScript
30 lines
572 B
JavaScript
const files = require('../../../lib/files');
|
|
|
|
module.exports = async function (req, res, next) {
|
|
|
|
try {
|
|
const entity = await files.get(req.params.path, req.params.project, req.query);
|
|
if (entity) {
|
|
if (entity.download) {
|
|
res.download(...entity.download, (err) => next(err));
|
|
} else {
|
|
// Directory listing
|
|
res.status(203).json(entity);
|
|
next();
|
|
}
|
|
} else {
|
|
throw {
|
|
status: 404,
|
|
code: "ENOENT"
|
|
};
|
|
}
|
|
} catch (err) {
|
|
if (err.code == 'ENOENT') {
|
|
res.status(404).json({message: err.code});
|
|
} else {
|
|
next(err);
|
|
}
|
|
}
|
|
|
|
};
|