mirror of
https://github.com/linuxserver/Heimdall-Apps.git
synced 2026-01-20 20:02:12 +08:00
* Immich: display large numbers with suffixes Because an app plate is quite small, displaying large numbers can be problematic as they collide and cannot be distinguished. This commit fixes this issue by displaying large numbers using fewer characters and ISO suffixes, up to G (giga, 10^9). Here is an example of the problematic behaviour: +-----------------------+ | PHOTOS VIDEOS USAGE | | 14398443 0.94GiB | +-----------------------+ The 14,398 photo count collides with the 443 video count. This commit changes the display to: +-----------------------+ | PHOTOS VIDEOS USAGE | | 15k 443 0.94GiB | +-----------------------+ * fixup! Immich: display large numbers with suffixes
73 lines
2.1 KiB
PHP
73 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\SupportedApps\Immich;
|
|
|
|
class Immich extends \App\SupportedApps implements \App\EnhancedApps
|
|
{
|
|
public $config;
|
|
|
|
//protected $login_first = true; // Uncomment if api requests need to be authed first
|
|
//protected $method = 'POST'; // Uncomment if requests to the API should be set by POST
|
|
|
|
public function __construct()
|
|
{
|
|
//$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set
|
|
}
|
|
|
|
public function test()
|
|
{
|
|
$attrs = [
|
|
"headers" => [
|
|
"Accept" => "application/json",
|
|
"x-api-key" => $this->config->api_key,
|
|
],
|
|
];
|
|
$test = parent::appTest($this->url("server/statistics"), $attrs);
|
|
echo $test->status;
|
|
}
|
|
|
|
private function formatLargeNumber($number)
|
|
{
|
|
$suffixes = [ "", "k", "M", "G" ];
|
|
$rank = 0;
|
|
while (abs($number) > 1000 && $rank < count($suffixes)) {
|
|
$number /= 1000;
|
|
$rank++;
|
|
}
|
|
$decimals = $number < 10 && $rank > 0 ? 1 : 0;
|
|
return number_format($number, $decimals) . $suffixes[$rank];
|
|
}
|
|
|
|
public function livestats()
|
|
{
|
|
$status = "inactive";
|
|
$attrs = [
|
|
"headers" => [
|
|
"Accept" => "application/json",
|
|
"x-api-key" => $this->config->api_key,
|
|
],
|
|
];
|
|
$res = parent::execute($this->url("server/statistics"), $attrs);
|
|
$details = json_decode($res->getBody());
|
|
|
|
$data = [];
|
|
|
|
if ($details) {
|
|
$status = "active";
|
|
$data["photos"] = $this->formatLargeNumber($details->photos);
|
|
$data["videos"] = $this->formatLargeNumber($details->videos);
|
|
$usageInGiB = number_format($details->usage / 1073741824, 2);
|
|
$data["usage"] = $usageInGiB . 'GiB';
|
|
}
|
|
|
|
return parent::getLiveStats($status, $data);
|
|
}
|
|
public function url($endpoint)
|
|
{
|
|
$api_url = parent::normaliseurl($this->config->url) .
|
|
"api/" .
|
|
$endpoint;
|
|
return $api_url;
|
|
}
|
|
}
|