Add API files endpoint.

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.
This commit is contained in:
D. Berge
2023-08-30 13:51:31 +02:00
parent ec03627119
commit 70cf59bb4c
14 changed files with 268 additions and 0 deletions

View File

@@ -252,6 +252,12 @@ app.map({
// // post: [ mw.permissions.post ],
// // delete: [ mw.permissions.delete ]
// },
'/project/:project/files/:path(*)': {
get: [ mw.auth.access.write, mw.files.get ]
},
'/files/?:path(*)': {
get: [ mw.auth.access.write, mw.files.get ]
},
'/navdata/': {
get: [ mw.navdata.get ],
'gis/:featuretype(line|point)': {

View File

@@ -0,0 +1,29 @@
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);
}
}
};

View File

@@ -0,0 +1,7 @@
module.exports = {
get: require('./get'),
post: require('./post'),
put: require('./put'),
delete: require('./delete')
}

View File

@@ -1,5 +1,6 @@
module.exports = {
event: require('./event'),
files: require('./files'),
plan: require('./plan'),
line: require('./line'),
project: require('./project'),