missions mission pages
This commit is contained in:
parent
6d3827bd6c
commit
ff1b5244e6
70
app/api/centrale/image/[...path]/route.ts
Normal file
70
app/api/centrale/image/[...path]/route.ts
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
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 });
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -224,14 +224,16 @@ export default function CentralePage() {
|
|||||||
<div className="w-48 h-48 relative">
|
<div className="w-48 h-48 relative">
|
||||||
{mission.logo ? (
|
{mission.logo ? (
|
||||||
<img
|
<img
|
||||||
src={mission.logo || ''}
|
src={mission.logo}
|
||||||
alt={mission.name}
|
alt={mission.name}
|
||||||
className="w-full h-full object-cover rounded-md"
|
className="w-full h-full object-cover rounded-md"
|
||||||
onError={(e) => {
|
onError={(e) => {
|
||||||
console.log("Logo failed to load:", mission.logo);
|
console.error("Logo failed to load:", mission.logo);
|
||||||
console.log("Full URL attempted:", mission.logo);
|
console.error("Full URL attempted:", window.location.origin + 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
|
||||||
const fallbackDiv = e.currentTarget.parentElement?.querySelector('.logo-fallback');
|
const fallbackDiv = e.currentTarget.parentElement?.querySelector('.logo-fallback');
|
||||||
if (fallbackDiv) {
|
if (fallbackDiv) {
|
||||||
|
|||||||
@ -146,7 +146,7 @@ export function Sidebar({ isOpen, onClose }: SidebarProps) {
|
|||||||
iframe: process.env.NEXT_PUBLIC_IFRAME_PAROLE_URL,
|
iframe: process.env.NEXT_PUBLIC_IFRAME_PAROLE_URL,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "Centrale",
|
title: "Mes Missions",
|
||||||
icon: Kanban,
|
icon: Kanban,
|
||||||
href: "/centrale",
|
href: "/centrale",
|
||||||
iframe: process.env.NEXT_PUBLIC_IFRAME_MISSIONSBOARD_URL,
|
iframe: process.env.NEXT_PUBLIC_IFRAME_MISSIONSBOARD_URL,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user