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 });
}
// 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);
// Forward to storage handler
try {
const { GET: storageContentHandler } = await import('@/app/api/storage/files/content/route');
return await storageContentHandler(request);
} catch (error) {
console.error('Error calling storage content handler:', error);
return NextResponse.json({ error: 'Failed to get file content' }, { status: 500 });
}
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 });

View File

@ -13,25 +13,14 @@ export async function GET(request: Request) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
// Get query parameters
const { searchParams } = new URL(request.url);
const folder = searchParams.get('folder');
// Create a new URL for the storage API with the same parameters
const newUrl = new URL('/api/storage/files', request.url);
if (folder) {
newUrl.searchParams.set('folder', folder);
// Get query parameters - we'll pass the same request to the storage handler
try {
const { GET: storageFilesHandler } = await import('@/app/api/storage/files/route');
return await storageFilesHandler(request);
} catch (error) {
console.error('Error calling storage files handler:', error);
return NextResponse.json({ error: 'Failed to list files' }, { status: 500 });
}
// 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 adapter (GET):', error);
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 });
}
// Get request body
const body = await request.json();
// Forward the request to the new endpoint
const response = await fetch('/api/storage/files', {
method: 'POST',
headers: {
'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 });
// Forward to storage handler
try {
const { POST: storageFilesHandler } = await import('@/app/api/storage/files/route');
return await storageFilesHandler(request);
} catch (error) {
console.error('Error calling storage files handler:', error);
return NextResponse.json({ error: 'Failed to create file' }, { status: 500 });
}
} catch (error) {
console.error('Error in NextCloud adapter (POST):', error);
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 });
}
// Get request body
const body = await request.json();
// Forward the request to the new endpoint
const response = await fetch('/api/storage/files', {
method: 'PUT',
headers: {
'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 });
// Forward to storage handler
try {
const { PUT: storageFilesHandler } = await import('@/app/api/storage/files/route');
return await storageFilesHandler(request);
} catch (error) {
console.error('Error calling storage files handler:', error);
return NextResponse.json({ error: 'Failed to update file' }, { status: 500 });
}
} catch (error) {
console.error('Error in NextCloud adapter (PUT):', error);
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 });
}
// Get query parameters
const { searchParams } = new URL(request.url);
const id = searchParams.get('id');
// Create a new URL for the storage API with the same parameters
const newUrl = new URL('/api/storage/files', request.url);
if (id) {
newUrl.searchParams.set('id', id);
// Forward to storage handler
try {
const { DELETE: storageFilesHandler } = await import('@/app/api/storage/files/route');
return await storageFilesHandler(request);
} catch (error) {
console.error('Error calling storage files handler:', error);
return NextResponse.json({ error: 'Failed to delete file' }, { status: 500 });
}
// 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) {
console.error('Error in NextCloud adapter (DELETE):', error);
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 });
}
// Forward the request to the new endpoint
const response = await fetch('/api/storage/init', {
method: 'POST',
headers: {
'Cookie': request.headers.get('cookie') || ''
}
});
// Return the response from the new endpoint
return NextResponse.json(await response.json(), { status: response.status });
// Forward to storage handler
try {
const { POST: storageInitHandler } = await import('@/app/api/storage/init/route');
return await storageInitHandler();
} catch (error) {
console.error('Error calling storage init handler:', error);
return NextResponse.json({ error: 'Failed to initialize storage' }, { status: 500 });
}
} catch (error) {
console.error('Error in NextCloud init adapter:', error);
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 });
}
// Get the base URL from the request
const { protocol, host } = new URL(request.url);
const baseUrl = `${protocol}//${host}`;
// Forward the request to the new endpoint
const response = await fetch(`${baseUrl}/api/storage/status`, {
headers: {
'Cookie': request.headers.get('cookie') || ''
}
});
// Return the response from the new endpoint
return NextResponse.json(await response.json(), { status: response.status });
// Instead of making an HTTP request, directly call the handler function
// for the storage status endpoint
try {
const { GET: storageStatusHandler } = await import('@/app/api/storage/status/route');
const storageResponse = await storageStatusHandler();
// Return the response
return storageResponse;
} catch (error) {
console.error('Error calling storage status handler:', error);
return NextResponse.json({ error: 'Failed to get storage status' }, { status: 500 });
}
} catch (error) {
console.error('Error in NextCloud status adapter:', error);
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 { createUserFolderStructure } from '@/lib/s3';
export async function POST() {
export async function POST(request: Request) {
try {
const session = await getServerSession(authOptions);
if (!session?.user?.id) {