Fix jwt-token
This commit is contained in:
6
.env
6
.env
@@ -30,9 +30,9 @@ TWILIO_PHONE_NUMBER=your_twilio_phone_number_here
|
||||
CORS_ORIGIN=http://localhost:3000
|
||||
|
||||
# Debug Configuration
|
||||
STORE_HEARTBEATS=false
|
||||
STORE_DRONE_TYPE0=false
|
||||
LOG_ALL_DETECTIONS=false
|
||||
STORE_HEARTBEATS=true
|
||||
STORE_DRONE_TYPE0=true
|
||||
LOG_ALL_DETECTIONS=true
|
||||
API_DEBUG=true
|
||||
|
||||
# Health Probe Simulator Configuration
|
||||
|
||||
@@ -271,4 +271,93 @@ router.delete('/:id', authenticateToken, async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* GET /api/detections/debug
|
||||
* Get all drone detections including drone_type 0 for debugging
|
||||
*/
|
||||
router.get('/debug', authenticateToken, async (req, res) => {
|
||||
try {
|
||||
const {
|
||||
device_id,
|
||||
start_date,
|
||||
end_date,
|
||||
page = 1,
|
||||
limit = 100,
|
||||
sort = 'server_timestamp',
|
||||
order = 'desc'
|
||||
} = req.query;
|
||||
|
||||
// Build where clause for filtering (includes drone_type 0)
|
||||
const whereClause = {};
|
||||
|
||||
if (device_id) {
|
||||
whereClause.device_id = device_id;
|
||||
}
|
||||
|
||||
if (start_date) {
|
||||
whereClause.server_timestamp = { ...whereClause.server_timestamp, [Op.gte]: new Date(start_date) };
|
||||
}
|
||||
|
||||
if (end_date) {
|
||||
whereClause.server_timestamp = { ...whereClause.server_timestamp, [Op.lte]: new Date(end_date) };
|
||||
}
|
||||
|
||||
// Calculate offset for pagination
|
||||
const offset = (parseInt(page) - 1) * parseInt(limit);
|
||||
|
||||
// Query ALL detections including drone_type 0
|
||||
const { count, rows: detections } = await DroneDetection.findAndCountAll({
|
||||
where: whereClause,
|
||||
include: [{
|
||||
model: Device,
|
||||
attributes: ['id', 'name', 'geo_lat', 'geo_lon', 'location_description']
|
||||
}],
|
||||
order: [[sort, order.toUpperCase()]],
|
||||
limit: parseInt(limit),
|
||||
offset: offset
|
||||
});
|
||||
|
||||
const totalPages = Math.ceil(count / parseInt(limit));
|
||||
const hasNextPage = parseInt(page) < totalPages;
|
||||
const hasPrevPage = parseInt(page) > 1;
|
||||
|
||||
// Enhance detections with drone type information and debug flags
|
||||
const enhancedDetections = detections.map(detection => {
|
||||
const droneTypeInfo = getDroneTypeInfo(detection.drone_type);
|
||||
const isDebugDetection = detection.drone_type === 0;
|
||||
|
||||
return {
|
||||
...detection.toJSON(),
|
||||
drone_type_info: droneTypeInfo,
|
||||
is_debug_detection: isDebugDetection,
|
||||
debug_note: isDebugDetection ? 'Debug detection (drone_type 0) - no alerts triggered' : null
|
||||
};
|
||||
});
|
||||
|
||||
res.json({
|
||||
detections: enhancedDetections,
|
||||
pagination: {
|
||||
currentPage: parseInt(page),
|
||||
totalPages,
|
||||
totalCount: count,
|
||||
limit: parseInt(limit),
|
||||
hasNextPage,
|
||||
hasPrevPage
|
||||
},
|
||||
debug_info: {
|
||||
includes_drone_type_0: true,
|
||||
total_detections: count,
|
||||
debug_detections: enhancedDetections.filter(d => d.is_debug_detection).length
|
||||
}
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error fetching debug detections:', error);
|
||||
res.status(500).json({
|
||||
error: 'Failed to fetch debug detections',
|
||||
details: error.message
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -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,6 +302,8 @@ async function handleDetection(req, res) {
|
||||
});
|
||||
|
||||
// Emit real-time update via Socket.IO with movement analysis (from original)
|
||||
// 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,
|
||||
@@ -340,6 +331,9 @@ async function handleDetection(req, res) {
|
||||
});
|
||||
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user