Agenda refactor
This commit is contained in:
parent
fd24dfbd21
commit
e17cdf21d1
@ -45,34 +45,29 @@ export async function discoverInfomaniakCalendars(
|
|||||||
password: string
|
password: string
|
||||||
): Promise<CalDAVCalendar[]> {
|
): Promise<CalDAVCalendar[]> {
|
||||||
try {
|
try {
|
||||||
|
console.log(`[CALDAV] Starting calendar discovery for ${email}`);
|
||||||
const client = await getInfomaniakCalDAVClient(email, password);
|
const client = await getInfomaniakCalDAVClient(email, password);
|
||||||
|
|
||||||
// List all calendars using PROPFIND on root
|
// List all calendars using PROPFIND on root
|
||||||
logger.debug('Discovering Infomaniak calendars', { email });
|
console.log(`[CALDAV] Fetching directory contents from root (/)`);
|
||||||
const items = await client.getDirectoryContents('/');
|
const items = await client.getDirectoryContents('/');
|
||||||
|
|
||||||
logger.debug('Found items in root directory', {
|
console.log(`[CALDAV] Found ${items.length} items in root directory:`,
|
||||||
email,
|
items.map(item => ({ filename: item.filename, type: item.type, basename: item.basename }))
|
||||||
itemsCount: items.length,
|
);
|
||||||
items: items.map(item => ({ filename: item.filename, type: item.type })),
|
|
||||||
});
|
|
||||||
|
|
||||||
const calendars: CalDAVCalendar[] = [];
|
const calendars: CalDAVCalendar[] = [];
|
||||||
|
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
// Skip non-directories, root, and special directories like /principals
|
// Skip non-directories, root, and special directories like /principals
|
||||||
if (item.type !== 'directory' || item.filename === '/' || item.filename === '/principals') {
|
if (item.type !== 'directory' || item.filename === '/' || item.filename === '/principals') {
|
||||||
logger.debug('Skipping item', {
|
console.log(`[CALDAV] Skipping item: ${item.filename} (type: ${item.type})`);
|
||||||
filename: item.filename,
|
|
||||||
type: item.type,
|
|
||||||
reason: item.type !== 'directory' ? 'not a directory' : 'special directory',
|
|
||||||
});
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get calendar properties to verify it's actually a calendar
|
// Get calendar properties to verify it's actually a calendar
|
||||||
try {
|
try {
|
||||||
logger.debug('Checking if item is a calendar', { filename: item.filename });
|
console.log(`[CALDAV] Checking if ${item.filename} is a calendar...`);
|
||||||
const props = await client.customRequest(item.filename, {
|
const props = await client.customRequest(item.filename, {
|
||||||
method: 'PROPFIND',
|
method: 'PROPFIND',
|
||||||
headers: {
|
headers: {
|
||||||
@ -96,18 +91,15 @@ export async function discoverInfomaniakCalendars(
|
|||||||
dataStr.includes('calendar') ||
|
dataStr.includes('calendar') ||
|
||||||
dataStr.includes('urn:ietf:params:xml:ns:caldav');
|
dataStr.includes('urn:ietf:params:xml:ns:caldav');
|
||||||
|
|
||||||
logger.debug('Calendar check result', {
|
console.log(`[CALDAV] Calendar check for ${item.filename}:`, {
|
||||||
filename: item.filename,
|
|
||||||
isCalendar,
|
isCalendar,
|
||||||
hasData: !!props.data,
|
hasData: !!props.data,
|
||||||
dataPreview: props.data ? props.data.substring(0, 500) : 'no data',
|
dataLength: dataStr.length,
|
||||||
|
dataPreview: dataStr.substring(0, 300),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!isCalendar) {
|
if (!isCalendar) {
|
||||||
logger.debug('Skipping non-calendar directory', {
|
console.log(`[CALDAV] Skipping ${item.filename} - not a calendar (resourcetype check failed)`);
|
||||||
filename: item.filename,
|
|
||||||
reason: 'resourcetype does not indicate calendar',
|
|
||||||
});
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,38 +114,31 @@ export async function discoverInfomaniakCalendars(
|
|||||||
color: color,
|
color: color,
|
||||||
};
|
};
|
||||||
|
|
||||||
logger.debug('Found valid calendar', calendar);
|
console.log(`[CALDAV] ✅ Found valid calendar:`, calendar);
|
||||||
calendars.push(calendar);
|
calendars.push(calendar);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Error fetching calendar properties', {
|
console.error(`[CALDAV] Error fetching calendar properties for ${item.filename}:`,
|
||||||
calendar: item.filename,
|
error instanceof Error ? error.message : String(error)
|
||||||
error: error instanceof Error ? error.message : String(error),
|
);
|
||||||
});
|
|
||||||
// Don't add calendars that fail property fetch - they might not be calendars
|
// Don't add calendars that fail property fetch - they might not be calendars
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info('Infomaniak calendar discovery completed', {
|
console.log(`[CALDAV] Discovery completed: found ${calendars.length} calendars for ${email}`);
|
||||||
email,
|
if (calendars.length > 0) {
|
||||||
calendarsFound: calendars.length,
|
console.log(`[CALDAV] Calendars:`, calendars.map(cal => ({ id: cal.id, name: cal.name, url: cal.url })));
|
||||||
calendars: calendars.map(cal => ({ id: cal.id, name: cal.name, url: cal.url })),
|
}
|
||||||
});
|
|
||||||
|
|
||||||
return calendars;
|
return calendars;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||||
const errorDetails = error instanceof Error ? {
|
const errorStack = error instanceof Error ? error.stack?.substring(0, 500) : undefined;
|
||||||
name: error.name,
|
|
||||||
message: error.message,
|
|
||||||
stack: error.stack?.substring(0, 500), // More stack for debugging
|
|
||||||
} : { raw: String(error) };
|
|
||||||
|
|
||||||
// Log as error for debugging, but don't throw to avoid breaking the page
|
console.error(`[CALDAV] ❌ Calendar discovery failed for ${email}:`, {
|
||||||
logger.error('Infomaniak calendar discovery failed', {
|
|
||||||
email,
|
|
||||||
error: errorMessage,
|
error: errorMessage,
|
||||||
errorDetails,
|
stack: errorStack,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Ne pas faire échouer toute la page agenda si la découverte échoue
|
// Ne pas faire échouer toute la page agenda si la découverte échoue
|
||||||
// On retourne simplement une liste vide -> pas de sync auto possible
|
// On retourne simplement une liste vide -> pas de sync auto possible
|
||||||
return [];
|
return [];
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user