From 93a8701c0c33453da82cb48218d2def2a538206a Mon Sep 17 00:00:00 2001 From: GeiserX <9169332+GeiserX@users.noreply.github.com> Date: Thu, 3 Dec 2026 01:28:18 +0100 Subject: [PATCH] CashPilot: make the tile work with CashPilot's read-only key --- CashPilot/CashPilot.php | 32 +++++++++++++++++++++++++------- CashPilot/cashpilot.svg | 2 +- CashPilot/config.blade.php | 6 +++--- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/CashPilot/CashPilot.php b/CashPilot/CashPilot.php index 7f61b660f2..d971f00d84 100644 --- a/CashPilot/CashPilot.php +++ b/CashPilot/CashPilot.php @@ -9,15 +9,33 @@ class CashPilot extends \App\SupportedApps implements \App\EnhancedApps public function test() { $test = parent::appTest($this->url('api/earnings/summary'), $this->attrs()); + + // CashPilot answers 403 to its fleet key (CASHPILOT_API_KEY), which only + // enrolls workers and reads nothing. Say which key the tile needs. + if ($test->code === 403) { + echo 'Failed: use the read-only API key (CASHPILOT_READONLY_API_KEY)'; + return; + } + echo $test->status; } public function livestats() { $status = 'inactive'; - $data = []; + $data = [ + 'earnings' => '—', + 'running' => '—', + ]; $res = parent::execute($this->url('api/earnings/summary'), $this->attrs()); + + // execute() returns null when CashPilot cannot be reached, and a 401 or + // 403 body still decodes to an object. Only a 200 is an answer. + if ($res === null || $res->getStatusCode() !== 200) { + return parent::getLiveStats($status, $data); + } + $details = json_decode($res->getBody()); if ($details) { @@ -27,15 +45,15 @@ public function livestats() // is zero". has_readings is false on a fresh install and on one whose // collection has stopped, so a figure there would state a // measurement that was never taken. - $data['earnings'] = (isset($details->has_readings) && $details->has_readings) - ? '$' . number_format((float) ($details->total_adjusted ?? 0), 2) - : '—'; + if (isset($details->has_readings) && $details->has_readings) { + $data['earnings'] = '$' . number_format((float) ($details->total_adjusted ?? 0), 2); + } // active_services is null when the count could not be taken. Showing // 0 would read as "nothing is running" while containers are running. - $data['running'] = (isset($details->active_services) && $details->active_services !== null) - ? $details->active_services - : '—'; + if (isset($details->active_services)) { + $data['running'] = $details->active_services; + } } return parent::getLiveStats($status, $data); diff --git a/CashPilot/cashpilot.svg b/CashPilot/cashpilot.svg index 57ad584d40..126a7682ee 100644 --- a/CashPilot/cashpilot.svg +++ b/CashPilot/cashpilot.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/CashPilot/config.blade.php b/CashPilot/config.blade.php index 4f5a6c9c70..518d206cd0 100644 --- a/CashPilot/config.blade.php +++ b/CashPilot/config.blade.php @@ -2,11 +2,11 @@