Log and Database

This commit is contained in:
root
2025-09-29 19:04:26 +00:00
parent ba0905e2b9
commit 241a509a15
15 changed files with 532 additions and 8 deletions
+59
View File
@@ -6,6 +6,7 @@ import http from 'http';
import { Server } from 'socket.io';
import path from 'path';
import { fileURLToPath } from 'url';
import { db } from './db/index.js';
dotenv.config();
@@ -91,6 +92,64 @@ app.get('/api/stacks', async (req, res) => {
}
});
// Redeploy-Logs abrufen
app.get('/api/logs', (req, res) => {
const { stackId, status, from, to } = req.query;
const limit = Math.min(parseInt(req.query.limit, 10) || 100, 500);
const offset = Math.max(parseInt(req.query.offset, 10) || 0, 0);
const filters = [];
const params = { limit, offset };
if (stackId) {
filters.push('stack_id = @stackId');
params.stackId = stackId;
}
if (status) {
filters.push('status = @status');
params.status = status;
}
if (from) {
filters.push('timestamp >= @from');
params.from = from;
}
if (to) {
filters.push('timestamp <= @to');
params.to = to;
}
const whereClause = filters.length ? `WHERE ${filters.join(' AND ')}` : '';
const query = `
SELECT
id,
timestamp,
stack_id AS stackId,
stack_name AS stackName,
status,
message,
endpoint
FROM redeploy_logs
${whereClause}
ORDER BY datetime(timestamp) DESC
LIMIT @limit OFFSET @offset
`;
try {
const stmt = db.prepare(query);
const logs = stmt.all(params);
res.json(logs);
} catch (err) {
console.error('❌ Fehler beim Abrufen der Redeploy-Logs:', err.message);
if (err.message.includes('no such table')) {
return res.status(500).json({ error: 'redeploy_logs table nicht gefunden. Bitte Migration ausführen.' });
}
res.status(500).json({ error: 'Fehler beim Abrufen der Redeploy-Logs' });
}
});
// Einzel-Redeploy
app.put('/api/stacks/:id/redeploy', async (req, res) => {
const { id } = req.params;