Pages corrections
This commit is contained in:
parent
588707bd68
commit
e55bcb8b78
@ -236,22 +236,34 @@ export default function CarnetPage() {
|
|||||||
const response = await fetch(`/api/storage/files?folder=${folderLowercase}`);
|
const response = await fetch(`/api/storage/files?folder=${folderLowercase}`);
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
const files = await response.json();
|
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) =>
|
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
|
// Parse VCF files and extract contact information
|
||||||
const parsedContacts = await Promise.all(
|
const parsedContacts = await Promise.all(
|
||||||
vcfFiles.map(async (file: any) => {
|
vcfFiles.map(async (file: any) => {
|
||||||
try {
|
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) {
|
if (contentResponse.ok) {
|
||||||
const { content } = await contentResponse.json();
|
const { content } = await contentResponse.json();
|
||||||
const contacts = parseVCardContent(content);
|
const contacts = parseVCardContent(content);
|
||||||
|
console.log(`[fetchContacts] Parsed ${contacts.length} contacts from ${fileKey}`);
|
||||||
return contacts.map(contact => ({
|
return contacts.map(contact => ({
|
||||||
...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 [];
|
return [];
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -262,7 +274,12 @@ export default function CarnetPage() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Flatten the array of contact arrays
|
// 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) {
|
} catch (error) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user