Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced gotify #759

Merged
merged 4 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions Gotify/Gotify.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,78 @@

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
],
];
}
}
2 changes: 1 addition & 1 deletion Gotify/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
14 changes: 14 additions & 0 deletions Gotify/config.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<h2>{{ __('app.apps.config') }} ({{ __('app.optional') }}) @include('items.enable')</h2>
<div class="items">
<div class="input">
<label>{{ strtoupper(__('app.url')) }}</label>
{!! Form::text('config[override_url]', isset($item) ? $item->getconfig()->override_url : null, ['placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control']) !!}
</div>
<div class="input">
<label>{{ __('app.apps.apikey') }}</label>
{!! Form::text('config[apikey]', isset($item) ? $item->getconfig()->apikey : null, ['placeholder' => __('app.apps.apikey'), 'data-config' => 'apikey', 'class' => 'form-control config-item']) !!}
</div>
<div class="input">
<button style="margin-top: 32px;" class="btn test" id="test_config">Test</button>
</div>
</div>
14 changes: 14 additions & 0 deletions Gotify/livestats.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<ul class="livestats">
<li>
<span class="title">Apps</span>
<strong>{!! $applications !!}</strong>
</li>
<li>
<span class="title">Clients</span>
<strong>{!! $clients !!}</strong>
</li>
<li>
<span class="title">Messages</span>
<strong>{!! $messages !!}</strong>
</li>
</ul>