const core = require('../../cores/logs.local') const router = require('express').Router(); router.post('/start', async (req, res) => { const { name } = req.body; const session = await core.startRecording(name); res.status(200).send({ status: 'Started', session: session }); }); router.get('/', (req, res) => { const session = core.getSession(); if (session) { res.status(200).send(session); } else { res.status(404).send({ session: 'Nessuna sessione attiva' }); } }); router.get('/list', async (req, res) => { const logs = await core.listLogs(); res.status(200).send(logs); }); router.get('/:log', async (req, res) => { const { log } = req.params const data = await core.getLog(log); if (data) { res.status(200).send(data); } else { res.status(404).send({ error: 'Log non trovato' }); } }); router.get('/download/:name', (req, res) => { const name = req.params.name; const filePath = core.getLogFile(name); if (filePath) { res.download(filePath); } else { res.status(404).send({ error: 'File non trovato' }); } }); router.post('/stop', async (req, res) => { await core.stopRecording(); res.status(200).send({ status: 'Stopped' }); }); module.exports = router;