cinema-studio-pro/backend/get_current_image.php
2026-01-13 14:52:37 +05:30

70 lines
1.8 KiB
PHP

<?php
/**
* Get Current Image API
* Returns the current session image as JSON with base64 data
*/
// Suppress HTML error output
error_reporting(E_ALL);
ini_set('display_errors', 0);
ini_set('log_errors', 1);
header('Content-Type: application/json');
// Initialize session manager
require_once 'session_manager.php';
$sessionManager = new SessionManager();
// Initialize auth status with default (for logging)
$authStatus = [
'authenticated' => true,
'user' => [
'name' => 'User',
'preferred_username' => 'anonymous@nano-banana-pro.com'
]
];
// Check authentication (with graceful fallback)
try {
if (file_exists(__DIR__ . '/AuthMiddleware.php')) {
require_once 'AuthMiddleware.php';
$auth = new AuthMiddleware();
$authStatus = $auth->isAuthenticated();
if (!$authStatus['authenticated']) {
http_response_code(401);
echo json_encode([
'success' => false,
'error' => 'Authentication required'
]);
exit;
}
}
} catch (Exception $e) {
// Log error but continue without auth (for testing)
error_log("Auth check failed in get_current_image.php: " . $e->getMessage());
}
try {
// Get current image from session
$currentImage = $sessionManager->getCurrentImage();
if ($currentImage) {
echo json_encode([
'success' => true,
'data' => $currentImage['data'],
'mime_type' => $currentImage['mime_type']
]);
} else {
echo json_encode([
'success' => false,
'error' => 'No image in current session'
]);
}
} catch (Exception $e) {
http_response_code(500);
echo json_encode([
'success' => false,
'error' => $e->getMessage()
]);
}