<?php
header('Content-Type: application/json; charset=utf-8');
header('Access-Control-Allow-Origin: *');

$dbPath = __DIR__ . '/../wedding_data.db';
try {
    $pdo = new PDO("sqlite:$dbPath");
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    $stmt = $pdo->query("SELECT storage_path, file_name FROM audio_assets WHERE audio_type = 'bgm' AND is_active = 1 ORDER BY created_at");
    $audioList = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    echo json_encode(array(
        'success' => true,
        'data' => $audioList
    ));
} catch (PDOException $e) {
    echo json_encode(array(
        'success' => false,
        'message' => '数据库查询失败: ' . $e->getMessage()
    ));
}
?>