From b7f889e011f761f53d23dd35836d94475fe43849 Mon Sep 17 00:00:00 2001 From: alma Date: Sun, 20 Apr 2025 19:26:49 +0200 Subject: [PATCH] carnet panel contact --- app/api/nextcloud/files/content/route.ts | 1 + app/carnet/page.tsx | 46 ++++++++++++++---------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/app/api/nextcloud/files/content/route.ts b/app/api/nextcloud/files/content/route.ts index d80b7566..16bb356b 100644 --- a/app/api/nextcloud/files/content/route.ts +++ b/app/api/nextcloud/files/content/route.ts @@ -61,6 +61,7 @@ export async function GET(request: Request) { // Use either id or path to fetch the file content const filePath = id || path; const content = await client.getFileContents(filePath, { format: 'text' }); + console.log('Raw file content:', content); return NextResponse.json({ content }); } catch (error) { console.error('Error fetching file content:', error); diff --git a/app/carnet/page.tsx b/app/carnet/page.tsx index 963f4e8f..c3828baa 100644 --- a/app/carnet/page.tsx +++ b/app/carnet/page.tsx @@ -196,25 +196,46 @@ export default function CarnetPage() { lines.forEach(line => { console.log('Processing line:', line); + // Handle FN (Formatted Name) if (line.startsWith('FN:')) { contact.fullName = line.substring(3).trim(); console.log('Found full name:', contact.fullName); - } else if (line.startsWith('EMAIL;')) { + } + // Handle N (Name components) + else if (line.startsWith('N:')) { + const nameParts = line.substring(2).split(';'); + if (nameParts.length >= 2) { + const lastName = nameParts[0]?.trim(); + const firstName = nameParts[1]?.trim(); + if (!contact.fullName) { + contact.fullName = `${firstName} ${lastName}`.trim(); + console.log('Constructed full name from N field:', contact.fullName); + } + } + } + // Handle EMAIL + else if (line.startsWith('EMAIL;')) { const email = line.split(':')[1]; if (email) { contact.email = email.trim(); console.log('Found email:', contact.email); } - } else if (line.startsWith('TEL;')) { + } + // Handle TEL + else if (line.startsWith('TEL;')) { const phone = line.split(':')[1]; if (phone) { contact.phone = phone.trim(); console.log('Found phone:', contact.phone); } - } else if (line.startsWith('ORG:')) { + } + // Handle ORG + else if (line.startsWith('ORG:')) { contact.organization = line.substring(4).trim(); console.log('Found organization:', contact.organization); - } else if (line.startsWith('ADR;')) { + } + // Handle ADR + else if (line.startsWith('ADR;')) { const addressParts = line.split(':')[1].split(';'); if (addressParts.length >= 7) { const street = addressParts[2]?.trim(); @@ -225,25 +246,14 @@ export default function CarnetPage() { contact.address = [street, city, state, zip, country].filter(Boolean).join(', '); console.log('Found address:', contact.address); } - } else if (line.startsWith('NOTE:')) { + } + // Handle NOTE + else if (line.startsWith('NOTE:')) { contact.notes = line.substring(5).trim(); console.log('Found notes:', contact.notes); } }); - if (!contact.fullName) { - const nLine = lines.find(line => line.startsWith('N:')); - if (nLine) { - const nameParts = nLine.substring(2).split(';'); - if (nameParts.length >= 2) { - const lastName = nameParts[0]?.trim(); - const firstName = nameParts[1]?.trim(); - contact.fullName = `${firstName} ${lastName}`.trim(); - console.log('Constructed full name from N field:', contact.fullName); - } - } - } - if (!contact.fullName) { contact.fullName = 'Unknown Contact'; console.log('No name found, using default');