carnet panel contact
This commit is contained in:
parent
ffa842d140
commit
f9ebf00e32
@ -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);
|
||||
|
||||
@ -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;
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user