From 0e20e7b4b4010865a63d5efbb0c00516f567ca08 Mon Sep 17 00:00:00 2001 From: alma Date: Fri, 16 Jan 2026 14:13:09 +0100 Subject: [PATCH] Pages corrections pages missions --- app/api/missions/[missionId]/files/route.ts | 45 ++++++++++++++------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/app/api/missions/[missionId]/files/route.ts b/app/api/missions/[missionId]/files/route.ts index c5838af..1314ca9 100644 --- a/app/api/missions/[missionId]/files/route.ts +++ b/app/api/missions/[missionId]/files/route.ts @@ -71,7 +71,11 @@ export async function GET( const path = searchParams.get('path') || ''; // Subfolder path within mission // Construct prefix for listing - const prefix = path ? `missions/${missionId}/${path}/` : `missions/${missionId}/`; + // Note: In MinIO, files are stored without the "missions/" prefix (it's removed during upload) + // So the prefix should be just "{missionId}/" or "{missionId}/{path}/" + const prefix = path ? `${missionId}/${path}/` : `${missionId}/`; + + console.log(`[GET /api/missions/${missionId}/files] Listing with prefix: ${prefix} in bucket: ${MISSIONS_S3_CONFIG.bucket}`); const command = new ListObjectsV2Command({ Bucket: MISSIONS_S3_CONFIG.bucket, @@ -84,14 +88,16 @@ export async function GET( // Extract folders (CommonPrefixes) const folders = (response.CommonPrefixes || []).map(commonPrefix => { const folderPath = commonPrefix.Prefix || ''; - // Extract folder name from path (e.g., "missions/123/docs/" -> "docs") + // Extract folder name from path (e.g., "123/docs/" -> "docs") const pathParts = folderPath.replace(prefix, '').split('/').filter(Boolean); const folderName = pathParts[pathParts.length - 1] || folderPath; + // Store full path with missions/ prefix for consistency + const fullPath = `missions/${folderPath}`; return { type: 'folder', name: folderName, - path: folderPath, - key: folderPath + path: fullPath, + key: fullPath }; }); @@ -105,14 +111,19 @@ export async function GET( if (obj.Key.includes('.placeholder')) return false; return true; }) - .map(obj => ({ - type: 'file', - name: obj.Key?.split('/').pop() || obj.Key, - path: obj.Key, - key: obj.Key, - size: obj.Size, - lastModified: obj.LastModified - })); + .map(obj => { + const key = obj.Key || ''; + // Store full path with missions/ prefix for consistency + const fullPath = `missions/${key}`; + return { + type: 'file', + name: key.split('/').pop() || key, + path: fullPath, + key: fullPath, + size: obj.Size, + lastModified: obj.LastModified + }; + }); return NextResponse.json({ folders, @@ -165,9 +176,12 @@ export async function POST( return NextResponse.json({ error: 'Invalid file path' }, { status: 400 }); } + // Remove missions/ prefix for MinIO (files are stored without it) + const minioKey = key.replace(/^missions\//, ''); + const command = new GetObjectCommand({ Bucket: MISSIONS_S3_CONFIG.bucket, - Key: key + Key: minioKey }); const response = await missionsS3Client.send(command); @@ -215,9 +229,12 @@ export async function PUT( return NextResponse.json({ error: 'Invalid file path' }, { status: 400 }); } + // Remove missions/ prefix for MinIO (files are stored without it) + const minioKey = key.replace(/^missions\//, ''); + const command = new PutObjectCommand({ Bucket: MISSIONS_S3_CONFIG.bucket, - Key: key, + Key: minioKey, Body: content || Buffer.alloc(0), ContentType: 'text/plain' });