<?php
declare(strict_types=1);
require __DIR__ . '/auth.php';
send_security_headers();
site_language();

if (current_user() === null) {
    redirect_to('/register.php');
}

$path = getenv('UCAIY_APK_PATH') ?: '/var/lib/ucaiy/mihuan-ai-86-30.apk';
if (!is_file($path) || !is_readable($path)) {
    http_response_code(404);
    exit(site_text('下载文件暂不可用。', 'The download is temporarily unavailable.'));
}

header('Content-Type: application/vnd.android.package-archive');
header('Content-Disposition: attachment; filename="mihuan-ai-86-30.apk"');
header('Content-Length: ' . (string) filesize($path));
readfile($path);
