api: Handle views directory better, and disable obsver1 download
This commit is contained in:
parent
c32a475b96
commit
31af59819e
|
@ -17,7 +17,7 @@ const app = express();
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
|
|
||||||
// Express configuration
|
// Express configuration
|
||||||
app.set('views', './views');
|
app.set('views', path.join(__dirname, '..', 'views'));
|
||||||
app.set('view engine', 'pug');
|
app.set('view engine', 'pug');
|
||||||
|
|
||||||
// Normal express config defaults
|
// Normal express config defaults
|
||||||
|
|
|
@ -389,30 +389,15 @@ router.get(
|
||||||
|
|
||||||
// download the original file
|
// download the original file
|
||||||
router.get(
|
router.get(
|
||||||
'/:track/download',
|
'/:track/download/original.csv',
|
||||||
auth.optional,
|
auth.optional,
|
||||||
wrapRoute(async (req, res) => {
|
wrapRoute(async (req, res) => {
|
||||||
if (req.track.isVisibleToPrivate(req.user)) {
|
if (!req.track.isVisibleToPrivate(req.user)) {
|
||||||
return res.download(req.track.fullOriginalFilePath)
|
|
||||||
} else if (req.track.isVisibleTo(req.user)) {
|
|
||||||
await req.track.populate('publicTrackData').execPopulate()
|
|
||||||
|
|
||||||
if (!req.track.publicTrackData) {
|
|
||||||
return res.sendStatus(403);
|
|
||||||
}
|
|
||||||
|
|
||||||
const body = buildObsver1(req.track.publicTrackData.points)
|
|
||||||
const fileName = req.track.slug + '_public.csv'
|
|
||||||
|
|
||||||
res.set({
|
|
||||||
'Content-Disposition': 'attachment; filename=' + JSON.stringify(fileName),
|
|
||||||
'Content-Type': 'text/csv',
|
|
||||||
});
|
|
||||||
return res.end(body)
|
|
||||||
} else {
|
|
||||||
return res.sendStatus(403);
|
return res.sendStatus(403);
|
||||||
}
|
}
|
||||||
}),
|
|
||||||
);
|
return res.download(req.track.getOriginalFilePath(), req.track.originalFileName)
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|
Loading…
Reference in a new issue