carnet panel contact

This commit is contained in:
alma 2025-04-20 19:26:49 +02:00
parent 8489096328
commit b7f889e011
2 changed files with 29 additions and 18 deletions

View File

@ -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);

View File

@ -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');