From 9db972b80a375d5b2df8b53ea62b3e72c6a223b3 Mon Sep 17 00:00:00 2001 From: alma Date: Fri, 16 Jan 2026 14:56:00 +0100 Subject: [PATCH] Pages corrections pages missions --- .../[missionId]/files/folder/route.ts | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/app/api/missions/[missionId]/files/folder/route.ts b/app/api/missions/[missionId]/files/folder/route.ts index 070d38f..35eceee 100644 --- a/app/api/missions/[missionId]/files/folder/route.ts +++ b/app/api/missions/[missionId]/files/folder/route.ts @@ -5,14 +5,15 @@ import { prisma } from '@/lib/prisma'; import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3'; // Use the exact same S3 client configuration as mission-uploads.ts +// Use hardcoded credentials as primary (same as mission-uploads.ts) const missionsS3Client = new S3Client({ region: 'us-east-1', endpoint: 'https://dome-api.slm-lab.net', credentials: { - accessKeyId: process.env.MINIO_ACCESS_KEY || '4aBT4CMb7JIMMyUtp4Pl', - secretAccessKey: process.env.MINIO_SECRET_KEY || 'HGn39XhCIlqOjmDVzRK9MED2Fci2rYvDDgbLFElg' + accessKeyId: '4aBT4CMb7JIMMyUtp4Pl', // Primary: hardcoded (same as mission-uploads.ts) + secretAccessKey: 'HGn39XhCIlqOjmDVzRK9MED2Fci2rYvDDgbLFElg' // Primary: hardcoded (same as mission-uploads.ts) }, - forcePathStyle: true + forcePathStyle: true // Required for MinIO }); const MISSIONS_BUCKET = 'missions'; @@ -68,7 +69,25 @@ export async function POST( // Construct the S3 key for the folder marker // Files are stored in MinIO without the "missions/" prefix - const s3Key = path.endsWith('/') ? `${path}.placeholder` : `${path}/.placeholder`; + // The path from frontend might be relative (e.g., "attachments/Content") or absolute + // We need to ensure it includes the missionId + let folderPath = path; + if (!folderPath.startsWith(missionId)) { + // If path doesn't start with missionId, prepend it + folderPath = `${missionId}/${folderPath}`; + } + + // Remove "missions/" prefix if present (for consistency) + folderPath = folderPath.replace(/^missions\//, ''); + + const s3Key = folderPath.endsWith('/') ? `${folderPath}.placeholder` : `${folderPath}/.placeholder`; + + console.log(`[POST /api/missions/${missionId}/files/folder] Creating folder:`, { + originalPath: path, + folderPath: folderPath, + s3Key: s3Key, + bucket: MISSIONS_BUCKET + }); // Create folder marker in S3 await missionsS3Client.send(new PutObjectCommand({