This commit is contained in:
alma 2025-05-04 13:54:23 +02:00
parent e5a2e63994
commit dab73b433c
5 changed files with 58 additions and 113 deletions

View File

@ -13,29 +13,14 @@ export async function GET(request: Request) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
} }
// Get query parameters // Forward to storage handler
const { searchParams } = new URL(request.url); try {
const path = searchParams.get('path'); const { GET: storageContentHandler } = await import('@/app/api/storage/files/content/route');
const id = searchParams.get('id'); return await storageContentHandler(request);
} catch (error) {
// Create a new URL for the storage API with the same parameters console.error('Error calling storage content handler:', error);
const newUrl = new URL('/api/storage/files/content', request.url); return NextResponse.json({ error: 'Failed to get file content' }, { status: 500 });
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) { } catch (error) {
console.error('Error in NextCloud content adapter:', error); console.error('Error in NextCloud content adapter:', error);
return NextResponse.json({ error: 'Internal server error' }, { status: 500 }); return NextResponse.json({ error: 'Internal server error' }, { status: 500 });

View File

@ -13,25 +13,14 @@ export async function GET(request: Request) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
} }
// Get query parameters // Get query parameters - we'll pass the same request to the storage handler
const { searchParams } = new URL(request.url); try {
const folder = searchParams.get('folder'); const { GET: storageFilesHandler } = await import('@/app/api/storage/files/route');
return await storageFilesHandler(request);
// Create a new URL for the storage API with the same parameters } catch (error) {
const newUrl = new URL('/api/storage/files', request.url); console.error('Error calling storage files handler:', error);
if (folder) { return NextResponse.json({ error: 'Failed to list files' }, { status: 500 });
newUrl.searchParams.set('folder', folder);
} }
// 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) { } catch (error) {
console.error('Error in NextCloud adapter (GET):', error); console.error('Error in NextCloud adapter (GET):', error);
return NextResponse.json({ error: 'Internal server error' }, { status: 500 }); return NextResponse.json({ error: 'Internal server error' }, { status: 500 });
@ -46,21 +35,14 @@ export async function POST(request: Request) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
} }
// Get request body // Forward to storage handler
const body = await request.json(); try {
const { POST: storageFilesHandler } = await import('@/app/api/storage/files/route');
// Forward the request to the new endpoint return await storageFilesHandler(request);
const response = await fetch('/api/storage/files', { } catch (error) {
method: 'POST', console.error('Error calling storage files handler:', error);
headers: { return NextResponse.json({ error: 'Failed to create file' }, { status: 500 });
'Content-Type': 'application/json', }
'Cookie': request.headers.get('cookie') || ''
},
body: JSON.stringify(body)
});
// Return the response from the new endpoint
return NextResponse.json(await response.json(), { status: response.status });
} catch (error) { } catch (error) {
console.error('Error in NextCloud adapter (POST):', error); console.error('Error in NextCloud adapter (POST):', error);
return NextResponse.json({ error: 'Internal server error' }, { status: 500 }); return NextResponse.json({ error: 'Internal server error' }, { status: 500 });
@ -75,21 +57,14 @@ export async function PUT(request: Request) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
} }
// Get request body // Forward to storage handler
const body = await request.json(); try {
const { PUT: storageFilesHandler } = await import('@/app/api/storage/files/route');
// Forward the request to the new endpoint return await storageFilesHandler(request);
const response = await fetch('/api/storage/files', { } catch (error) {
method: 'PUT', console.error('Error calling storage files handler:', error);
headers: { return NextResponse.json({ error: 'Failed to update file' }, { status: 500 });
'Content-Type': 'application/json', }
'Cookie': request.headers.get('cookie') || ''
},
body: JSON.stringify(body)
});
// Return the response from the new endpoint
return NextResponse.json(await response.json(), { status: response.status });
} catch (error) { } catch (error) {
console.error('Error in NextCloud adapter (PUT):', error); console.error('Error in NextCloud adapter (PUT):', error);
return NextResponse.json({ error: 'Internal server error' }, { status: 500 }); return NextResponse.json({ error: 'Internal server error' }, { status: 500 });
@ -104,26 +79,14 @@ export async function DELETE(request: Request) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
} }
// Get query parameters // Forward to storage handler
const { searchParams } = new URL(request.url); try {
const id = searchParams.get('id'); const { DELETE: storageFilesHandler } = await import('@/app/api/storage/files/route');
return await storageFilesHandler(request);
// Create a new URL for the storage API with the same parameters } catch (error) {
const newUrl = new URL('/api/storage/files', request.url); console.error('Error calling storage files handler:', error);
if (id) { return NextResponse.json({ error: 'Failed to delete file' }, { status: 500 });
newUrl.searchParams.set('id', id);
} }
// Forward the request to the new endpoint
const response = await fetch(newUrl, {
method: 'DELETE',
headers: {
'Cookie': request.headers.get('cookie') || ''
}
});
// Return the response from the new endpoint
return NextResponse.json(await response.json(), { status: response.status });
} catch (error) { } catch (error) {
console.error('Error in NextCloud adapter (DELETE):', error); console.error('Error in NextCloud adapter (DELETE):', error);
return NextResponse.json({ error: 'Internal server error' }, { status: 500 }); return NextResponse.json({ error: 'Internal server error' }, { status: 500 });

View File

@ -13,16 +13,14 @@ export async function POST(request: Request) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
} }
// Forward the request to the new endpoint // Forward to storage handler
const response = await fetch('/api/storage/init', { try {
method: 'POST', const { POST: storageInitHandler } = await import('@/app/api/storage/init/route');
headers: { return await storageInitHandler();
'Cookie': request.headers.get('cookie') || '' } catch (error) {
} console.error('Error calling storage init handler:', error);
}); return NextResponse.json({ error: 'Failed to initialize storage' }, { status: 500 });
}
// Return the response from the new endpoint
return NextResponse.json(await response.json(), { status: response.status });
} catch (error) { } catch (error) {
console.error('Error in NextCloud init adapter:', error); console.error('Error in NextCloud init adapter:', error);
return NextResponse.json({ error: 'Internal server error' }, { status: 500 }); return NextResponse.json({ error: 'Internal server error' }, { status: 500 });

View File

@ -13,19 +13,18 @@ export async function GET(request: Request) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
} }
// Get the base URL from the request // Instead of making an HTTP request, directly call the handler function
const { protocol, host } = new URL(request.url); // for the storage status endpoint
const baseUrl = `${protocol}//${host}`; try {
const { GET: storageStatusHandler } = await import('@/app/api/storage/status/route');
const storageResponse = await storageStatusHandler();
// Forward the request to the new endpoint // Return the response
const response = await fetch(`${baseUrl}/api/storage/status`, { return storageResponse;
headers: { } catch (error) {
'Cookie': request.headers.get('cookie') || '' console.error('Error calling storage status handler:', error);
} return NextResponse.json({ error: 'Failed to get storage status' }, { status: 500 });
}); }
// Return the response from the new endpoint
return NextResponse.json(await response.json(), { status: response.status });
} catch (error) { } catch (error) {
console.error('Error in NextCloud status adapter:', error); console.error('Error in NextCloud status adapter:', error);
return NextResponse.json({ error: 'Internal server error' }, { status: 500 }); return NextResponse.json({ error: 'Internal server error' }, { status: 500 });

View File

@ -3,7 +3,7 @@ import { getServerSession } from 'next-auth';
import { authOptions } from '@/app/api/auth/[...nextauth]/route'; import { authOptions } from '@/app/api/auth/[...nextauth]/route';
import { createUserFolderStructure } from '@/lib/s3'; import { createUserFolderStructure } from '@/lib/s3';
export async function POST() { export async function POST(request: Request) {
try { try {
const session = await getServerSession(authOptions); const session = await getServerSession(authOptions);
if (!session?.user?.id) { if (!session?.user?.id) {