Pages corrections
This commit is contained in:
parent
70730709db
commit
722873fdac
@ -195,24 +195,55 @@ export default function CarnetPage() {
|
||||
|
||||
// Extract contact properties with proper type handling
|
||||
const uid = vcard.uid?.[0]?.value;
|
||||
const fullName = vcard.fn?.[0]?.value;
|
||||
const email = vcard.email?.[0]?.value;
|
||||
const phone = vcard.tel?.[0]?.value;
|
||||
const organization = vcard.org?.[0]?.value;
|
||||
const address = vcard.adr?.[0]?.value;
|
||||
const notes = vcard.note?.[0]?.value;
|
||||
const group = vcard.categories?.[0]?.value;
|
||||
let fullName = vcard.fn?.[0]?.value;
|
||||
|
||||
console.log(`[parseVCardContent] Parsed contact ${index + 1}:`, { uid, fullName, email, phone });
|
||||
// If FN is not available, try to construct name from N field (Family;Given;Additional;Prefix;Suffix)
|
||||
if (!fullName && vcard.n?.[0]?.value) {
|
||||
const nameParts = vcard.n[0].value.split(';').filter(Boolean);
|
||||
// N format: Family;Given;Additional;Prefix;Suffix
|
||||
// Construct: Given Family or Family Given
|
||||
if (nameParts.length >= 2) {
|
||||
fullName = `${nameParts[1]} ${nameParts[0]}`.trim() || nameParts[0] || nameParts[1];
|
||||
} else if (nameParts.length === 1) {
|
||||
fullName = nameParts[0];
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: try to extract from raw content if parser didn't work
|
||||
if (!fullName) {
|
||||
const fnMatch = section.match(/FN[;:]?([^\r\n]+)/i);
|
||||
if (fnMatch) {
|
||||
fullName = fnMatch[1].trim();
|
||||
} else {
|
||||
const nMatch = section.match(/N[;:]?([^\r\n]+)/i);
|
||||
if (nMatch) {
|
||||
const nameParts = nMatch[1].split(';').filter(Boolean);
|
||||
if (nameParts.length >= 2) {
|
||||
fullName = `${nameParts[1]} ${nameParts[0]}`.trim() || nameParts[0] || nameParts[1];
|
||||
} else if (nameParts.length === 1) {
|
||||
fullName = nameParts[0].trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const email = vcard.email?.[0]?.value || vcard.email?.[0];
|
||||
const phone = vcard.tel?.[0]?.value || vcard.tel?.[0];
|
||||
const organization = vcard.org?.[0]?.value || vcard.org?.[0];
|
||||
const address = vcard.adr?.[0]?.value || (vcard.adr?.[0] ? JSON.stringify(vcard.adr[0]) : '');
|
||||
const notes = vcard.note?.[0]?.value || vcard.note?.[0];
|
||||
const group = vcard.categories?.[0]?.value || vcard.categories?.[0];
|
||||
|
||||
console.log(`[parseVCardContent] Parsed contact ${index + 1}:`, { uid, fullName, email, phone, rawVCard: vcard });
|
||||
|
||||
// Create a clean contact object
|
||||
const contact: Contact = {
|
||||
id: uid || Math.random().toString(36).substr(2, 9),
|
||||
fullName: fullName || 'Unknown Contact',
|
||||
fullName: fullName || email || 'Sans nom',
|
||||
email: email || '',
|
||||
phone: phone || '',
|
||||
organization: organization || '',
|
||||
address: address || '',
|
||||
address: typeof address === 'string' ? address : '',
|
||||
notes: notes || '',
|
||||
group: group || ''
|
||||
};
|
||||
@ -279,8 +310,9 @@ export default function CarnetPage() {
|
||||
const contentResponse = await fetch(`/api/storage/files/content?path=${encodeURIComponent(fileKey)}`);
|
||||
if (contentResponse.ok) {
|
||||
const { content } = await contentResponse.json();
|
||||
console.log(`[fetchContacts] VCF content preview (first 500 chars):`, content.substring(0, 500));
|
||||
const contacts = parseVCardContent(content);
|
||||
console.log(`[fetchContacts] Parsed ${contacts.length} contacts from ${fileKey}`);
|
||||
console.log(`[fetchContacts] Parsed ${contacts.length} contacts from ${fileKey}`, contacts);
|
||||
return contacts.map(contact => ({
|
||||
...contact,
|
||||
group: (file.name || file.key?.split('/').pop() || 'contacts')?.replace('.vcf', '')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user