Fix jwt-token

This commit is contained in:
2025-09-09 06:54:13 +02:00
parent a879cd7487
commit 29f7b25954
3 changed files with 126 additions and 43 deletions

View File

@@ -280,24 +280,13 @@ async function handleDetection(req, res) {
});
}
// Handle drone type 0 (None) - should not trigger alarms or be stored as detection
// Handle drone type 0 (None) - store for debugging but don't trigger alarms
let isDebugDetection = false;
if (detectionData.drone_type === 0) {
if (DEBUG_CONFIG.logAllDetections) {
console.log(`🔍 Debug: Drone type 0 (None) received from device ${detectionData.device_id}`);
console.log(`🔍 Debug: Drone type 0 (None) received from device ${detectionData.device_id} - storing for debug purposes`);
}
if (!DEBUG_CONFIG.storeNoneDetections) {
// Don't store in database, just acknowledge receipt
return res.status(200).json({
success: true,
message: 'Heartbeat received (no detection)',
stored: false,
debug: DEBUG_CONFIG.logAllDetections
});
}
// If debugging enabled, store but mark as debug data
console.log(`🐛 Debug mode: Storing drone type 0 detection for debugging`);
isDebugDetection = true;
}
// Create detection record
@@ -313,33 +302,38 @@ async function handleDetection(req, res) {
});
// Emit real-time update via Socket.IO with movement analysis (from original)
req.io.emit('drone_detection', {
id: detection.id,
device_id: detection.device_id,
drone_id: detection.drone_id,
drone_type: detection.drone_type,
rssi: detection.rssi,
freq: detection.freq,
geo_lat: detection.geo_lat,
geo_lon: detection.geo_lon,
server_timestamp: detection.server_timestamp,
confidence_level: detection.confidence_level,
signal_duration: detection.signal_duration,
movement_analysis: movementAnalysis,
device: {
id: device.id,
name: device.name,
geo_lat: device.geo_lat,
geo_lon: device.geo_lon
}
});
// Skip real-time updates for debug detections (drone_type 0)
if (!isDebugDetection) {
req.io.emit('drone_detection', {
id: detection.id,
device_id: detection.device_id,
drone_id: detection.drone_id,
drone_type: detection.drone_type,
rssi: detection.rssi,
freq: detection.freq,
geo_lat: detection.geo_lat,
geo_lon: detection.geo_lon,
server_timestamp: detection.server_timestamp,
confidence_level: detection.confidence_level,
signal_duration: detection.signal_duration,
movement_analysis: movementAnalysis,
device: {
id: device.id,
name: device.name,
geo_lat: device.geo_lat,
geo_lon: device.geo_lon
}
});
// Process alerts asynchronously (from original)
alertService.processAlert(detection, req.io).catch(error => {
console.error('Alert processing error:', error);
});
// Process alerts asynchronously (from original)
alertService.processAlert(detection, req.io).catch(error => {
console.error('Alert processing error:', error);
});
console.log(`✅ Detection recorded and alert processing initiated for detection ${detection.id}`);
console.log(`✅ Detection recorded and alert processing initiated for detection ${detection.id}`);
} else {
console.log(`🐛 Debug detection stored for device ${detection.device_id} (drone_type 0) - no alerts or real-time updates`);
}
return res.status(201).json({
success: true,