Skip to content

Commit d163378

Browse files
authored
Enhanced gotify (#759)
* Enhancing Gotify App(Need Testing) * Enhancing Gotify tested and working * Remove whitespaces
1 parent 95926bd commit d163378

File tree

4 files changed

+103
-1
lines changed

4 files changed

+103
-1
lines changed

Gotify/Gotify.php

+74
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,78 @@
44

55
class Gotify extends \App\SupportedApps implements \App\EnhancedApps
66
{
7+
public $config;
8+
9+
public function __construct()
10+
{
11+
}
12+
13+
public function test()
14+
{
15+
$attrs = $this->getAttrs();
16+
$test = parent::appTest($this->url("health"), $attrs);
17+
echo $test->status;
18+
}
19+
20+
public function livestats()
21+
{
22+
$status = "inactive";
23+
$data = [];
24+
$attrs = $this->getAttrs();
25+
26+
// Fetch applications
27+
$applicationsResponse = parent::execute($this->url("application"), $attrs);
28+
$applications = json_decode($applicationsResponse->getBody());
29+
30+
// Count applications
31+
if ($applications) {
32+
$data["applications"] = count($applications);
33+
} else {
34+
$data["applications"] = 0;
35+
}
36+
37+
// Fetch clients
38+
$clientsResponse = parent::execute($this->url("client"), $attrs);
39+
$clients = json_decode($clientsResponse->getBody());
40+
41+
// Count clients
42+
if ($clients) {
43+
$data["clients"] = count($clients);
44+
} else {
45+
$data["clients"] = 0;
46+
}
47+
48+
// Fetch messages
49+
$messagesResponse = parent::execute($this->url("message"), $attrs);
50+
$messages = json_decode($messagesResponse->getBody());
51+
52+
// Count messages
53+
if ($messages && isset($messages->messages)) {
54+
$data["messages"] = count($messages->messages);
55+
} else {
56+
$data["messages"] = 0;
57+
}
58+
59+
// Determine status based on data
60+
if ($data["applications"] > 0 || $data["clients"] > 0 || $data["messages"] > 0) {
61+
$status = "active";
62+
}
63+
64+
return parent::getLiveStats($status, $data);
65+
}
66+
67+
public function url($endpoint)
68+
{
69+
$api_url = parent::normaliseurl($this->config->url) . $endpoint;
70+
return $api_url;
71+
}
72+
private function getAttrs()
73+
{
74+
return [
75+
"headers" => [
76+
"Accept" => "application/json",
77+
"X-Gotify-Key" => $this->config->apikey
78+
],
79+
];
80+
}
781
}

Gotify/app.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"website": "https://gotify.net",
55
"license": "MIT License",
66
"description": "A self-hosted push notification service.",
7-
"enhanced": false,
7+
"enhanced": true,
88
"tile_background": "dark",
99
"icon": "gotify.png"
1010
}

Gotify/config.blade.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<h2>{{ __('app.apps.config') }} ({{ __('app.optional') }}) @include('items.enable')</h2>
2+
<div class="items">
3+
<div class="input">
4+
<label>{{ strtoupper(__('app.url')) }}</label>
5+
{!! Form::text('config[override_url]', isset($item) ? $item->getconfig()->override_url : null, ['placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control']) !!}
6+
</div>
7+
<div class="input">
8+
<label>{{ __('app.apps.apikey') }}</label>
9+
{!! Form::text('config[apikey]', isset($item) ? $item->getconfig()->apikey : null, ['placeholder' => __('app.apps.apikey'), 'data-config' => 'apikey', 'class' => 'form-control config-item']) !!}
10+
</div>
11+
<div class="input">
12+
<button style="margin-top: 32px;" class="btn test" id="test_config">Test</button>
13+
</div>
14+
</div>

Gotify/livestats.blade.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<ul class="livestats">
2+
<li>
3+
<span class="title">Apps</span>
4+
<strong>{!! $applications !!}</strong>
5+
</li>
6+
<li>
7+
<span class="title">Clients</span>
8+
<strong>{!! $clients !!}</strong>
9+
</li>
10+
<li>
11+
<span class="title">Messages</span>
12+
<strong>{!! $messages !!}</strong>
13+
</li>
14+
</ul>

0 commit comments

Comments
 (0)