From bf36e3de802f900d73d7e740de02b05d222ba104 Mon Sep 17 00:00:00 2001 From: alma Date: Tue, 6 May 2025 12:56:06 +0200 Subject: [PATCH] missions s3 --- .../missions/[missionId]/attachments/route.ts | 2 +- app/api/missions/[missionId]/route.ts | 4 ++-- app/api/missions/route.ts | 2 +- app/api/missions/upload/route.ts | 4 ++-- lib/mission-uploads.ts | 20 +++++++++---------- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/api/missions/[missionId]/attachments/route.ts b/app/api/missions/[missionId]/attachments/route.ts index 3aa29a8e..18afc045 100644 --- a/app/api/missions/[missionId]/attachments/route.ts +++ b/app/api/missions/[missionId]/attachments/route.ts @@ -64,7 +64,7 @@ export async function GET(request: Request, props: { params: Promise<{ missionId // Add public URLs to attachments const attachmentsWithUrls = attachments.map(attachment => ({ ...attachment, - publicUrl: getPublicUrl(attachment.filePath, S3_CONFIG.missionsBucket) + publicUrl: getPublicUrl(attachment.filePath, S3_CONFIG.bucket) })); return NextResponse.json(attachmentsWithUrls); diff --git a/app/api/missions/[missionId]/route.ts b/app/api/missions/[missionId]/route.ts index 480bbbea..b42630ae 100644 --- a/app/api/missions/[missionId]/route.ts +++ b/app/api/missions/[missionId]/route.ts @@ -82,10 +82,10 @@ export async function GET(request: Request, props: { params: Promise<{ missionId // Add public URLs to mission logo and attachments const missionWithUrls = { ...mission, - logoUrl: mission.logo ? getPublicUrl(mission.logo, S3_CONFIG.missionsBucket) : null, + logoUrl: mission.logo ? getPublicUrl(mission.logo, S3_CONFIG.bucket) : null, attachments: mission.attachments.map((attachment: { id: string; filename: string; filePath: string; fileType: string; fileSize: number; createdAt: Date }) => ({ ...attachment, - publicUrl: getPublicUrl(attachment.filePath, S3_CONFIG.missionsBucket) + publicUrl: getPublicUrl(attachment.filePath, S3_CONFIG.bucket) })) }; diff --git a/app/api/missions/route.ts b/app/api/missions/route.ts index c6ae164c..0843ab13 100644 --- a/app/api/missions/route.ts +++ b/app/api/missions/route.ts @@ -87,7 +87,7 @@ export async function GET(request: Request) { // Transform logo paths to public URLs const missionsWithPublicUrls = missions.map(mission => ({ ...mission, - logo: mission.logo ? getPublicUrl(mission.logo, S3_CONFIG.missionsBucket) : null + logo: mission.logo ? getPublicUrl(mission.logo, S3_CONFIG.bucket) : null })); return NextResponse.json({ diff --git a/app/api/missions/upload/route.ts b/app/api/missions/upload/route.ts index 6a042d34..92800227 100644 --- a/app/api/missions/upload/route.ts +++ b/app/api/missions/upload/route.ts @@ -148,7 +148,7 @@ export async function POST(request: Request) { console.log('Logo uploaded successfully to path:', filePath); // Generate public URL - const publicUrl = getPublicUrl(filePath, S3_CONFIG.missionsBucket); + const publicUrl = getPublicUrl(filePath, S3_CONFIG.bucket); console.log('Public URL for logo:', publicUrl); // Update mission record with logo path @@ -184,7 +184,7 @@ export async function POST(request: Request) { console.log('Attachment uploaded successfully to path:', filePath); // Generate public URL - const publicUrl = getPublicUrl(filePath, S3_CONFIG.missionsBucket); + const publicUrl = getPublicUrl(filePath, S3_CONFIG.bucket); console.log('Public URL for attachment:', publicUrl); // Create attachment record in database diff --git a/lib/mission-uploads.ts b/lib/mission-uploads.ts index 11cf6a1e..57db63f3 100644 --- a/lib/mission-uploads.ts +++ b/lib/mission-uploads.ts @@ -42,21 +42,21 @@ export async function uploadMissionLogo( const buffer = Buffer.from(arrayBuffer); console.log('Buffer created, size:', buffer.length); - // Upload to Minio using the missions bucket - console.log('Creating S3 command with bucket:', S3_CONFIG.missionsBucket); + // Upload to Minio using the pages bucket instead of missions bucket + console.log('Creating S3 command with bucket:', S3_CONFIG.bucket); console.log('S3 config:', { endpoint: S3_CONFIG.endpoint || 'MISSING!', region: S3_CONFIG.region || 'MISSING!', - bucket: S3_CONFIG.missionsBucket || 'MISSING!', + bucket: S3_CONFIG.bucket || 'MISSING!', hasAccessKey: !!S3_CONFIG.accessKey || 'MISSING!', hasSecretKey: !!S3_CONFIG.secretKey || 'MISSING!' }); // Log the full path being used - console.log('FULL S3 PATH:', `${S3_CONFIG.endpoint}/${S3_CONFIG.missionsBucket}/${filePath}`); + console.log('FULL S3 PATH:', `${S3_CONFIG.endpoint}/${S3_CONFIG.bucket}/${filePath}`); const command = new PutObjectCommand({ - Bucket: S3_CONFIG.missionsBucket, + Bucket: S3_CONFIG.bucket, Key: filePath, Body: buffer, ContentType: file.type, @@ -120,11 +120,11 @@ export async function uploadMissionAttachment( console.log('Buffer created, size:', buffer.length); // Log the full path being used - console.log('FULL S3 PATH:', `${S3_CONFIG.endpoint}/${S3_CONFIG.missionsBucket}/${filePath}`); + console.log('FULL S3 PATH:', `${S3_CONFIG.endpoint}/${S3_CONFIG.bucket}/${filePath}`); - // Upload to Minio using missions bucket + // Upload to Minio using pages bucket const command = new PutObjectCommand({ - Bucket: S3_CONFIG.missionsBucket, + Bucket: S3_CONFIG.bucket, Key: filePath, Body: buffer, ContentType: file.type, @@ -170,7 +170,7 @@ export async function uploadMissionAttachment( async function generateMissionPresignedUrl(key: string, expiresIn = 3600): Promise { try { const command = new PutObjectCommand({ - Bucket: S3_CONFIG.missionsBucket, + Bucket: S3_CONFIG.bucket, Key: key }); @@ -227,7 +227,7 @@ export async function generateMissionAttachmentUploadUrl( async function deleteMissionObject(key: string): Promise { try { const command = new DeleteObjectCommand({ - Bucket: S3_CONFIG.missionsBucket, + Bucket: S3_CONFIG.bucket, Key: key });