Agenda refactor

This commit is contained in:
alma 2026-01-14 20:30:00 +01:00
parent e60d98b03a
commit 45194e6a90
2 changed files with 32 additions and 1 deletions

View File

@ -178,7 +178,9 @@ export default async function CalendarPage() {
// For each Infomaniak account, ensure there's a synced calendar
// Skip if no Infomaniak accounts exist (user may only have Microsoft accounts)
if (infomaniakAccounts.length > 0) {
console.log(`[AGENDA] Processing ${infomaniakAccounts.length} Infomaniak account(s)`);
for (const account of infomaniakAccounts) {
console.log(`[AGENDA] Processing Infomaniak account: ${account.email}, hasPassword: ${!!account.password}, passwordLength: ${account.password?.length || 0}`);
// Check if a calendar sync already exists for this account (enabled or disabled)
// This prevents creating duplicate calendars for the same account
let existingSync = await prisma.calendarSync.findFirst({
@ -339,10 +341,18 @@ export default async function CalendarPage() {
// No sync exists for this account - try to discover and create calendar
// Only create calendar if discovery succeeds
try {
// Verify password is available
if (!account.password) {
console.log(`[AGENDA] Skipping Infomaniak account ${account.email} - no password available`);
continue;
}
console.log(`[AGENDA] Attempting to discover calendars for Infomaniak account ${account.email} (password length: ${account.password.length})`);
const { discoverInfomaniakCalendars } = await import('@/lib/services/caldav-sync');
const externalCalendars = await discoverInfomaniakCalendars(
account.email,
account.password!
account.password
);
console.log(`[AGENDA] Discovered ${externalCalendars.length} calendars for Infomaniak account ${account.email}`);

View File

@ -30,6 +30,17 @@ export async function getInfomaniakCalDAVClient(
// The actual CalDAV endpoint is at /caldav path
const baseUrl = 'https://sync.infomaniak.com/caldav';
if (!password || password.trim() === '') {
throw new Error('Password is required for Infomaniak CalDAV authentication');
}
logger.debug('Creating Infomaniak CalDAV client', {
email,
baseUrl,
hasPassword: !!password,
passwordLength: password.length,
});
const client = createClient(baseUrl, {
username: email,
password: password,
@ -46,11 +57,21 @@ export async function discoverInfomaniakCalendars(
password: string
): Promise<CalDAVCalendar[]> {
try {
logger.debug('Starting Infomaniak calendar discovery', {
email,
hasPassword: !!password,
passwordLength: password?.length || 0,
});
const client = await getInfomaniakCalDAVClient(email, password);
logger.debug('CalDAV client created, attempting to list directory contents');
// List all calendars using PROPFIND on root
const items = await client.getDirectoryContents('/');
logger.debug(`Successfully retrieved ${items.length} items from CalDAV server`);
const calendars: CalDAVCalendar[] = [];
for (const item of items) {