From f9ebf00e32966fbb1ea73d9555b0c98a10b1f9a8 Mon Sep 17 00:00:00 2001 From: alma Date: Sun, 20 Apr 2025 19:18:53 +0200 Subject: [PATCH] carnet panel contact --- app/api/nextcloud/files/content/route.ts | 13 ++++++++----- app/carnet/page.tsx | 17 ++++++++++++----- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/app/api/nextcloud/files/content/route.ts b/app/api/nextcloud/files/content/route.ts index c107a756..d80b7566 100644 --- a/app/api/nextcloud/files/content/route.ts +++ b/app/api/nextcloud/files/content/route.ts @@ -49,19 +49,22 @@ export async function GET(request: Request) { const { searchParams } = new URL(request.url); const id = searchParams.get('id'); + const path = searchParams.get('path'); - if (!id) { - return NextResponse.json({ error: 'Note ID is required' }, { status: 400 }); + if (!id && !path) { + return NextResponse.json({ error: 'File ID or path is required' }, { status: 400 }); } const { client } = await createWebDAVClient(session.user.id); try { - const content = await client.getFileContents(id, { format: 'text' }); + // Use either id or path to fetch the file content + const filePath = id || path; + const content = await client.getFileContents(filePath, { format: 'text' }); return NextResponse.json({ content }); } catch (error) { - console.error('Error fetching note content:', error); - return NextResponse.json({ error: 'Failed to fetch note content' }, { status: 500 }); + console.error('Error fetching file content:', error); + return NextResponse.json({ error: 'Failed to fetch file content' }, { status: 500 }); } } catch (error) { console.error('Error in GET request:', error); diff --git a/app/carnet/page.tsx b/app/carnet/page.tsx index a3e8f66c..04a14a5d 100644 --- a/app/carnet/page.tsx +++ b/app/carnet/page.tsx @@ -189,12 +189,19 @@ export default function CarnetPage() { // Parse VCF files and extract contact information const parsedContacts = await Promise.all( vcfFiles.map(async (file: any) => { - const contentResponse = await fetch(`/api/nextcloud/files/content?id=${file.id}`); - if (contentResponse.ok) { - const content = await contentResponse.text(); - return parseVCard(content); + try { + // Use the full filename for fetching content + const contentResponse = await fetch(`/api/nextcloud/files/content?path=${encodeURIComponent(file.filename)}`); + if (contentResponse.ok) { + const content = await contentResponse.text(); + return parseVCard(content); + } + console.error('Failed to fetch VCF content:', contentResponse.status); + return null; + } catch (error) { + console.error('Error fetching VCF content:', error); + return null; } - return null; }) );