<?php
// Face API Model Proxy
// This script serves as a proxy to load face-api.js models when direct CDN access fails

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET');
header('Access-Control-Allow-Headers: Content-Type');

$model = $_GET['model'] ?? '';

// Define allowed models to prevent arbitrary file access
$allowed_models = [
    'tiny_face_detector_model-weights_manifest.json',
    'tiny_face_detector_model-shard1',
    'tiny_face_detector_model-shard2',
    'tiny_face_detector_model-shard3'
];

if (!in_array($model, $allowed_models)) {
    http_response_code(400);
    die('Invalid model requested');
}

// Set appropriate content type based on file extension
if (strpos($model, '.json') !== false) {
    header('Content-Type: application/json');
} else {
    header('Content-Type: application/octet-stream');
}

// In a real implementation, you would fetch the model from a reliable source
// For now, we'll return a 404 to indicate that manual download is required
http_response_code(404);
echo "Model file not found. Please download the required model files manually.\n";
echo "See setup_face_models.php for download links.";
?>