diff --git a/api/src/routes/api/tracks.js b/api/src/routes/api/tracks.js index eb06437..ef1c205 100644 --- a/api/src/routes/api/tracks.js +++ b/api/src/routes/api/tracks.js @@ -206,7 +206,6 @@ router.post( await track.queueProcessing(); } - // console.log(track.author); return res.json({ track: track.toJSONFor(req.user) }); }), ); @@ -353,37 +352,43 @@ router.delete( // return an track's generated data router.get( - '/:track/data/:filename', + '/:track/data', auth.optional, wrapRoute(async (req, res) => { - const {filename} = req.params - - if (!['statistics', 'all_measurements'].includes(filename)) { - return res.sendStatus(404); + const FILE_BY_KEY = { + allMeasurements: 'all_measurements.json', + confirmedMeasurements: 'confirmed_measurements.json', + track: 'track.json', } - console.log(req.track.author, req.user) if (!req.track.isVisibleTo(req.user)) { return res.sendStatus(403); } - const filePath = path.join(PROCESSING_OUTPUT_DIR, req.track.filePath, filename + '.json') + const result = {} + for (const [key, filename] of Object.entries(FILE_BY_KEY)) { + const filePath = path.join(PROCESSING_OUTPUT_DIR, req.track.filePath, filename) - let stats + let stats - try { - stats = await fs.promises.stat(filePath) - } catch(err) { - return res.sendStatus(404); + try { + stats = await fs.promises.stat(filePath) + } catch(err) { + continue + } + + if (!stats.isFile()) { + // file does not exist (yet) + continue + } + + const content = await fs.promises.readFile(filePath) + const contentJson = JSON.parse(content) + + result[key] = contentJson } - if (!stats.isFile()) { - // file does not exist (yet) - return res.sendStatus(404); - } - - const content = await fs.promises.readFile(filePath) - return res.json(JSON.parse(content)); + return res.json(result); }), ); diff --git a/frontend/src/pages/TrackPage/TrackMap.tsx b/frontend/src/pages/TrackPage/TrackMap.tsx index 1c8bf93..2e7d688 100644 --- a/frontend/src/pages/TrackPage/TrackMap.tsx +++ b/frontend/src/pages/TrackPage/TrackMap.tsx @@ -102,8 +102,7 @@ export default function TrackMap({trackData, show, ...props}: {trackData: TrackD const trackPointsD2: Feature[] = [] const trackPointsUntaggedD1: Feature[] = [] const trackPointsUntaggedD2: Feature[] = [] - const points: Coordinate[] = [] - const filteredPoints: TrackPoint[] = trackData?.features.filter(isValidTrackPoint) ?? [] + const filteredPoints: TrackPoint[] = trackData?.allMeasurements?.features.filter(isValidTrackPoint) ?? [] for (const feature of filteredPoints) { const { @@ -114,7 +113,6 @@ export default function TrackMap({trackData, show, ...props}: {trackData: TrackD } = feature const p = fromLonLat([longitude, latitude]) - points.push(p) const geometry = new Point(p) @@ -135,6 +133,10 @@ export default function TrackMap({trackData, show, ...props}: {trackData: TrackD } } + const points: Coordinate[] = trackData?.track.geometry.coordinates.map(([latitude, longitude]) => { + return fromLonLat([longitude, latitude]) + }) ?? [] + //Simplify to 1 point per 2 meter const trackVectorSource = new VectorSource({ features: [new Feature(new LineString(points).simplify(2))], @@ -142,7 +144,7 @@ export default function TrackMap({trackData, show, ...props}: {trackData: TrackD const viewExtent = points.length ? trackVectorSource.getExtent() : null return {trackVectorSource, trackPointsD1, trackPointsD2, trackPointsUntaggedD1, trackPointsUntaggedD2, viewExtent} - }, [trackData?.features]) + }, [trackData?.allMeasurements?.features]) const trackLayerStyle = React.useMemo( () => diff --git a/frontend/src/pages/TrackPage/index.tsx b/frontend/src/pages/TrackPage/index.tsx index 2becdaf..eb22887 100644 --- a/frontend/src/pages/TrackPage/index.tsx +++ b/frontend/src/pages/TrackPage/index.tsx @@ -51,7 +51,7 @@ const TrackPage = connect((state) => ({login: state.login}))(function TrackPage( ) const trackData$ = slug$.pipe( - map((slug) => `/tracks/${slug}/data/all_measurements`), + map((slug) => `/tracks/${slug}/data`), switchMap((url) => concat( of(undefined), diff --git a/frontend/src/types.ts b/frontend/src/types.ts index 12c8534..0a5abf0 100644 --- a/frontend/src/types.ts +++ b/frontend/src/types.ts @@ -1,4 +1,4 @@ -import type {FeatureCollection, Point} from 'geojson' +import type {FeatureCollection, Feature, LineString, Point} from 'geojson' export type UserProfile = { username: string @@ -6,7 +6,12 @@ export type UserProfile = { bio?: string | null } -export type TrackData = FeatureCollection +export type TrackData = { + track: Feature, + allMeasurements: FeatureCollection, + confirmedMeasurements: FeatureCollection, +} + export type TrackStatistics = { recordedAt?: Date recordedUntil?: Date