Pages corrections
This commit is contained in:
parent
722873fdac
commit
0d769ffb64
@ -183,14 +183,46 @@ export default function CarnetPage() {
|
||||
try {
|
||||
console.log(`[parseVCardContent] Parsing VCF content, length: ${content.length}`);
|
||||
|
||||
// Split the content into individual vCards
|
||||
// Handle both formats: BEGIN:VCARD\n... and BEGIN:VCARD\r\n...
|
||||
const vcards = content.split(/BEGIN:VCARD/i).filter(section => section.trim());
|
||||
console.log(`[parseVCardContent] Found ${vcards.length} vCard sections`);
|
||||
// Normalize line endings and split vCards
|
||||
// Replace \r\n with \n, then split by BEGIN:VCARD
|
||||
const normalizedContent = content.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
||||
|
||||
const parsed = vcards.map((section, index) => {
|
||||
// Split the content into individual vCards
|
||||
// Handle formats like: BEGIN:VCARD\n... or BEGIN:VCARDVERSION:3.0...
|
||||
const vcardSections = normalizedContent.split(/BEGIN:VCARD/i).filter(section => section.trim());
|
||||
console.log(`[parseVCardContent] Found ${vcardSections.length} vCard sections`);
|
||||
|
||||
const parsed = vcardSections.map((section, index) => {
|
||||
try {
|
||||
const vcardContent = 'BEGIN:VCARD' + section;
|
||||
// Reconstruct vCard content with proper formatting
|
||||
let vcardContent = 'BEGIN:VCARD\n';
|
||||
|
||||
// Clean up the section and ensure proper line breaks
|
||||
let cleanedSection = section.trim();
|
||||
|
||||
// Fix format where BEGIN:VCARD is directly followed by VERSION (no newline)
|
||||
cleanedSection = cleanedSection.replace(/^VERSION:/, 'VERSION:');
|
||||
|
||||
// Ensure each field is on its own line
|
||||
cleanedSection = cleanedSection
|
||||
.replace(/([^\n])(VERSION:)/g, '$1\n$2')
|
||||
.replace(/([^\n])(UID:)/g, '$1\n$2')
|
||||
.replace(/([^\n])(FN:)/g, '$1\n$2')
|
||||
.replace(/([^\n])(EMAIL)/g, '$1\n$2')
|
||||
.replace(/([^\n])(TEL)/g, '$1\n$2')
|
||||
.replace(/([^\n])(ORG:)/g, '$1\n$2')
|
||||
.replace(/([^\n])(NOTE:)/g, '$1\n$2')
|
||||
.replace(/([^\n])(END:VCARD)/g, '$1\n$2');
|
||||
|
||||
vcardContent += cleanedSection;
|
||||
|
||||
// Ensure it ends with END:VCARD
|
||||
if (!vcardContent.trim().endsWith('END:VCARD')) {
|
||||
vcardContent += '\nEND:VCARD';
|
||||
}
|
||||
|
||||
console.log(`[parseVCardContent] Processing vCard ${index + 1}, content preview:`, vcardContent.substring(0, 300));
|
||||
|
||||
const vcard = parseVCard(vcardContent);
|
||||
|
||||
// Extract contact properties with proper type handling
|
||||
|
||||
Loading…
Reference in New Issue
Block a user