Pages corrections pages missions

This commit is contained in:
alma 2026-01-16 14:13:09 +01:00
parent 2913a4c560
commit 0e20e7b4b4

View File

@ -71,7 +71,11 @@ export async function GET(
const path = searchParams.get('path') || ''; // Subfolder path within mission const path = searchParams.get('path') || ''; // Subfolder path within mission
// Construct prefix for listing // 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({ const command = new ListObjectsV2Command({
Bucket: MISSIONS_S3_CONFIG.bucket, Bucket: MISSIONS_S3_CONFIG.bucket,
@ -84,14 +88,16 @@ export async function GET(
// Extract folders (CommonPrefixes) // Extract folders (CommonPrefixes)
const folders = (response.CommonPrefixes || []).map(commonPrefix => { const folders = (response.CommonPrefixes || []).map(commonPrefix => {
const folderPath = commonPrefix.Prefix || ''; 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 pathParts = folderPath.replace(prefix, '').split('/').filter(Boolean);
const folderName = pathParts[pathParts.length - 1] || folderPath; const folderName = pathParts[pathParts.length - 1] || folderPath;
// Store full path with missions/ prefix for consistency
const fullPath = `missions/${folderPath}`;
return { return {
type: 'folder', type: 'folder',
name: folderName, name: folderName,
path: folderPath, path: fullPath,
key: folderPath key: fullPath
}; };
}); });
@ -105,14 +111,19 @@ export async function GET(
if (obj.Key.includes('.placeholder')) return false; if (obj.Key.includes('.placeholder')) return false;
return true; return true;
}) })
.map(obj => ({ .map(obj => {
type: 'file', const key = obj.Key || '';
name: obj.Key?.split('/').pop() || obj.Key, // Store full path with missions/ prefix for consistency
path: obj.Key, const fullPath = `missions/${key}`;
key: obj.Key, return {
size: obj.Size, type: 'file',
lastModified: obj.LastModified name: key.split('/').pop() || key,
})); path: fullPath,
key: fullPath,
size: obj.Size,
lastModified: obj.LastModified
};
});
return NextResponse.json({ return NextResponse.json({
folders, folders,
@ -165,9 +176,12 @@ export async function POST(
return NextResponse.json({ error: 'Invalid file path' }, { status: 400 }); 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({ const command = new GetObjectCommand({
Bucket: MISSIONS_S3_CONFIG.bucket, Bucket: MISSIONS_S3_CONFIG.bucket,
Key: key Key: minioKey
}); });
const response = await missionsS3Client.send(command); const response = await missionsS3Client.send(command);
@ -215,9 +229,12 @@ export async function PUT(
return NextResponse.json({ error: 'Invalid file path' }, { status: 400 }); 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({ const command = new PutObjectCommand({
Bucket: MISSIONS_S3_CONFIG.bucket, Bucket: MISSIONS_S3_CONFIG.bucket,
Key: key, Key: minioKey,
Body: content || Buffer.alloc(0), Body: content || Buffer.alloc(0),
ContentType: 'text/plain' ContentType: 'text/plain'
}); });