Fix jwt-token

This commit is contained in:
2025-09-22 08:22:17 +02:00
parent 3a94adcdbd
commit 8c8556314f

View File

@@ -357,7 +357,11 @@ class AlertService {
// PRIORITY 9: Cooldown period check // PRIORITY 9: Cooldown period check
if (rule.cooldown_period > 0) { if (rule.cooldown_period > 0) {
const cooldownStart = new Date(Date.now() - rule.cooldown_period * 1000); const cooldownStart = new Date(Date.now() - rule.cooldown_period * 1000);
const recentAlert = await AlertLog.findOne({
console.log(`🔍 Checking cooldown for rule "${rule.name}" (${rule.cooldown_period}s) - looking for alerts after ${cooldownStart.toISOString()}`);
// First, get all recent alert logs for this rule that were successfully sent
const recentAlerts = await AlertLog.findAll({
where: { where: {
alert_rule_id: rule.id, alert_rule_id: rule.id,
status: 'sent', status: 'sent',
@@ -368,18 +372,33 @@ class AlertService {
include: [{ include: [{
model: DroneDetection, model: DroneDetection,
as: 'detection', as: 'detection',
where: { attributes: ['device_id'],
device_id: detection.device_id
// Removed drone_id check - cooldown applies per device, not per device+drone combination
// This prevents alert spam when multiple drones are detected by the same device
},
required: false // Allow alerts without detection_id (like device offline alerts) required: false // Allow alerts without detection_id (like device offline alerts)
}] }]
}); });
if (recentAlert) { console.log(`🔍 Found ${recentAlerts.length} recent alerts for rule "${rule.name}"`);
console.log(`❌ Rule "${rule.name}": Still in cooldown period (last alert: ${recentAlert.sent_at})`);
// Check if any recent alert was for the same device
const deviceAlert = recentAlerts.find(alert => {
console.log(`🔍 Checking alert: detection device_id=${alert.detection?.device_id}, alert device_id=${alert.device_id}, target device_id=${detection.device_id}, sent_at=${alert.sent_at}`);
// For alerts with detection, check device_id match
if (alert.detection && alert.detection.device_id === detection.device_id) {
return true;
}
// For alerts without detection (like device offline), check device_id field directly
if (!alert.detection && alert.device_id === detection.device_id) {
return true;
}
return false; return false;
});
if (deviceAlert) {
console.log(`❌ Rule "${rule.name}": Still in cooldown period for device ${detection.device_id} (last alert: ${deviceAlert.sent_at})`);
return false;
} else {
console.log(`✅ Rule "${rule.name}": Cooldown period expired or no recent alerts for device ${detection.device_id}`);
} }
} }