carnet panel contact

This commit is contained in:
alma 2025-04-20 19:18:53 +02:00
parent ffa842d140
commit f9ebf00e32
2 changed files with 20 additions and 10 deletions

View File

@ -49,19 +49,22 @@ export async function GET(request: Request) {
const { searchParams } = new URL(request.url); const { searchParams } = new URL(request.url);
const id = searchParams.get('id'); const id = searchParams.get('id');
const path = searchParams.get('path');
if (!id) { if (!id && !path) {
return NextResponse.json({ error: 'Note ID is required' }, { status: 400 }); return NextResponse.json({ error: 'File ID or path is required' }, { status: 400 });
} }
const { client } = await createWebDAVClient(session.user.id); const { client } = await createWebDAVClient(session.user.id);
try { 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 }); return NextResponse.json({ content });
} catch (error) { } catch (error) {
console.error('Error fetching note content:', error); console.error('Error fetching file content:', error);
return NextResponse.json({ error: 'Failed to fetch note content' }, { status: 500 }); return NextResponse.json({ error: 'Failed to fetch file content' }, { status: 500 });
} }
} catch (error) { } catch (error) {
console.error('Error in GET request:', error); console.error('Error in GET request:', error);

View File

@ -189,12 +189,19 @@ export default function CarnetPage() {
// 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) => {
const contentResponse = await fetch(`/api/nextcloud/files/content?id=${file.id}`); try {
if (contentResponse.ok) { // Use the full filename for fetching content
const content = await contentResponse.text(); const contentResponse = await fetch(`/api/nextcloud/files/content?path=${encodeURIComponent(file.filename)}`);
return parseVCard(content); 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;
}) })
); );