![]() 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/api/ |
<?php
// Don't require session for track details - just viewing
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type');
require_once '../config/database.php';
try {
$pdo = getDBConnection();
$track_id = $_GET['track_id'] ?? null;
// Log the request
error_log("Track details request for track_id: " . $track_id);
if (!$track_id) {
throw new Exception('Track ID is required');
}
// Get track information with artist details
$stmt = $pdo->prepare("
SELECT
mt.id,
mt.title,
mt.prompt,
mt.duration,
mt.audio_url,
mt.status,
mt.created_at,
mt.music_type,
mt.metadata,
mt.price,
u.name as artist_name,
u.id as artist_id
FROM music_tracks mt
JOIN users u ON mt.user_id = u.id
WHERE mt.id = ? AND mt.status = 'complete'
");
$stmt->execute([$track_id]);
$track = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$track) {
error_log("Track not found for ID: " . $track_id);
throw new Exception('Track not found or not available for purchase');
}
error_log("Track found: " . $track['title']);
// Parse metadata for additional info
$metadata = json_decode($track['metadata'] ?: '{}', true);
// Process track for display
$processed_track = [
'id' => $track['id'],
'title' => $track['title'] ?: 'Untitled Track',
'duration' => $track['duration'] ?: 0,
'audio_url' => $track['audio_url'],
'status' => $track['status'],
'created_at' => $track['created_at'],
'music_type' => $track['music_type'] ?: 'music',
'genre' => $metadata['genre'] ?? 'Unknown',
'description' => $track['prompt'] ?: '',
'price' => floatval($track['price'] ?: 1.00), // Convert to float
'artist_name' => $track['artist_name'] ?: 'Unknown Artist',
'artist_id' => $track['artist_id'],
'metadata' => $metadata // CRITICAL FIX: Include metadata so stems can be accessed
];
echo json_encode([
'success' => true,
'track' => $processed_track
]);
} catch (Exception $e) {
http_response_code(400);
echo json_encode([
'success' => false,
'error' => $e->getMessage()
]);
}
?>