Fix jwt-token

This commit is contained in:
2025-09-01 07:42:59 +02:00
parent b430018310
commit 3a3fadfad7
3 changed files with 76 additions and 70 deletions

View File

@@ -27,3 +27,8 @@ RATE_LIMIT_MAX_REQUESTS=100
# CORS Configuration # CORS Configuration
CORS_ORIGIN=http://localhost:3000 CORS_ORIGIN=http://localhost:3000
# Debug Configuration
STORE_HEARTBEATS=false
STORE_DRONE_TYPE0=false
LOG_ALL_DETECTIONS=false

View File

@@ -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 /api/detections/debug
* Get all detections including drone type 0 (None) for debugging purposes * 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; module.exports = router;

View File

@@ -9,8 +9,9 @@ const { getDroneTypeInfo, getDroneTypeName } = require('../utils/droneTypes');
// Configuration for debugging and data storage // Configuration for debugging and data storage
const DEBUG_CONFIG = { const DEBUG_CONFIG = {
storeNoneDetections: process.env.STORE_NONE_DETECTIONS === 'true', // Store drone_type 0 for debugging storeHeartbeats: process.env.STORE_HEARTBEATS === 'true', // Store heartbeat data for debugging
logAllDetections: process.env.LOG_ALL_DETECTIONS === 'true' // Log all detections including type 0 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 // Initialize services