From 143b8156a158294ec72794be8acf5e1ffbfddbc0 Mon Sep 17 00:00:00 2001 From: alma Date: Sun, 20 Apr 2025 21:00:22 +0200 Subject: [PATCH] carnet panel contact --- app/api/nextcloud/files/route.ts | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/app/api/nextcloud/files/route.ts b/app/api/nextcloud/files/route.ts index edc26a55..9fb6d958 100644 --- a/app/api/nextcloud/files/route.ts +++ b/app/api/nextcloud/files/route.ts @@ -59,9 +59,20 @@ export async function GET(request: Request) { const files = await client.getDirectoryContents(path); console.log('Raw files response:', JSON.stringify(files, null, 2)); - // Return all files for the Contacts folder + // For Contacts folder, only return VCF files if (folder === 'Contacts') { - return NextResponse.json(files); + const vcfFiles = files + .filter((file: any) => file.basename.endsWith('.vcf') && !file.basename.endsWith('.vcf.md')) + .map((file: any) => ({ + id: file.filename, + title: file.basename, + lastModified: new Date(file.lastmod).toISOString(), + size: file.size, + type: 'file', + mime: file.mime, + etag: file.etag + })); + return NextResponse.json(vcfFiles); } // For other folders, filter markdown files @@ -145,12 +156,13 @@ export async function PUT(request: Request) { const { client, username } = await createWebDAVClient(session.user.id); try { - // Use the title as is, since it should already include the extension - const path = `/files/${username}/Private/${folder}/${title}`; + // For Contacts folder, ensure we're using .vcf extension + const fileExtension = folder === 'Contacts' ? '.vcf' : '.md'; + const path = `/files/${username}/Private/${folder}/${title}${fileExtension}`; console.log('Updating file at path:', path); - // Set the correct content type based on file extension - const contentType = title.endsWith('.vcf') ? 'text/vcard' : 'text/markdown'; + // Set the correct content type based on folder + const contentType = folder === 'Contacts' ? 'text/vcard' : 'text/markdown'; await client.putFileContents(path, content, { contentType }); // Get the updated file details