mission-tab deletemission

This commit is contained in:
alma 2026-01-04 15:43:42 +01:00
parent aafe4d7035
commit 96738a341f

View File

@ -6,7 +6,7 @@ import { N8nService } from '@/lib/services/n8n-service';
import { Prisma } from '@prisma/client'; import { Prisma } from '@prisma/client';
import { s3Client } from '@/lib/s3'; import { s3Client } from '@/lib/s3';
import { CopyObjectCommand, DeleteObjectCommand, HeadObjectCommand } from '@aws-sdk/client-s3'; import { CopyObjectCommand, DeleteObjectCommand, HeadObjectCommand } from '@aws-sdk/client-s3';
import { uploadMissionLogo, uploadMissionAttachment } from '@/lib/mission-uploads'; import { uploadMissionLogo, uploadMissionAttachment, getMissionFileUrl } from '@/lib/mission-uploads';
// Types // Types
interface MissionCreateInput { interface MissionCreateInput {
@ -284,6 +284,7 @@ export async function POST(request: Request) {
// Step 3: Upload logo to Minio if present // Step 3: Upload logo to Minio if present
let logoPath = null; let logoPath = null;
let logoUrl = null; // Public URL for the logo
if (body.logo?.data) { if (body.logo?.data) {
try { try {
// Convert base64 to File object // Convert base64 to File object
@ -296,13 +297,25 @@ export async function POST(request: Request) {
logoPath = filePath; logoPath = filePath;
uploadedFiles.push({ type: 'logo', path: filePath }); uploadedFiles.push({ type: 'logo', path: filePath });
// Generate public URL for the logo (using the API endpoint)
// Use the helper function to construct the URL
const relativeUrl = getMissionFileUrl(filePath);
// Construct full URL with base domain
const baseUrl = process.env.NEXT_PUBLIC_API_URL || process.env.NEXT_PUBLIC_APP_URL || 'https://hub.slm-lab.net';
logoUrl = `${baseUrl}${relativeUrl}`;
// Update mission with logo path // Update mission with logo path
await prisma.mission.update({ await prisma.mission.update({
where: { id: mission.id }, where: { id: mission.id },
data: { logo: filePath } data: { logo: filePath }
}); });
console.log('Logo uploaded successfully:', { logoPath }); console.log('Logo uploaded successfully:', {
logoPath,
logoUrl,
baseUrl
});
} catch (uploadError) { } catch (uploadError) {
console.error('Error uploading logo:', uploadError); console.error('Error uploading logo:', uploadError);
throw new Error('Failed to upload logo'); throw new Error('Failed to upload logo');