fix: prune deleted Synology calendars from stored list

When fetching events, refresh the calendar list from the Synology
server and remove any stored calendars that no longer exist. This
stops repeated "Calendar unavailable" errors from deleted calendars.

v1.37.3
This commit is contained in:
mARTin 2026-03-16 22:28:28 +01:00
parent a32e5601d0
commit 0fa2893e10
2 changed files with 33 additions and 8 deletions

View File

@ -1,6 +1,6 @@
{
"name": "my-weekly-todo-list",
"version": "1.37.2",
"version": "1.37.3",
"description": "A web-based weekly task management application that organizes to-dos and calendar events in a single, intuitive weekly view",
"main": "index.js",
"scripts": {

View File

@ -425,22 +425,47 @@ export const getCalendarEvents = async (
continue;
}
// Use stored calendar selection (same pattern as Outlook/Google)
// Fetch live calendar list from Synology to detect deleted calendars
let calendarIds: string[] = [];
let calendars: any[] = [];
let freshCalendars: any[] = [];
try {
freshCalendars = await getSynologyCalendars(serverUrl, username, password);
} catch (err) {
console.error('[CALENDAR] Synology: failed to fetch calendar list:', err);
}
const freshIds = new Set(freshCalendars.map(c => c.id));
if (connection.calendars && Array.isArray(connection.calendars) && connection.calendars.length > 0) {
calendars = connection.calendars as any[];
const storedCalendars = connection.calendars as any[];
// Remove calendars that no longer exist on the server
calendars = storedCalendars.filter((c: any) => freshIds.has(c.id));
if (calendars.length < storedCalendars.length) {
const removed = storedCalendars.length - calendars.length;
console.log(`[CALENDAR] Synology: pruned ${removed} deleted calendar(s) from stored list`);
// Update stored calendars in DB to remove stale entries
try {
await prisma.calendarConnection.update({
where: { id: connection.id },
data: { calendars: calendars },
});
} catch (dbErr) {
console.error('[CALENDAR] Synology: failed to update stored calendars:', dbErr);
}
}
calendarIds = calendars
.filter((c: any) => c.selected !== false)
.map((c: any) => c.id);
console.log('[CALENDAR] Synology: using stored calendars, selected:', calendarIds.length, 'of', calendars.length);
} else {
// Fallback: fetch fresh from server if no stored calendars
console.log('[CALENDAR] Synology: no stored calendars, fetching from server...');
const fresh = await getSynologyCalendars(serverUrl, username, password);
calendars = fresh;
calendarIds = fresh.map(c => c.id);
// No stored calendars: use fresh list
console.log('[CALENDAR] Synology: no stored calendars, using fresh list');
calendars = freshCalendars;
calendarIds = freshCalendars.map(c => c.id);
}
if (calendarIds.length === 0) {