![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/domains/soundstudiopro.com/private_html/utils/ |
<?php
// Enable error reporting for debugging
error_reporting(E_ALL);
ini_set('display_errors', 0);
// Set proper headers
header('Content-Type: application/json; charset=utf-8');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type, Authorization');
// Handle preflight requests
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
http_response_code(200);
exit(0);
}
// Include database configuration
require_once 'config/database.php';
// Start session to get user info
session_start();
// Check if user is logged in
if (!isset($_SESSION['user_id'])) {
http_response_code(401);
echo json_encode(['success' => false, 'error' => 'User not authenticated']);
exit;
}
try {
// Get the request data
$input = json_decode(file_get_contents('php://input'), true);
$method = $_SERVER['REQUEST_METHOD'];
if ($method === 'GET') {
// GET request - retrieve by task ID from URL parameter
$taskId = $_GET['taskId'] ?? null;
} else {
// POST request - retrieve by task ID from JSON body
$taskId = $input['taskId'] ?? null;
}
if (!$taskId) {
throw new Exception('Task ID is required');
}
// Get result from database
$track = getMusicTrackByTaskId($taskId);
if (!$track) {
// Task not found or still processing
echo json_encode([
'success' => true,
'status' => 'processing',
'message' => 'Task is still being processed',
'taskId' => $taskId
]);
exit;
}
// Check if this track belongs to the current user
if ($track['user_id'] != $_SESSION['user_id']) {
http_response_code(403);
echo json_encode(['success' => false, 'error' => 'Access denied']);
exit;
}
if ($track['status'] === 'processing') {
echo json_encode([
'success' => true,
'status' => 'processing',
'message' => 'Task is still being processed',
'taskId' => $taskId
]);
exit;
}
// Return the complete result
$resultData = [
'taskId' => $track['task_id'],
'status' => $track['status'],
'audio_url' => $track['audio_url'],
'video_url' => $track['video_url'],
'lyrics' => $track['lyrics'],
'title' => $track['title'],
'prompt' => $track['prompt'],
'duration' => $track['duration'],
'created_at' => $track['created_at']
];
// Return the result
echo json_encode([
'success' => true,
'status' => 'complete',
'data' => $resultData,
'taskId' => $taskId
]);
} catch (Exception $e) {
// Log the error for debugging
error_log('Get Result API Error: ' . $e->getMessage());
http_response_code(500);
echo json_encode([
'success' => false,
'error' => $e->getMessage()
]);
}
?>