feat: refactor parsing and scanning logic for test files
- Updated `parseFilename` to `parseTargetFilename` and modified its return structure to include `test_id` instead of `file_id`. - Introduced `parseResultFilename` to extract `test_id` and `device` from result file names. - Enhanced `fullScan` to separately handle target and results directories, improving clarity and functionality. - Updated database interactions to use `test_id` instead of `file_id` across various modules. - Added a new `/rescan` endpoint to trigger a full scan of target and results directories. - Improved logging and error handling throughout the scanning process. - Introduced `parseTputRssi` to extract throughput and RSSI data from log files.
This commit is contained in:
@@ -58,4 +58,23 @@ router.post('/', async (req, res) => {
|
||||
res.json({ ok: true, testCount: null, completedCount: null });
|
||||
});
|
||||
|
||||
router.post('/rescan', async (req, res) => {
|
||||
const targetDir = getConfig('target_dir');
|
||||
const resultsDir = getConfig('results_dir');
|
||||
if (!targetDir || !resultsDir) {
|
||||
return res.status(400).json({ error: 'Directories not configured' });
|
||||
}
|
||||
try {
|
||||
await fullScan(targetDir, resultsDir);
|
||||
} catch (e) {
|
||||
console.error('[config] rescan error:', e.message);
|
||||
return res.status(500).json({ error: `Scan failed: ${e.message}` });
|
||||
}
|
||||
startWatching(targetDir, resultsDir);
|
||||
const tests = getAllTests();
|
||||
const completed = tests.filter(t => t.completed).length;
|
||||
console.log(`[config] Rescan complete — ${tests.length} tests, ${completed} completed`);
|
||||
res.json({ ok: true, testCount: tests.length, completedCount: completed });
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -26,7 +26,7 @@ router.get('/', (req, res) => {
|
||||
tests.sort((a, b) => {
|
||||
const ia = a.interference || '';
|
||||
const ib = b.interference || '';
|
||||
return ia.localeCompare(ib) || (a.file_id || '').localeCompare(b.file_id || '');
|
||||
return ia.localeCompare(ib) || (a.test_id || '').localeCompare(b.test_id || '');
|
||||
});
|
||||
|
||||
res.json(tests);
|
||||
|
||||
Reference in New Issue
Block a user