<?php
require_once __DIR__ . '/../../config/bootstrap.php';

$logoPath = $_GET['path'] ?? '';

if (empty($logoPath)) {
    http_response_code(404);
    exit('Logo no encontrado');
}

// Sanitizar el path para evitar directory traversal
$logoPath = str_replace(['..', '\\'], ['', '/'], $logoPath);
$fullPath = storage_path($logoPath);

if (!file_exists($fullPath)) {
    http_response_code(404);
    exit('Logo no encontrado');
}

// Detectar tipo MIME
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mimeType = finfo_file($finfo, $fullPath);
finfo_close($finfo);

// Servir imagen
header('Content-Type: ' . $mimeType);
header('Content-Length: ' . filesize($fullPath));
header('Cache-Control: public, max-age=31536000'); // Cache por 1 año
header('Content-Disposition: inline');

readfile($fullPath);
exit;
