From 3a3fadfad70532dfed8336ae027074edcfabf0a7 Mon Sep 17 00:00:00 2001 From: Alexander Borg Date: Mon, 1 Sep 2025 07:42:59 +0200 Subject: [PATCH] Fix jwt-token --- server/.env.example | 5 ++ server/routes/detections.js | 136 ++++++++++++++++++------------------ server/routes/detectors.js | 5 +- 3 files changed, 76 insertions(+), 70 deletions(-) diff --git a/server/.env.example b/server/.env.example index c60cae2..9a8b32e 100644 --- a/server/.env.example +++ b/server/.env.example @@ -27,3 +27,8 @@ RATE_LIMIT_MAX_REQUESTS=100 # CORS Configuration CORS_ORIGIN=http://localhost:3000 + +# Debug Configuration +STORE_HEARTBEATS=false +STORE_DRONE_TYPE0=false +LOG_ALL_DETECTIONS=false diff --git a/server/routes/detections.js b/server/routes/detections.js index 2506c2b..c00ddfc 100644 --- a/server/routes/detections.js +++ b/server/routes/detections.js @@ -100,74 +100,6 @@ router.get('/', authenticateToken, async (req, res) => { } }); -/** - * GET /api/detections/:id - * Get a specific detection by ID - */ -router.get('/:id', authenticateToken, async (req, res) => { - try { - const { id } = req.params; - - const detection = await DroneDetection.findByPk(id, { - include: [{ - model: Device, - as: 'device', - attributes: ['id', 'name', 'geo_lat', 'geo_lon', 'location_description', 'is_approved'] - }] - }); - - if (!detection) { - return res.status(404).json({ error: 'Detection not found' }); - } - - // Enhance detection with drone type information - const droneTypeInfo = getDroneTypeInfo(detection.drone_type); - const enhancedDetection = { - ...detection.toJSON(), - drone_type_info: droneTypeInfo - }; - - res.json(enhancedDetection); - - } catch (error) { - console.error('Error fetching detection:', error); - res.status(500).json({ - error: 'Failed to fetch detection', - details: error.message - }); - } -}); - -/** - * DELETE /api/detections/:id - * Delete a specific detection (admin only) - */ -router.delete('/:id', authenticateToken, async (req, res) => { - try { - // Check if user is admin - if (req.user.role !== 'admin') { - return res.status(403).json({ error: 'Admin access required' }); - } - - const { id } = req.params; - - const detection = await DroneDetection.findByPk(id); - if (!detection) { - return res.status(404).json({ error: 'Detection not found' }); - } - - await detection.destroy(); - res.json({ message: 'Detection deleted successfully' }); - - } catch (error) { - console.error('Error deleting detection:', error); - res.status(500).json({ - error: 'Failed to delete detection', - details: error.message - }); - } -}); - /** * GET /api/detections/debug * Get all detections including drone type 0 (None) for debugging purposes @@ -271,4 +203,72 @@ router.get('/debug', authenticateToken, async (req, res) => { } }); +/** + * GET /api/detections/:id + * Get a specific detection by ID + */ +router.get('/:id', authenticateToken, async (req, res) => { + try { + const { id } = req.params; + + const detection = await DroneDetection.findByPk(id, { + include: [{ + model: Device, + as: 'device', + attributes: ['id', 'name', 'geo_lat', 'geo_lon', 'location_description', 'is_approved'] + }] + }); + + if (!detection) { + return res.status(404).json({ error: 'Detection not found' }); + } + + // Enhance detection with drone type information + const droneTypeInfo = getDroneTypeInfo(detection.drone_type); + const enhancedDetection = { + ...detection.toJSON(), + drone_type_info: droneTypeInfo + }; + + res.json(enhancedDetection); + + } catch (error) { + console.error('Error fetching detection:', error); + res.status(500).json({ + error: 'Failed to fetch detection', + details: error.message + }); + } +}); + +/** + * DELETE /api/detections/:id + * Delete a specific detection (admin only) + */ +router.delete('/:id', authenticateToken, async (req, res) => { + try { + // Check if user is admin + if (req.user.role !== 'admin') { + return res.status(403).json({ error: 'Admin access required' }); + } + + const { id } = req.params; + + const detection = await DroneDetection.findByPk(id); + if (!detection) { + return res.status(404).json({ error: 'Detection not found' }); + } + + await detection.destroy(); + res.json({ message: 'Detection deleted successfully' }); + + } catch (error) { + console.error('Error deleting detection:', error); + res.status(500).json({ + error: 'Failed to delete detection', + details: error.message + }); + } +}); + module.exports = router; diff --git a/server/routes/detectors.js b/server/routes/detectors.js index 0812590..53d1b64 100644 --- a/server/routes/detectors.js +++ b/server/routes/detectors.js @@ -9,8 +9,9 @@ const { getDroneTypeInfo, getDroneTypeName } = require('../utils/droneTypes'); // Configuration for debugging and data storage const DEBUG_CONFIG = { - storeNoneDetections: process.env.STORE_NONE_DETECTIONS === 'true', // Store drone_type 0 for debugging - logAllDetections: process.env.LOG_ALL_DETECTIONS === 'true' // Log all detections including type 0 + storeHeartbeats: process.env.STORE_HEARTBEATS === 'true', // Store heartbeat data for debugging + storeNoneDetections: process.env.STORE_DRONE_TYPE0 === 'true', // Store drone_type 0 for debugging + logAllDetections: process.env.LOG_ALL_DETECTIONS === 'true' // Log all detection data }; // Initialize services