import { NextResponse } from 'next/server'; import { getServerSession } from 'next-auth'; import { authOptions } from '@/app/api/auth/[...nextauth]/route'; // This file serves as an adapter to redirect requests from the old NextCloud // content endpoint to the new MinIO S3 content endpoint export async function GET(request: Request) { try { // Get session const session = await getServerSession(authOptions); if (!session?.user) { return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); } // Get query parameters const { searchParams } = new URL(request.url); const path = searchParams.get('path'); const id = searchParams.get('id'); // Create a new URL for the storage API with the same parameters const newUrl = new URL('/api/storage/files/content', request.url); if (path) { newUrl.searchParams.set('path', path); } if (id) { newUrl.searchParams.set('id', id); } // Forward the request to the new endpoint const response = await fetch(newUrl, { headers: { 'Cookie': request.headers.get('cookie') || '' } }); // Return the response from the new endpoint return NextResponse.json(await response.json(), { status: response.status }); } catch (error) { console.error('Error in NextCloud content adapter:', error); return NextResponse.json({ error: 'Internal server error' }, { status: 500 }); } }