Verified Commit fea75dbb authored by noplanman's avatar noplanman

Fetch and cache file data from bintray, rename/introduce env variables...

Fetch and cache file data from bintray, rename/introduce env variables BINTRAY_USERNAME and BINTRAY_API_KEY
parent bebd3504
<?php
$api_url = 'https://bauerj:' . getenv('API_KEY') . '@api.bintray.com/packages/borg-binary-builder/borg-binaries/borg-binaries/files';
$_files = file_get_contents($api_url);
$_files = json_decode($_files, false);
function get_bintray_files_cache($force = false)
{
$cache_file = '_cache/bintray-files.json';
$cache_time = 300;
$cache_expired = !file_exists($cache_file) || (time() - filemtime($cache_file) >= $cache_time);
if ($force || $cache_expired) {
$files_json = file_get_contents(sprintf(
'https://%s:%s@api.bintray.com/packages/borg-binary-builder/borg-binaries/borg-binaries/files',
getenv('BINTRAY_USERNAME'),
getenv('BINTRAY_API_KEY')
));
file_put_contents($cache_file, $files_json);
} else {
$files_json = file_get_contents($cache_file);
}
return json_decode($files_json, false);
}
function human_filesize($bytes, $decimals = 2)
{
......@@ -24,7 +42,7 @@ function get_dl_link($flavor, $version, $file = null)
}
$files = [];
foreach ($_files as $file) {
foreach (get_bintray_files_cache() as $file) {
$files[$file->name] = $file;
}
uasort($files, static function ($a, $b) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment