Rework Photography admin dashboard
All checks were successful
Build & Push Docker Image to Gitea Registry / build-and-push (push) Successful in 30s
All checks were successful
Build & Push Docker Image to Gitea Registry / build-and-push (push) Successful in 30s
This commit is contained in:
@@ -4,7 +4,6 @@ const jwt = require('jsonwebtoken');
|
||||
const bcrypt = require('bcryptjs');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { execFile } = require('child_process');
|
||||
const archiver = require('archiver');
|
||||
const db = require('./database');
|
||||
|
||||
@@ -20,10 +19,7 @@ const DEV_FULLS_DIR = path.join(__dirname, '../images/fulls');
|
||||
const DEV_THUMBS_DIR = path.join(__dirname, '../images/thumbs');
|
||||
const FULLS_DIR = process.env.FULLS_DIR || (fs.existsSync(DEFAULT_FULLS_DIR) ? DEFAULT_FULLS_DIR : DEV_FULLS_DIR);
|
||||
const THUMBS_DIR = process.env.THUMBS_DIR || (fs.existsSync(DEFAULT_THUMBS_DIR) ? DEFAULT_THUMBS_DIR : DEV_THUMBS_DIR);
|
||||
const SYNC_IMAGE = process.env.SYNC_IMAGE || 'git.mischlabs.de/mrdiderot/photography:latest';
|
||||
const SYNC_CONTAINER = process.env.SYNC_CONTAINER || 'photography-website';
|
||||
const IMAGE_RE = /\.(jpg|jpeg|png|gif|webp)$/i;
|
||||
let syncInProgress = false;
|
||||
|
||||
console.log('Using full-size images at', FULLS_DIR);
|
||||
console.log('Using thumbnails at', THUMBS_DIR);
|
||||
@@ -151,12 +147,6 @@ function serveProtectedImage(req, res) {
|
||||
});
|
||||
}
|
||||
|
||||
function runDocker(args, callback) {
|
||||
execFile('docker', args, { timeout: 5 * 60 * 1000 }, (err, stdout, stderr) => {
|
||||
callback(err, `${stdout || ''}${stderr || ''}`.trim());
|
||||
});
|
||||
}
|
||||
|
||||
// ==================== AUTH API ====================
|
||||
|
||||
app.post('/api/auth/login', (req, res) => {
|
||||
@@ -418,41 +408,6 @@ app.post('/api/admin/assign', requireAdmin, (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.post('/api/admin/sync', requireAdmin, (req, res) => {
|
||||
if (syncInProgress) {
|
||||
return res.status(409).json({ error: 'Sync laeuft bereits' });
|
||||
}
|
||||
|
||||
syncInProgress = true;
|
||||
runDocker(['pull', SYNC_IMAGE], (pullErr, pullOutput) => {
|
||||
syncInProgress = false;
|
||||
|
||||
if (pullErr) {
|
||||
console.error('Sync pull failed:', pullOutput || pullErr.message);
|
||||
return res.status(500).json({
|
||||
error: 'Docker pull fehlgeschlagen',
|
||||
details: pullOutput || pullErr.message
|
||||
});
|
||||
}
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
message: 'Neues Image geladen. Container startet neu.',
|
||||
output: pullOutput
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
runDocker(['restart', SYNC_CONTAINER], (restartErr, restartOutput) => {
|
||||
if (restartErr) {
|
||||
console.error('Sync restart failed:', restartOutput || restartErr.message);
|
||||
return;
|
||||
}
|
||||
console.log('Sync restart complete:', restartOutput);
|
||||
});
|
||||
}, 500);
|
||||
});
|
||||
});
|
||||
|
||||
// ==================== DOWNLOAD API ====================
|
||||
|
||||
function isValidName(name) {
|
||||
|
||||
Reference in New Issue
Block a user