carnet panel contact
This commit is contained in:
parent
b36ac5d15a
commit
8489096328
@ -180,7 +180,10 @@ export default function CarnetPage() {
|
||||
|
||||
const parseVCard = (content: string): Contact | null => {
|
||||
try {
|
||||
console.log('Raw VCF content:', content);
|
||||
const lines = content.split('\n').filter(line => line.trim());
|
||||
console.log('Parsed lines:', lines);
|
||||
|
||||
const contact: Partial<Contact> = {
|
||||
id: Math.random().toString(36).substr(2, 9),
|
||||
fullName: '',
|
||||
@ -192,16 +195,25 @@ export default function CarnetPage() {
|
||||
};
|
||||
|
||||
lines.forEach(line => {
|
||||
console.log('Processing line:', line);
|
||||
if (line.startsWith('FN:')) {
|
||||
contact.fullName = line.substring(3).trim();
|
||||
console.log('Found full name:', contact.fullName);
|
||||
} else if (line.startsWith('EMAIL;')) {
|
||||
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;')) {
|
||||
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:')) {
|
||||
contact.organization = line.substring(4).trim();
|
||||
console.log('Found organization:', contact.organization);
|
||||
} else if (line.startsWith('ADR;')) {
|
||||
const addressParts = line.split(':')[1].split(';');
|
||||
if (addressParts.length >= 7) {
|
||||
@ -211,9 +223,11 @@ export default function CarnetPage() {
|
||||
const zip = addressParts[5]?.trim();
|
||||
const country = addressParts[6]?.trim();
|
||||
contact.address = [street, city, state, zip, country].filter(Boolean).join(', ');
|
||||
console.log('Found address:', contact.address);
|
||||
}
|
||||
} else if (line.startsWith('NOTE:')) {
|
||||
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 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');
|
||||
}
|
||||
|
||||
console.log('Final contact object:', contact);
|
||||
return contact as Contact;
|
||||
} catch (error) {
|
||||
console.error('Error parsing VCF content:', error);
|
||||
@ -252,7 +269,9 @@ export default function CarnetPage() {
|
||||
const parsedContacts = await Promise.all(
|
||||
vcfFiles.map(async (file: any) => {
|
||||
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) {
|
||||
const content = await contentResponse.text();
|
||||
const contact = parseVCard(content);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user