| 1 |
<?php |
| 2 |
|
| 3 |
header("Expires: Tue, 03 Jul 2001 06:00:00 GMT"); |
| 4 |
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); |
| 5 |
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); |
| 6 |
header("Cache-Control: post-check=0, pre-check=0", false); |
| 7 |
header("Pragma: no-cache"); |
| 8 |
header("Status: 200 OK"); |
| 9 |
|
| 10 |
|
| 11 |
list($_, $version, $arch, $type) = explode('/', preg_replace('/https:\/\/dl\.dpp\.dev\//', '', $_SERVER['REDIRECT_URL'] ?? ''), 4); |
| 12 |
$version = !empty($version) ? $version : 'latest'; |
| 13 |
$arch = !empty($arch) ? $arch : 'linux-x64'; |
| 14 |
$type = !empty($type) ? $type : 'deb'; |
| 15 |
$urls = []; |
| 16 |
|
| 17 |
|
| 18 |
if (preg_match('/^win/i', $arch) && $type === 'deb') { |
| 19 |
$type = 'zip'; |
| 20 |
} |
| 21 |
|
| 22 |
if ($arch === 'win') { |
| 23 |
$arch = 'win32-release-vs2019'; |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
$json = json_decode(file_get_contents('release.json')); |
| 28 |
|
| 29 |
|
| 30 |
if ($version === 'latest') { |
| 31 |
$version = $json[0]->tag_name; |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
$searchName = 'libdpp-' . preg_replace('/^v/', '', $version) . '-' . $arch . '.' . $type; |
| 36 |
|
| 37 |
|
| 38 |
foreach ($json as $index => $release) { |
| 39 |
foreach ($release->assets as $index2 => $asset) { |
| 40 |
$url = $asset->browser_download_url; |
| 41 |
$name = $asset->name; |
| 42 |
$thisVersion = $release->tag_name; |
| 43 |
|
| 44 |
if (strtoupper($searchName) == strtoupper($name)) { |
| 45 |
header('Content-Type: application/octet-stream'); |
| 46 |
header('Content-Disposition: attachment; filename="' . $name . '"'); |
| 47 |
readfile($url); |
| 48 |
exit; |
| 49 |
} |
| 50 |
$urls[] = [ |
| 51 |
'name' => $name, |
| 52 |
'url' => $url, |
| 53 |
'version' => $thisVersion, |
| 54 |
]; |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
if ($version === 'json') { |
| 60 |
header('Content-Type: application/json'); |
| 61 |
echo json_encode($urls); |
| 62 |
} else { |
| 63 |
|
| 64 |
foreach ($urls as $thisUrl) { |
| 65 |
printf("%s - <a href='%s' target='_blank'>%s</a><br />", $thisUrl['version'], $thisUrl['url'], $thisUrl['name']); |
| 66 |
} |
| 67 |
} |
| 68 |
|