Pages corrections

This commit is contained in:
alma 2026-01-16 12:05:23 +01:00
parent 588707bd68
commit e55bcb8b78

View File

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