76 lines
2.8 KiB
PHP
76 lines
2.8 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
header('X-Content-Type-Options: nosniff');
|
|
header('Referrer-Policy: no-referrer');
|
|
|
|
$apiUrl = 'https://git.dominicspringer.de/api/v1/repos/Emporex/Void-Bastion-Releases/releases';
|
|
$response = false;
|
|
|
|
if (function_exists('curl_init')) {
|
|
$curl = curl_init($apiUrl);
|
|
curl_setopt_array($curl, [
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_FOLLOWLOCATION => true,
|
|
CURLOPT_CONNECTTIMEOUT => 4,
|
|
CURLOPT_TIMEOUT => 8,
|
|
CURLOPT_USERAGENT => 'GerGames-Void-Bastion-Website/1.0',
|
|
CURLOPT_HTTPHEADER => ['Accept: application/json'],
|
|
]);
|
|
$body = curl_exec($curl);
|
|
$status = (int) curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
|
|
curl_close($curl);
|
|
if (is_string($body) && $status >= 200 && $status < 300) {
|
|
$response = $body;
|
|
}
|
|
} else {
|
|
$context = stream_context_create(['http' => [
|
|
'method' => 'GET',
|
|
'timeout' => 8,
|
|
'ignore_errors' => true,
|
|
'header' => "Accept: application/json\r\nUser-Agent: GerGames-Void-Bastion-Website/1.0\r\n",
|
|
]]);
|
|
$body = @file_get_contents($apiUrl, false, $context);
|
|
if (is_string($body)) {
|
|
$response = $body;
|
|
}
|
|
}
|
|
|
|
$releases = is_string($response) ? json_decode($response, true) : null;
|
|
if (!is_array($releases)) {
|
|
http_response_code(503);
|
|
header('Cache-Control: no-store');
|
|
echo json_encode(['error' => 'Release-Information vorübergehend nicht verfügbar.']);
|
|
exit;
|
|
}
|
|
|
|
foreach ($releases as $release) {
|
|
if (!is_array($release) || !empty($release['draft'])) {
|
|
continue;
|
|
}
|
|
foreach (($release['assets'] ?? []) as $asset) {
|
|
if (!is_array($asset) || strtolower((string) ($asset['name'] ?? '')) !== 'void-bastion-setup-x64.exe') {
|
|
continue;
|
|
}
|
|
$downloadUrl = (string) ($asset['browser_download_url'] ?? '');
|
|
$parts = parse_url($downloadUrl);
|
|
if (($parts['scheme'] ?? '') !== 'https' || strtolower((string) ($parts['host'] ?? '')) !== 'git.dominicspringer.de') {
|
|
continue;
|
|
}
|
|
|
|
header('Cache-Control: public, max-age=300, stale-while-revalidate=600');
|
|
echo json_encode([
|
|
'version' => ltrim((string) ($release['tag_name'] ?? ''), 'v'),
|
|
'windows_url' => $downloadUrl,
|
|
'release_url' => 'https://git.dominicspringer.de/Emporex/Void-Bastion-Releases/releases/tag/' . rawurlencode((string) ($release['tag_name'] ?? '')),
|
|
'windows_size_mib' => (string) max(1, (int) round(((int) ($asset['size'] ?? 0)) / 1048576)),
|
|
], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
http_response_code(404);
|
|
header('Cache-Control: no-store');
|
|
echo json_encode(['error' => 'Es wurde noch kein Windows-Setup veröffentlicht.']);
|