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:
parent
a32e5601d0
commit
0fa2893e10
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "my-weekly-todo-list",
|
"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",
|
"description": "A web-based weekly task management application that organizes to-dos and calendar events in a single, intuitive weekly view",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@ -425,22 +425,47 @@ export const getCalendarEvents = async (
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use stored calendar selection (same pattern as Outlook/Google)
|
// Fetch live calendar list from Synology to detect deleted calendars
|
||||||
let calendarIds: string[] = [];
|
let calendarIds: string[] = [];
|
||||||
let calendars: any[] = [];
|
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) {
|
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
|
calendarIds = calendars
|
||||||
.filter((c: any) => c.selected !== false)
|
.filter((c: any) => c.selected !== false)
|
||||||
.map((c: any) => c.id);
|
.map((c: any) => c.id);
|
||||||
console.log('[CALENDAR] Synology: using stored calendars, selected:', calendarIds.length, 'of', calendars.length);
|
console.log('[CALENDAR] Synology: using stored calendars, selected:', calendarIds.length, 'of', calendars.length);
|
||||||
} else {
|
} else {
|
||||||
// Fallback: fetch fresh from server if no stored calendars
|
// No stored calendars: use fresh list
|
||||||
console.log('[CALENDAR] Synology: no stored calendars, fetching from server...');
|
console.log('[CALENDAR] Synology: no stored calendars, using fresh list');
|
||||||
const fresh = await getSynologyCalendars(serverUrl, username, password);
|
calendars = freshCalendars;
|
||||||
calendars = fresh;
|
calendarIds = freshCalendars.map(c => c.id);
|
||||||
calendarIds = fresh.map(c => c.id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (calendarIds.length === 0) {
|
if (calendarIds.length === 0) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user