Fix Kalender-Suche: Sync-Fehler sichtbar, force-sync beim Kalender-Refresh, Backdrop opak

This commit is contained in:
2026-06-05 16:45:47 +02:00
parent 197ea6fbff
commit ca55ecbf5f
3 changed files with 24 additions and 13 deletions

View File

@@ -71,12 +71,6 @@ router.post('/sync-calendar', authenticate, async (req, res) => {
}
}
const ins = db.prepare(`
INSERT INTO calendar_event_cache
(feed_id, user_id, summary, description, location, start_dt, end_dt, synced_at)
VALUES (?,?,?,?,?,?,?,datetime('now','localtime'))
`);
let totalSynced = 0;
const errors = [];
@@ -85,16 +79,27 @@ router.post('/sync-calendar', authenticate, async (req, res) => {
const raw = await fetchIcal(feed.url);
if (!raw) { errors.push(`${feed.name}: kein gültiger iCal-Feed`); continue; }
const events = parseIcal(raw);
if (!events.length) { errors.push(`${feed.name}: 0 Events geparst`); continue; }
// prepare INSIDE try-catch wirft wenn Tabelle nicht existiert
const ins = db.prepare(`
INSERT INTO calendar_event_cache
(feed_id, user_id, summary, description, location, start_dt, end_dt, synced_at)
VALUES (?,?,?,?,?,?,?,datetime('now','localtime'))
`);
db.transaction(() => {
db.prepare('DELETE FROM calendar_event_cache WHERE feed_id=?').run(feed.id);
events.slice(0, 300).forEach(ev =>
ins.run(feed.id, uid, ev.summary, ev.description, ev.location, ev.start, ev.end)
ins.run(feed.id, uid, ev.summary||'', ev.description||'', ev.location||'', ev.start||'', ev.end||'')
);
})();
totalSynced += events.length;
} catch(e) { errors.push(`${feed.name}: ${e.message}`); }
} catch(e) {
console.error(`[CalendarSync] Feed "${feed.name}" (${feed.url}): ${e.message}`);
errors.push(`${feed.name}: ${e.message}`);
}
}
console.log(`[CalendarSync] uid=${uid} synced=${totalSynced} feeds=${feeds.length} errors=${errors.length}`);
res.json({ ok: true, synced: totalSynced, feeds: feeds.length, errors });
});