This commit is contained in:
Matthias Hochmeister
2026-03-13 14:01:06 +01:00
parent 3361f1e28d
commit 7215e7f472
10 changed files with 119 additions and 17 deletions

View File

@@ -46,7 +46,7 @@ function msUntilMidnight(): number {
return midnight.getTime() - now.getTime();
}
async function runSync(): Promise<void> {
async function runSync(force = false): Promise<void> {
if (syncRunning) {
log('Sync already in progress, skipping');
return;
@@ -64,9 +64,10 @@ async function runSync(): Promise<void> {
});
try {
if (force) log('Force mode: ON');
log('Starting FDISK sync');
const { members, ausbildungen } = await scrapeAll(username, password);
await syncToDatabase(pool, members, ausbildungen);
await syncToDatabase(pool, members, ausbildungen, force);
log(`Sync complete — ${members.length} members, ${ausbildungen.length} Ausbildungen`);
} finally {
syncRunning = false;
@@ -87,9 +88,20 @@ function startHttpServer(port: number) {
res.end(JSON.stringify({ running: true, message: 'Sync already in progress' }));
return;
}
res.writeHead(200);
res.end(JSON.stringify({ started: true }));
runSync().catch(err => log(`ERROR during manual sync: ${err.message}`));
let body = '';
req.on('data', (chunk: Buffer) => { body += chunk.toString(); });
req.on('end', () => {
let force = false;
try {
const parsed = JSON.parse(body);
force = parsed?.force === true;
} catch {
// no body or invalid JSON — force stays false
}
res.writeHead(200);
res.end(JSON.stringify({ started: true, force }));
runSync(force).catch(err => log(`ERROR during manual sync: ${err.message}`));
});
} else {
res.writeHead(404);
res.end(JSON.stringify({ message: 'Not found' }));