From c1708495806db98bf84706ed8d5b4e93656df56e Mon Sep 17 00:00:00 2001 From: PedroBuffon Date: Sat, 13 Jul 2024 09:34:12 -0300 Subject: [PATCH] Enhanced gotify (#756) * Enhancing Gotify App(Need Testing) * Enhancing Gotify tested and working * Remove whitespaces --- Gotify/Gotify.php | 76 +++++++++++++++++++++++++++++++++++++- Gotify/app.json | 2 +- Gotify/config.blade.php | 14 +++++++ Gotify/livestats.blade.php | 14 +++++++ 4 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 Gotify/config.blade.php create mode 100644 Gotify/livestats.blade.php diff --git a/Gotify/Gotify.php b/Gotify/Gotify.php index f89f1444dd..e07181b5c1 100644 --- a/Gotify/Gotify.php +++ b/Gotify/Gotify.php @@ -2,6 +2,80 @@ namespace App\SupportedApps\Gotify; -class Gotify extends \App\SupportedApps +class Gotify extends \App\SupportedApps implements \App\EnhancedApps { + public $config; + + public function __construct() + { + } + + public function test() + { + $attrs = $this->getAttrs(); + $test = parent::appTest($this->url("health"), $attrs); + echo $test->status; + } + + public function livestats() + { + $status = "inactive"; + $data = []; + $attrs = $this->getAttrs(); + + // Fetch applications + $applicationsResponse = parent::execute($this->url("application"), $attrs); + $applications = json_decode($applicationsResponse->getBody()); + + // Count applications + if ($applications) { + $data["applications"] = count($applications); + } else { + $data["applications"] = 0; + } + + // Fetch clients + $clientsResponse = parent::execute($this->url("client"), $attrs); + $clients = json_decode($clientsResponse->getBody()); + + // Count clients + if ($clients) { + $data["clients"] = count($clients); + } else { + $data["clients"] = 0; + } + + // Fetch messages + $messagesResponse = parent::execute($this->url("message"), $attrs); + $messages = json_decode($messagesResponse->getBody()); + + // Count messages + if ($messages && isset($messages->messages)) { + $data["messages"] = count($messages->messages); + } else { + $data["messages"] = 0; + } + + // Determine status based on data + if ($data["applications"] > 0 || $data["clients"] > 0 || $data["messages"] > 0) { + $status = "active"; + } + + return parent::getLiveStats($status, $data); + } + + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } + private function getAttrs() + { + return [ + "headers" => [ + "Accept" => "application/json", + "X-Gotify-Key" => $this->config->apikey + ], + ]; + } } diff --git a/Gotify/app.json b/Gotify/app.json index 3915b6f3fb..04c632383f 100644 --- a/Gotify/app.json +++ b/Gotify/app.json @@ -4,7 +4,7 @@ "website": "https://gotify.net", "license": "MIT License", "description": "A self-hosted push notification service.", - "enhanced": false, + "enhanced": true, "tile_background": "dark", "icon": "gotify.png" } diff --git a/Gotify/config.blade.php b/Gotify/config.blade.php new file mode 100644 index 0000000000..4a8082c945 --- /dev/null +++ b/Gotify/config.blade.php @@ -0,0 +1,14 @@ +

{{ __('app.apps.config') }} ({{ __('app.optional') }}) @include('items.enable')

+
+
+ + {!! Form::text('config[override_url]', isset($item) ? $item->getconfig()->override_url : null, ['placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control']) !!} +
+
+ + {!! Form::text('config[apikey]', isset($item) ? $item->getconfig()->apikey : null, ['placeholder' => __('app.apps.apikey'), 'data-config' => 'apikey', 'class' => 'form-control config-item']) !!} +
+
+ +
+
diff --git a/Gotify/livestats.blade.php b/Gotify/livestats.blade.php new file mode 100644 index 0000000000..77df438e86 --- /dev/null +++ b/Gotify/livestats.blade.php @@ -0,0 +1,14 @@ +