diff --git a/app/api/nextcloud/files/route.ts b/app/api/nextcloud/files/route.ts index edc26a55..90eba367 100644 --- a/app/api/nextcloud/files/route.ts +++ b/app/api/nextcloud/files/route.ts @@ -137,7 +137,7 @@ export async function PUT(request: Request) { return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); } - const { id, title, content, folder } = await request.json(); + const { id, title, content, folder, mime } = await request.json(); if (!id || !title || !content || !folder) { return NextResponse.json({ error: 'Missing required fields' }, { status: 400 }); } @@ -145,12 +145,12 @@ 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}`; + // Use the provided path directly + const path = id; 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 file extension or provided mime type + const contentType = mime || (title.endsWith('.vcf') ? 'text/vcard' : 'text/markdown'); await client.putFileContents(path, content, { contentType }); // Get the updated file details