diff --git a/app/api/centrale/[missionId]/route.ts b/app/api/centrale/[missionId]/route.ts deleted file mode 100644 index cf7189b7..00000000 --- a/app/api/centrale/[missionId]/route.ts +++ /dev/null @@ -1,101 +0,0 @@ -import { NextResponse } from 'next/server'; -import { getServerSession } from 'next-auth'; -import { authOptions } from "@/app/api/auth/options"; -import { prisma } from '@/lib/prisma'; -import { deleteMissionLogo } from '@/lib/mission-uploads'; -import { getPublicUrl, S3_CONFIG } from '@/lib/s3'; -import { IntegrationService } from '@/lib/services/integration-service'; - -// Helper function to check authentication -async function checkAuth(request: Request) { - const session = await getServerSession(authOptions); - if (!session?.user?.id) { - console.error('Unauthorized access attempt:', { - url: request.url, - method: request.method, - headers: Object.fromEntries(request.headers) - }); - return { authorized: false, userId: null }; - } - return { authorized: true, userId: session.user.id }; -} - -// GET endpoint to retrieve a mission by ID -export async function GET(request: Request, props: { params: Promise<{ missionId: string }> }) { - const params = await props.params; - try { - const { authorized, userId } = await checkAuth(request); - if (!authorized || !userId) { - return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); - } - - const { missionId } = params; - if (!missionId) { - return NextResponse.json({ error: 'Mission ID is required' }, { status: 400 }); - } - - // Get mission with detailed info - const mission = await (prisma as any).mission.findFirst({ - where: { - id: missionId, - OR: [ - { creatorId: userId }, - { missionUsers: { some: { userId } } } - ] - }, - include: { - creator: { - select: { - id: true, - email: true - } - }, - missionUsers: { - select: { - id: true, - role: true, - user: { - select: { - id: true, - email: true - } - } - } - }, - attachments: { - select: { - id: true, - filename: true, - filePath: true, - fileType: true, - fileSize: true, - createdAt: true - }, - orderBy: { createdAt: 'desc' } - } - } - }); - - if (!mission) { - return NextResponse.json({ error: 'Mission not found or access denied' }, { status: 404 }); - } - - // Add public URLs to mission logo and attachments - const missionWithUrls = { - ...mission, - logoUrl: mission.logo ? `/api/centrale/image/${mission.logo}` : null, - attachments: mission.attachments.map((attachment: { id: string; filename: string; filePath: string; fileType: string; fileSize: number; createdAt: Date }) => ({ - ...attachment, - publicUrl: `/api/centrale/image/${attachment.filePath}` - })) - }; - - return NextResponse.json(missionWithUrls); - } catch (error) { - console.error('Error retrieving mission:', error); - return NextResponse.json({ - error: 'Internal server error', - details: error instanceof Error ? error.message : String(error) - }, { status: 500 }); - } -} \ No newline at end of file diff --git a/app/api/centrale/all/route.ts b/app/api/centrale/all/route.ts index 442922c5..9f65c6a7 100644 --- a/app/api/centrale/all/route.ts +++ b/app/api/centrale/all/route.ts @@ -88,7 +88,7 @@ export async function GET(request: Request) { // Transform logo paths to public URLs const missionsWithPublicUrls = missions.map(mission => ({ ...mission, - logo: mission.logo ? `/api/centrale/image/${mission.logo}` : null + logo: mission.logo ? `/api/missions/image/${mission.logo}` : null })); return NextResponse.json({ diff --git a/app/api/centrale/image/[...path]/route.ts b/app/api/centrale/image/[...path]/route.ts deleted file mode 100644 index 80c0f861..00000000 --- a/app/api/centrale/image/[...path]/route.ts +++ /dev/null @@ -1,70 +0,0 @@ -import { NextRequest, NextResponse } from 'next/server'; -import { getServerSession } from 'next-auth'; -import { authOptions } from '@/app/api/auth/options'; -import { S3Client, GetObjectCommand } from '@aws-sdk/client-s3'; -import { S3_CONFIG } from '@/lib/s3'; - -// Initialize S3 client -const s3Client = new S3Client({ - region: S3_CONFIG.region, - endpoint: S3_CONFIG.endpoint, - credentials: { - accessKeyId: S3_CONFIG.accessKey || '', - secretAccessKey: S3_CONFIG.secretKey || '' - }, - forcePathStyle: true // Required for MinIO -}); - -// This endpoint serves mission images from Minio using the server's credentials -export async function GET(request: NextRequest, { params }: { params: { path: string[] } }) { - try { - // Check if path is provided - if (!params.path || params.path.length === 0) { - console.error('Missing path parameter'); - return new NextResponse('Path is required', { status: 400 }); - } - - // Reconstruct the full path from path segments - const filePath = params.path.join('/'); - console.log('Fetching centrale image:', filePath); - console.log('S3 bucket being used:', S3_CONFIG.bucket); - - // Create S3 command to get the object - const command = new GetObjectCommand({ - Bucket: S3_CONFIG.bucket, // Use the pages bucket - Key: filePath, - }); - - // Get the object from S3/Minio - console.log('Sending S3 request...'); - const response = await s3Client.send(command); - console.log('S3 response received'); - - if (!response.Body) { - console.error('File not found in Minio:', filePath); - return new NextResponse('File not found', { status: 404 }); - } - - // Log success information - console.log('File found, content type:', response.ContentType); - console.log('File size:', response.ContentLength, 'bytes'); - - // Get the readable web stream directly - const stream = response.Body.transformToWebStream(); - - // Determine content type - const contentType = response.ContentType || 'application/octet-stream'; - - // Create and return a new response with the file stream - return new NextResponse(stream as ReadableStream, { - headers: { - 'Content-Type': contentType, - 'Cache-Control': 'public, max-age=31536000', // Cache for 1 year - }, - }); - } catch (error) { - console.error('Error serving centrale image:', error); - console.error('Error details:', JSON.stringify(error, null, 2)); - return new NextResponse('Internal Server Error', { status: 500 }); - } -} \ No newline at end of file diff --git a/app/api/centrale/route.ts b/app/api/centrale/route.ts index d993b769..66c100e2 100644 --- a/app/api/centrale/route.ts +++ b/app/api/centrale/route.ts @@ -87,13 +87,13 @@ export async function GET(request: Request) { const totalCount = await (prisma as any).mission.count({ where }); // Transform logo paths to public URLs - const missionsWithFormatting = missions.map((mission: any) => ({ + const missionsWithPublicUrls = missions.map((mission: any) => ({ ...mission, - logo: mission.logo ? `/api/centrale/image/${mission.logo}` : null + logo: mission.logo ? `/api/missions/image/${mission.logo}` : null })); return NextResponse.json({ - missions: missionsWithFormatting, + missions: missionsWithPublicUrls, pagination: { total: totalCount, offset, diff --git a/app/centrale/[missionId]/edit/page.tsx b/app/centrale/[missionId]/edit/page.tsx index 0389f916..8dd05227 100644 --- a/app/centrale/[missionId]/edit/page.tsx +++ b/app/centrale/[missionId]/edit/page.tsx @@ -1,67 +1,58 @@ "use client"; import { useState, useEffect } from "react"; -import { useRouter } from "next/navigation"; -import { MissionsAdminPanel } from "@/components/missions/missions-admin-panel"; import { Button } from "@/components/ui/button"; -import { ArrowLeft, Home } from "lucide-react"; +import { useToast } from "@/components/ui/use-toast"; +import { useParams, useRouter } from "next/navigation"; -export default function EditMissionPage({ params }: { params: { missionId: string }}) { +export default function EditMissionPage() { + const [loading, setLoading] = useState(true); + const { toast } = useToast(); + const params = useParams(); const router = useRouter(); - const { missionId } = params; - const [isLoading, setIsLoading] = useState(true); - - // Check if the mission exists + const missionId = params.missionId as string; + useEffect(() => { - const checkMission = async () => { - try { - const response = await fetch(`/api/centrale/${missionId}`); - if (!response.ok) { - console.error('Mission not found, redirecting to list'); - router.push('/centrale'); - } - setIsLoading(false); - } catch (error) { - console.error('Error checking mission:', error); - router.push('/centrale'); - } - }; + toast({ + title: "Fonctionnalité en développement", + description: "L'édition de mission sera bientôt disponible.", + variant: "default", + }); - checkMission(); - }, [missionId, router]); - - if (isLoading) { - return
+ La fonctionnalité d'édition de mission est en cours de développement et sera disponible prochainement. +
+ +