carnet panel contact

This commit is contained in:
alma 2025-04-20 19:24:29 +02:00
parent b36ac5d15a
commit 8489096328

View File

@ -180,7 +180,10 @@ export default function CarnetPage() {
const parseVCard = (content: string): Contact | null => { const parseVCard = (content: string): Contact | null => {
try { try {
console.log('Raw VCF content:', content);
const lines = content.split('\n').filter(line => line.trim()); const lines = content.split('\n').filter(line => line.trim());
console.log('Parsed lines:', lines);
const contact: Partial<Contact> = { const contact: Partial<Contact> = {
id: Math.random().toString(36).substr(2, 9), id: Math.random().toString(36).substr(2, 9),
fullName: '', fullName: '',
@ -192,16 +195,25 @@ export default function CarnetPage() {
}; };
lines.forEach(line => { lines.forEach(line => {
console.log('Processing line:', line);
if (line.startsWith('FN:')) { if (line.startsWith('FN:')) {
contact.fullName = line.substring(3).trim(); contact.fullName = line.substring(3).trim();
console.log('Found full name:', contact.fullName);
} else if (line.startsWith('EMAIL;')) { } else if (line.startsWith('EMAIL;')) {
const email = line.split(':')[1]; const email = line.split(':')[1];
if (email) contact.email = email.trim(); if (email) {
contact.email = email.trim();
console.log('Found email:', contact.email);
}
} else if (line.startsWith('TEL;')) { } else if (line.startsWith('TEL;')) {
const phone = line.split(':')[1]; const phone = line.split(':')[1];
if (phone) contact.phone = phone.trim(); if (phone) {
contact.phone = phone.trim();
console.log('Found phone:', contact.phone);
}
} else if (line.startsWith('ORG:')) { } else if (line.startsWith('ORG:')) {
contact.organization = line.substring(4).trim(); contact.organization = line.substring(4).trim();
console.log('Found organization:', contact.organization);
} else if (line.startsWith('ADR;')) { } else if (line.startsWith('ADR;')) {
const addressParts = line.split(':')[1].split(';'); const addressParts = line.split(':')[1].split(';');
if (addressParts.length >= 7) { if (addressParts.length >= 7) {
@ -211,9 +223,11 @@ export default function CarnetPage() {
const zip = addressParts[5]?.trim(); const zip = addressParts[5]?.trim();
const country = addressParts[6]?.trim(); const country = addressParts[6]?.trim();
contact.address = [street, city, state, zip, country].filter(Boolean).join(', '); contact.address = [street, city, state, zip, country].filter(Boolean).join(', ');
console.log('Found address:', contact.address);
} }
} else if (line.startsWith('NOTE:')) { } else if (line.startsWith('NOTE:')) {
contact.notes = line.substring(5).trim(); contact.notes = line.substring(5).trim();
console.log('Found notes:', contact.notes);
} }
}); });
@ -225,14 +239,17 @@ export default function CarnetPage() {
const lastName = nameParts[0]?.trim(); const lastName = nameParts[0]?.trim();
const firstName = nameParts[1]?.trim(); const firstName = nameParts[1]?.trim();
contact.fullName = `${firstName} ${lastName}`.trim(); contact.fullName = `${firstName} ${lastName}`.trim();
console.log('Constructed full name from N field:', contact.fullName);
} }
} }
} }
if (!contact.fullName) { if (!contact.fullName) {
contact.fullName = 'Unknown Contact'; contact.fullName = 'Unknown Contact';
console.log('No name found, using default');
} }
console.log('Final contact object:', contact);
return contact as Contact; return contact as Contact;
} catch (error) { } catch (error) {
console.error('Error parsing VCF content:', error); console.error('Error parsing VCF content:', error);
@ -252,7 +269,9 @@ export default function CarnetPage() {
const parsedContacts = await Promise.all( const parsedContacts = await Promise.all(
vcfFiles.map(async (file: any) => { vcfFiles.map(async (file: any) => {
try { try {
const contentResponse = await fetch(`/api/nextcloud/files/content?path=${encodeURIComponent(file.filename)}`); // Construct the full WebDAV path
const webdavPath = `/files/${file.filename}`;
const contentResponse = await fetch(`/api/nextcloud/files/content?path=${encodeURIComponent(webdavPath)}`);
if (contentResponse.ok) { if (contentResponse.ok) {
const content = await contentResponse.text(); const content = await contentResponse.text();
const contact = parseVCard(content); const contact = parseVCard(content);