missions s3

This commit is contained in:
alma 2025-05-06 12:56:06 +02:00
parent f1db84bca7
commit bf36e3de80
5 changed files with 16 additions and 16 deletions

View File

@ -64,7 +64,7 @@ export async function GET(request: Request, props: { params: Promise<{ missionId
// Add public URLs to attachments // Add public URLs to attachments
const attachmentsWithUrls = attachments.map(attachment => ({ const attachmentsWithUrls = attachments.map(attachment => ({
...attachment, ...attachment,
publicUrl: getPublicUrl(attachment.filePath, S3_CONFIG.missionsBucket) publicUrl: getPublicUrl(attachment.filePath, S3_CONFIG.bucket)
})); }));
return NextResponse.json(attachmentsWithUrls); return NextResponse.json(attachmentsWithUrls);

View File

@ -82,10 +82,10 @@ export async function GET(request: Request, props: { params: Promise<{ missionId
// Add public URLs to mission logo and attachments // Add public URLs to mission logo and attachments
const missionWithUrls = { const missionWithUrls = {
...mission, ...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 }) => ({ attachments: mission.attachments.map((attachment: { id: string; filename: string; filePath: string; fileType: string; fileSize: number; createdAt: Date }) => ({
...attachment, ...attachment,
publicUrl: getPublicUrl(attachment.filePath, S3_CONFIG.missionsBucket) publicUrl: getPublicUrl(attachment.filePath, S3_CONFIG.bucket)
})) }))
}; };

View File

@ -87,7 +87,7 @@ export async function GET(request: Request) {
// Transform logo paths to public URLs // Transform logo paths to public URLs
const missionsWithPublicUrls = missions.map(mission => ({ const missionsWithPublicUrls = missions.map(mission => ({
...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({ return NextResponse.json({

View File

@ -148,7 +148,7 @@ export async function POST(request: Request) {
console.log('Logo uploaded successfully to path:', filePath); console.log('Logo uploaded successfully to path:', filePath);
// Generate public URL // Generate public URL
const publicUrl = getPublicUrl(filePath, S3_CONFIG.missionsBucket); const publicUrl = getPublicUrl(filePath, S3_CONFIG.bucket);
console.log('Public URL for logo:', publicUrl); console.log('Public URL for logo:', publicUrl);
// Update mission record with logo path // Update mission record with logo path
@ -184,7 +184,7 @@ export async function POST(request: Request) {
console.log('Attachment uploaded successfully to path:', filePath); console.log('Attachment uploaded successfully to path:', filePath);
// Generate public URL // Generate public URL
const publicUrl = getPublicUrl(filePath, S3_CONFIG.missionsBucket); const publicUrl = getPublicUrl(filePath, S3_CONFIG.bucket);
console.log('Public URL for attachment:', publicUrl); console.log('Public URL for attachment:', publicUrl);
// Create attachment record in database // Create attachment record in database

View File

@ -42,21 +42,21 @@ export async function uploadMissionLogo(
const buffer = Buffer.from(arrayBuffer); const buffer = Buffer.from(arrayBuffer);
console.log('Buffer created, size:', buffer.length); console.log('Buffer created, size:', buffer.length);
// Upload to Minio using the missions bucket // Upload to Minio using the pages bucket instead of missions bucket
console.log('Creating S3 command with bucket:', S3_CONFIG.missionsBucket); console.log('Creating S3 command with bucket:', S3_CONFIG.bucket);
console.log('S3 config:', { console.log('S3 config:', {
endpoint: S3_CONFIG.endpoint || 'MISSING!', endpoint: S3_CONFIG.endpoint || 'MISSING!',
region: S3_CONFIG.region || 'MISSING!', region: S3_CONFIG.region || 'MISSING!',
bucket: S3_CONFIG.missionsBucket || 'MISSING!', bucket: S3_CONFIG.bucket || 'MISSING!',
hasAccessKey: !!S3_CONFIG.accessKey || 'MISSING!', hasAccessKey: !!S3_CONFIG.accessKey || 'MISSING!',
hasSecretKey: !!S3_CONFIG.secretKey || 'MISSING!' hasSecretKey: !!S3_CONFIG.secretKey || 'MISSING!'
}); });
// Log the full path being used // 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({ const command = new PutObjectCommand({
Bucket: S3_CONFIG.missionsBucket, Bucket: S3_CONFIG.bucket,
Key: filePath, Key: filePath,
Body: buffer, Body: buffer,
ContentType: file.type, ContentType: file.type,
@ -120,11 +120,11 @@ export async function uploadMissionAttachment(
console.log('Buffer created, size:', buffer.length); console.log('Buffer created, size:', buffer.length);
// Log the full path being used // 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({ const command = new PutObjectCommand({
Bucket: S3_CONFIG.missionsBucket, Bucket: S3_CONFIG.bucket,
Key: filePath, Key: filePath,
Body: buffer, Body: buffer,
ContentType: file.type, ContentType: file.type,
@ -170,7 +170,7 @@ export async function uploadMissionAttachment(
async function generateMissionPresignedUrl(key: string, expiresIn = 3600): Promise<string> { async function generateMissionPresignedUrl(key: string, expiresIn = 3600): Promise<string> {
try { try {
const command = new PutObjectCommand({ const command = new PutObjectCommand({
Bucket: S3_CONFIG.missionsBucket, Bucket: S3_CONFIG.bucket,
Key: key Key: key
}); });
@ -227,7 +227,7 @@ export async function generateMissionAttachmentUploadUrl(
async function deleteMissionObject(key: string): Promise<boolean> { async function deleteMissionObject(key: string): Promise<boolean> {
try { try {
const command = new DeleteObjectCommand({ const command = new DeleteObjectCommand({
Bucket: S3_CONFIG.missionsBucket, Bucket: S3_CONFIG.bucket,
Key: key Key: key
}); });