fix: corretto tempo di visualizzazione che non considerava la variabile. style: aggiunto pulsante per eliminare precedenti env.
This commit is contained in:
1 parent
cf500aabb3
commit
ec1fb25d4e
5 files changed
+101
-4
No files matched your search
@@ -67,6 +67,7 @@ router.post('/env', async (req, res) => {
|
||||
|
||||
// Write updated content to disk
|
||||
fs.writeFileSync(envPath, content, 'utf8');
|
||||
try { require('dotenv').config({ path: envPath, override: true }); } catch (_) {}
|
||||
|
||||
// Save snapshot in history table
|
||||
const info = db.prepare(`
|
||||
@@ -112,6 +113,7 @@ router.post('/env/restore/:history_id', async (req, res) => {
|
||||
|
||||
// Write snapshot content to disk
|
||||
fs.writeFileSync(envPath, record.content, 'utf8');
|
||||
try { require('dotenv').config({ path: envPath, override: true }); } catch (_) {}
|
||||
|
||||
// Insert new history record documenting the restore operation
|
||||
const restoreNote = `Ripristinato alla versione #${record.id} del ${record.created_at}`;
|
||||
@@ -144,4 +146,41 @@ router.post('/env/restore/:history_id', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// DELETE /api/config/env/history/:id — Delete a specific .env history entry
|
||||
router.delete('/env/history/:id', async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const operatorId = parseInt(req.headers['x-agent-id'] || '1', 10);
|
||||
const agentName = await resolveAgentName(operatorId);
|
||||
|
||||
const record = db.prepare('SELECT * FROM env_history WHERE id = ?').get(id);
|
||||
if (!record) {
|
||||
return res.status(404).json({ error: 'Versione di storico non trovata' });
|
||||
}
|
||||
|
||||
db.prepare('DELETE FROM env_history WHERE id = ?').run(id);
|
||||
|
||||
logAttivita({
|
||||
agente_id: operatorId,
|
||||
agente_nome: agentName,
|
||||
titolo_azione: 'Eliminazione Storico .env',
|
||||
azione: { deleted_history_id: id },
|
||||
esito: 'successo',
|
||||
});
|
||||
|
||||
const history = db.prepare(`
|
||||
SELECT * FROM env_history ORDER BY id DESC LIMIT 100
|
||||
`).all();
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
message: `Versione #${id} dello storico eliminata con successo!`,
|
||||
history,
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('Error deleting .env history entry:', err);
|
||||
res.status(500).json({ error: 'Errore durante l\'eliminazione della versione dello storico', message: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
Reference in new issue
Block a user