From e55bcb8b78b1425894ba16d0e29af0d6509645ee Mon Sep 17 00:00:00 2001 From: alma Date: Fri, 16 Jan 2026 12:05:23 +0100 Subject: [PATCH] Pages corrections --- app/pages/page.tsx | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/app/pages/page.tsx b/app/pages/page.tsx index 16f38fa..1273dcc 100644 --- a/app/pages/page.tsx +++ b/app/pages/page.tsx @@ -236,22 +236,34 @@ export default function CarnetPage() { const response = await fetch(`/api/storage/files?folder=${folderLowercase}`); if (response.ok) { const files = await response.json(); + console.log(`[fetchContacts] Found ${files.length} files in contacts folder`, files); + + // Filter VCF files - API returns { key, name, size, lastModified } const vcfFiles = files.filter((file: any) => - file.basename?.endsWith('.vcf') || file.title?.endsWith('.vcf') + file.name?.endsWith('.vcf') || file.key?.endsWith('.vcf') ); + console.log(`[fetchContacts] Found ${vcfFiles.length} VCF files`, vcfFiles); + // Parse VCF files and extract contact information const parsedContacts = await Promise.all( vcfFiles.map(async (file: any) => { try { - const contentResponse = await fetch(`/api/storage/files/content?path=${encodeURIComponent(file.id)}`); + // Use file.key (S3 key) or file.id as the path + const fileKey = file.key || file.id; + console.log(`[fetchContacts] Fetching content for VCF file: ${fileKey}`); + + const contentResponse = await fetch(`/api/storage/files/content?path=${encodeURIComponent(fileKey)}`); if (contentResponse.ok) { const { content } = await contentResponse.json(); const contacts = parseVCardContent(content); + console.log(`[fetchContacts] Parsed ${contacts.length} contacts from ${fileKey}`); return contacts.map(contact => ({ ...contact, - group: (file.basename || file.title)?.replace('.vcf', '') + group: (file.name || file.key?.split('/').pop() || 'contacts')?.replace('.vcf', '') })); + } else { + console.error(`[fetchContacts] Failed to fetch content for ${fileKey}:`, contentResponse.status); } return []; } catch (error) { @@ -262,7 +274,12 @@ export default function CarnetPage() { ); // Flatten the array of contact arrays - setContacts(parsedContacts.flat().filter(Boolean)); + const allContacts = parsedContacts.flat().filter(Boolean); + console.log(`[fetchContacts] Total contacts parsed: ${allContacts.length}`); + setContacts(allContacts); + } else { + console.error(`[fetchContacts] Failed to fetch files:`, response.status); + setContacts([]); } } } catch (error) {