Fix jwt-token
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
const express = require('express');
|
||||
const { ApiDebugLogger } = require('../utils/apiDebugLogger');
|
||||
const { DroneDetection, Heartbeat } = require('../models');
|
||||
const { Op } = require('sequelize');
|
||||
const { authenticateToken } = require('../middleware/auth');
|
||||
|
||||
const router = express.Router();
|
||||
const logger = new ApiDebugLogger();
|
||||
@@ -21,4 +24,108 @@ router.get('/debug-test', (req, res) => {
|
||||
res.json(response);
|
||||
});
|
||||
|
||||
// Get recent detection payloads with raw data
|
||||
router.get('/detection-payloads', authenticateToken, async (req, res) => {
|
||||
try {
|
||||
const { limit = 50, offset = 0, device_id } = req.query;
|
||||
|
||||
const whereClause = {
|
||||
raw_payload: { [Op.ne]: null }
|
||||
};
|
||||
|
||||
if (device_id) {
|
||||
whereClause.device_id = device_id;
|
||||
}
|
||||
|
||||
const detections = await DroneDetection.findAll({
|
||||
where: whereClause,
|
||||
order: [['server_timestamp', 'DESC']],
|
||||
limit: parseInt(limit),
|
||||
offset: parseInt(offset),
|
||||
attributes: [
|
||||
'id', 'device_id', 'drone_id', 'drone_type', 'rssi', 'freq',
|
||||
'server_timestamp', 'device_timestamp', 'raw_payload'
|
||||
]
|
||||
});
|
||||
|
||||
console.log(`🔍 Retrieved ${detections.length} detection payloads for debugging`);
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
data: detections,
|
||||
total: detections.length,
|
||||
filters: { device_id, limit, offset }
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error fetching detection payloads:', error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
error: 'Failed to fetch detection payloads'
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Get recent heartbeat payloads with raw data
|
||||
router.get('/heartbeat-payloads', authenticateToken, async (req, res) => {
|
||||
try {
|
||||
const { limit = 50, offset = 0, device_id } = req.query;
|
||||
|
||||
const whereClause = {
|
||||
raw_payload: { [Op.ne]: null }
|
||||
};
|
||||
|
||||
if (device_id) {
|
||||
whereClause.device_id = device_id;
|
||||
}
|
||||
|
||||
const heartbeats = await Heartbeat.findAll({
|
||||
where: whereClause,
|
||||
order: [['received_at', 'DESC']],
|
||||
limit: parseInt(limit),
|
||||
offset: parseInt(offset),
|
||||
attributes: [
|
||||
'id', 'device_id', 'device_key', 'signal_strength', 'battery_level',
|
||||
'temperature', 'received_at', 'raw_payload'
|
||||
]
|
||||
});
|
||||
|
||||
console.log(`🔍 Retrieved ${heartbeats.length} heartbeat payloads for debugging`);
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
data: heartbeats,
|
||||
total: heartbeats.length,
|
||||
filters: { device_id, limit, offset }
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error fetching heartbeat payloads:', error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
error: 'Failed to fetch heartbeat payloads'
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Get debug configuration status
|
||||
router.get('/config', authenticateToken, (req, res) => {
|
||||
const config = {
|
||||
STORE_HEARTBEATS: process.env.STORE_HEARTBEATS === 'true',
|
||||
STORE_DRONE_TYPE0: process.env.STORE_DRONE_TYPE0 === 'true',
|
||||
LOG_ALL_DETECTIONS: process.env.LOG_ALL_DETECTIONS === 'true',
|
||||
API_DEBUG: process.env.API_DEBUG === 'true',
|
||||
STORE_RAW_PAYLOAD: process.env.STORE_RAW_PAYLOAD === 'true',
|
||||
NODE_ENV: process.env.NODE_ENV
|
||||
};
|
||||
|
||||
console.log('🔍 Debug configuration requested');
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
config,
|
||||
timestamp: new Date().toISOString()
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
Reference in New Issue
Block a user