<?php
// Public, unauthenticated download of the current stable release --
// linked from the keylair.com sales page's "Download Community" button
// instead of the GitLab repository (which requires a login most
// visitors won't have). Fetches the same generic-package zip
// admin/deploy.php's own update mechanism uses, via the same
// read-only Deploy Token (see src/Deployer.php).

require __DIR__ . '/bootstrap.php';

use KeyLair\Deployer;

$zip = Deployer::fetchStableZip();

if ($zip === null) {
    http_response_code(502);
    header('Content-Type: text/plain; charset=utf-8');
    echo "Couldn't reach the download server right now. Please try again in a moment.";
    exit;
}

header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename="key-lair-latest.zip"');
header('Content-Length: ' . strlen($zip));
echo $zip;
