<?php
/**
 * 资源下载代理
 */
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../includes/LicenseClient.php';

// 权限检查：仅管理员可下载
if (!isAdmin()) {
    header('HTTP/1.1 403 Forbidden');
    exit;
}

$id = intval($_GET['id'] ?? 0);
if ($id <= 0) {
    header('HTTP/1.1 400 Bad Request');
    exit;
}

try {
    $client = new LicenseClient();
    $download_url = $client->getResourceDownloadUrl($id);
    
    // 重定向到主站下载地址
    header('Location: ' . $download_url);
    exit;
} catch (Exception $e) {
    header('HTTP/1.1 500 Internal Server Error');
    echo '下载失败：' . $e->getMessage();
    exit;
}