From 31af59819ec64e1db01edc7014f23b409b186c2e Mon Sep 17 00:00:00 2001 From: Paul Bienkowski Date: Sat, 1 May 2021 13:29:25 +0200 Subject: [PATCH] api: Handle views directory better, and disable obsver1 download --- api/src/index.js | 2 +- api/src/routes/api/tracks.js | 27 ++++++--------------------- 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/api/src/index.js b/api/src/index.js index 5d2b1ba..9ed2037 100644 --- a/api/src/index.js +++ b/api/src/index.js @@ -17,7 +17,7 @@ const app = express(); app.use(cors()); // Express configuration -app.set('views', './views'); +app.set('views', path.join(__dirname, '..', 'views')); app.set('view engine', 'pug'); // Normal express config defaults diff --git a/api/src/routes/api/tracks.js b/api/src/routes/api/tracks.js index ab08f26..eb06437 100644 --- a/api/src/routes/api/tracks.js +++ b/api/src/routes/api/tracks.js @@ -389,30 +389,15 @@ router.get( // download the original file router.get( - '/:track/download', + '/:track/download/original.csv', auth.optional, wrapRoute(async (req, res) => { - 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 { + if (!req.track.isVisibleToPrivate(req.user)) { return res.sendStatus(403); } - }), -); + + return res.download(req.track.getOriginalFilePath(), req.track.originalFileName) + }) +) module.exports = router;