carnet panel contact

This commit is contained in:
alma 2025-04-20 21:00:22 +02:00
parent 3fcabdde25
commit 143b8156a1

View File

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