missions s3

This commit is contained in:
alma 2025-05-06 11:40:19 +02:00
parent cf7538225e
commit 46ed11bd32
2 changed files with 10 additions and 3 deletions

View File

@ -2,6 +2,7 @@ import { NextResponse } from 'next/server';
import { getServerSession } from 'next-auth'; import { getServerSession } from 'next-auth';
import { authOptions } from "@/app/api/auth/options"; import { authOptions } from "@/app/api/auth/options";
import { prisma } from '@/lib/prisma'; import { prisma } from '@/lib/prisma';
import { getPublicUrl } from '@/lib/s3';
// Helper function to check authentication // Helper function to check authentication
async function checkAuth(request: Request) { async function checkAuth(request: Request) {
@ -82,8 +83,14 @@ export async function GET(request: Request) {
// Get total count // Get total count
const totalCount = await prisma.mission.count({ where }); const totalCount = await prisma.mission.count({ where });
// Transform logo paths to public URLs
const missionsWithPublicUrls = missions.map(mission => ({
...mission,
logo: mission.logo ? getPublicUrl(mission.logo) : null
}));
return NextResponse.json({ return NextResponse.json({
missions, missions: missionsWithPublicUrls,
pagination: { pagination: {
total: totalCount, total: totalCount,
offset, offset,

View File

@ -199,12 +199,12 @@ export default function MissionsPage() {
<div className="flex-shrink-0 mr-4 w-16 h-16 relative"> <div className="flex-shrink-0 mr-4 w-16 h-16 relative">
{mission.logo ? ( {mission.logo ? (
<img <img
src={mission.logo ? getPublicUrl(mission.logo) : ''} src={mission.logo || ''}
alt={mission.name} alt={mission.name}
className="w-full h-full object-cover rounded-md border border-gray-200" className="w-full h-full object-cover rounded-md border border-gray-200"
onError={(e) => { onError={(e) => {
console.log("Logo failed to load:", mission.logo); console.log("Logo failed to load:", mission.logo);
console.log("Full URL attempted:", mission.logo ? getPublicUrl(mission.logo) : 'undefined logo'); console.log("Full URL attempted:", mission.logo);
// If the image fails to load, show the fallback // If the image fails to load, show the fallback
(e.currentTarget as HTMLImageElement).style.display = 'none'; (e.currentTarget as HTMLImageElement).style.display = 'none';
// Show the fallback div // Show the fallback div