Add frontend git update button and backend update endpoint

This commit is contained in:
J0Z1L 2026-02-28 00:12:10 +01:00
parent 712d29921d
commit cd371a70be
5 changed files with 75 additions and 0 deletions

View file

@ -2,9 +2,12 @@ require('dotenv').config();
const express = require('express');
const path = require('path');
const axios = require('axios');
const { execFile } = require('child_process');
const { promisify } = require('util');
const app = express();
const port = Number(process.env.PORT || 3000);
const execFileAsync = promisify(execFile);
const lidarrUrl = (process.env.LIDARR_URL || '').replace(/\/$/, '');
const lidarrApiKey = process.env.LIDARR_API_KEY || '';
@ -40,6 +43,39 @@ function lidarrHeaders() {
};
}
async function runGit(args) {
const { stdout } = await execFileAsync('git', args, {
cwd: __dirname,
timeout: 20000
});
return String(stdout || '').trim();
}
async function updateFrontendFromGit() {
if (!require('fs').existsSync(path.join(__dirname, '.git'))) {
throw new Error('Kein Git-Repository im Container/Projektpfad gefunden.');
}
try {
await runGit(['--version']);
} catch (_err) {
throw new Error('git ist nicht installiert.');
}
const before = await runGit(['rev-parse', '--short', 'HEAD']);
const branch = await runGit(['rev-parse', '--abbrev-ref', 'HEAD']);
const dirty = await runGit(['status', '--porcelain']);
if (dirty) {
throw new Error('Lokale Aenderungen vorhanden. Update per Button ist blockiert.');
}
await runGit(['fetch', '--prune', 'origin']);
await runGit(['pull', '--ff-only', 'origin', branch]);
const after = await runGit(['rev-parse', '--short', 'HEAD']);
return { before, after, branch, updated: before !== after };
}
async function lidarrRequest(method, endpoint, data, params) {
if (!hasLidarrConfig()) {
throw new Error('Lidarr-Konfiguration unvollstaendig.');
@ -451,6 +487,15 @@ app.post('/api/lidarr/update-library', async (_req, res) => {
}
});
app.post('/api/system/update-frontend', async (_req, res) => {
try {
const result = await updateFrontendFromGit();
res.json({ success: true, ...result });
} catch (err) {
res.status(500).json({ error: err.message });
}
});
app.get('*', (_req, res) => {
res.sendFile(path.join(__dirname, 'public', 'index.html'));
});