1
0
mirror of https://github.com/thooge/esp32-nmea2000-obp60.git synced 2025-12-13 05:53:06 +01:00

handle artifact download correctly

This commit is contained in:
andreas
2023-09-04 19:45:12 +02:00
parent abf87f1955
commit 0709e92b6f
3 changed files with 192 additions and 89 deletions

View File

@@ -1,41 +1,51 @@
<?php
include("functions.php");
include("config.php");
$api="https://api.github.com/repos/#user#/#repo#/releases/latest";
$download="https://github.com/#user#/#repo#/releases/download/#dlVersion#/#dlName#";
$manifest="?dlName=#mName#&dlVersion=#mVersion#&user=#user#&repo=#repo#";
include("functions.php");
include("config.php");
$api = "https://api.github.com/repos/#user#/#repo#/releases/latest";
$download = "https://github.com/#user#/#repo#/releases/download/#dlVersion#/#dlName#";
$manifest = "?dlName=#mName#&dlVersion=#mVersion#&user=#user#&repo=#repo#";
try {
if (isset($_REQUEST['api'])) {
$vars=fillUserAndRepo();
proxy(replaceVars($api,$vars));
$vars = fillUserAndRepo();
proxy(replaceVars($api, $vars));
exit(0);
}
if (isset($_REQUEST['dlName'])){
$vars=fillUserAndRepo();
$vars=addVars($vars,array('dlName','dlVersion'));
proxy(replaceVars($download,$vars));
if (isset($_REQUEST['dlName'])) {
$vars = fillUserAndRepo();
$vars = addVars($vars, array('dlName', 'dlVersion'));
proxy(replaceVars($download, $vars));
exit(0);
}
if (isset($_REQUEST['flash'])){
$vars=fillUserAndRepo();
$json=getJson(replaceVars($api,$vars));
$assets=$json['assets'];
$targetUrl=null;
$targetBase=$_REQUEST['flash'];
$mode='all';
if (isset($_REQUEST['update'])) $mode='update';
$lb=strlen($targetBase);
foreach ($assets as &$asset){
if (substr($asset['name'],0,$lb) == $targetBase){
if (! preg_match("/-$mode.bin/",$asset['name'])) continue;
$targetUrl=$asset['browser_download_url'];
break;
}
if (isset($_REQUEST['flash'])) {
$vars = fillUserAndRepo();
$json = getJson(replaceVars($api, $vars));
$assets = $json['assets'];
$targetUrl = null;
$targetBase = $_REQUEST['flash'];
$mode = 'all';
if (isset($_REQUEST['update']))
$mode = 'update';
$lb = strlen($targetBase);
foreach ($assets as &$asset) {
if (substr($asset['name'], 0, $lb) == $targetBase) {
if (!preg_match("/-$mode.bin/", $asset['name']))
continue;
$targetUrl = $asset['browser_download_url'];
break;
}
}
if (! $targetUrl) die("unable to find $targetBase $mode\n");
if (!$targetUrl)
die("unable to find $targetBase $mode\n");
#echo("download for $targetBase=$targetUrl\n");
proxy($targetUrl);
exit(0);
}
die("invalid request");
?>
} catch (HTTPErrorException $h) {
header($_SERVER['SERVER_PROTOCOL'] . " " . $h->code . " " . $h->getMessage());
die($h->getMessage());
} catch (Exception $e) {
header($_SERVER['SERVER_PROTOCOL'] . ' 500 ' . $e->getMessage());
die($e->getMessage());
}
die("invalid request");
?>