Agenda refactor
This commit is contained in:
parent
e60d98b03a
commit
45194e6a90
@ -178,7 +178,9 @@ export default async function CalendarPage() {
|
|||||||
// For each Infomaniak account, ensure there's a synced calendar
|
// For each Infomaniak account, ensure there's a synced calendar
|
||||||
// Skip if no Infomaniak accounts exist (user may only have Microsoft accounts)
|
// Skip if no Infomaniak accounts exist (user may only have Microsoft accounts)
|
||||||
if (infomaniakAccounts.length > 0) {
|
if (infomaniakAccounts.length > 0) {
|
||||||
|
console.log(`[AGENDA] Processing ${infomaniakAccounts.length} Infomaniak account(s)`);
|
||||||
for (const account of infomaniakAccounts) {
|
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)
|
// Check if a calendar sync already exists for this account (enabled or disabled)
|
||||||
// This prevents creating duplicate calendars for the same account
|
// This prevents creating duplicate calendars for the same account
|
||||||
let existingSync = await prisma.calendarSync.findFirst({
|
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
|
// No sync exists for this account - try to discover and create calendar
|
||||||
// Only create calendar if discovery succeeds
|
// Only create calendar if discovery succeeds
|
||||||
try {
|
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 { discoverInfomaniakCalendars } = await import('@/lib/services/caldav-sync');
|
||||||
const externalCalendars = await discoverInfomaniakCalendars(
|
const externalCalendars = await discoverInfomaniakCalendars(
|
||||||
account.email,
|
account.email,
|
||||||
account.password!
|
account.password
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log(`[AGENDA] Discovered ${externalCalendars.length} calendars for Infomaniak account ${account.email}`);
|
console.log(`[AGENDA] Discovered ${externalCalendars.length} calendars for Infomaniak account ${account.email}`);
|
||||||
|
|||||||
@ -30,6 +30,17 @@ export async function getInfomaniakCalDAVClient(
|
|||||||
// The actual CalDAV endpoint is at /caldav path
|
// The actual CalDAV endpoint is at /caldav path
|
||||||
const baseUrl = 'https://sync.infomaniak.com/caldav';
|
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, {
|
const client = createClient(baseUrl, {
|
||||||
username: email,
|
username: email,
|
||||||
password: password,
|
password: password,
|
||||||
@ -46,11 +57,21 @@ export async function discoverInfomaniakCalendars(
|
|||||||
password: string
|
password: string
|
||||||
): Promise<CalDAVCalendar[]> {
|
): Promise<CalDAVCalendar[]> {
|
||||||
try {
|
try {
|
||||||
|
logger.debug('Starting Infomaniak calendar discovery', {
|
||||||
|
email,
|
||||||
|
hasPassword: !!password,
|
||||||
|
passwordLength: password?.length || 0,
|
||||||
|
});
|
||||||
|
|
||||||
const client = await getInfomaniakCalDAVClient(email, password);
|
const client = await getInfomaniakCalDAVClient(email, password);
|
||||||
|
|
||||||
|
logger.debug('CalDAV client created, attempting to list directory contents');
|
||||||
|
|
||||||
// List all calendars using PROPFIND on root
|
// List all calendars using PROPFIND on root
|
||||||
const items = await client.getDirectoryContents('/');
|
const items = await client.getDirectoryContents('/');
|
||||||
|
|
||||||
|
logger.debug(`Successfully retrieved ${items.length} items from CalDAV server`);
|
||||||
|
|
||||||
const calendars: CalDAVCalendar[] = [];
|
const calendars: CalDAVCalendar[] = [];
|
||||||
|
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user