Skip to content

Commit 3eed80d

Browse files
committed
N8n enhanced version
1 parent d3ab2ff commit 3eed80d

File tree

4 files changed

+88
-2
lines changed

4 files changed

+88
-2
lines changed

N8n/N8n.php

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,57 @@
22

33
namespace App\SupportedApps\N8n;
44

5-
class N8n extends \App\SupportedApps
5+
// use Barryvdh\Debugbar\Facades\Debugbar;
6+
// Debugbar::info($data);
7+
8+
class N8n extends \App\SupportedApps implements \App\EnhancedApps
69
{
10+
public $config;
11+
12+
public function __construct()
13+
{
14+
}
15+
16+
public function test()
17+
{
18+
$attrs = $this->getAttrs();
19+
$test = parent::appTest($this->url("workflows"), $attrs);
20+
echo $test->status;
21+
}
22+
23+
public function livestats()
24+
{
25+
$status = "active";
26+
$data = [];
27+
$attrs = $this->getAttrs();
28+
29+
// Fetch workflows
30+
$workflowsResponse = parent::execute($this->url("workflows"), $attrs);
31+
$workflows = json_decode($workflowsResponse->getBody());
32+
33+
$data["workflows"] = count($workflows->data);
34+
35+
// Fetch active workflows
36+
$activeResponse = parent::execute($this->url("workflows?active=true"), $attrs);
37+
$active = json_decode($activeResponse->getBody());
38+
39+
$data["active"] = count($active->data);
40+
41+
return parent::getLiveStats($status, $data);
42+
}
43+
44+
public function url($endpoint)
45+
{
46+
$api_url = parent::normaliseurl($this->config->url) . "api/v1/" . $endpoint;
47+
return $api_url;
48+
}
49+
private function getAttrs()
50+
{
51+
return [
52+
"headers" => [
53+
"Accept" => "application/json",
54+
"X-N8N-API-KEY" => $this->config->password
55+
],
56+
];
57+
}
758
}

N8n/app.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"website": "https://n8n.io",
55
"license": "Apache License 2.0",
66
"description": "n8n is an extendable workflow automation tool. With a fair-code distribution model, n8n will always have visible source code, be available to self-host, and allow you to add your own custom functions, logic and apps. n8n's node-based approach makes it highly versatile, enabling you to connect anything to everything.",
7-
"enhanced": false,
7+
"enhanced": true,
88
"tile_background": "light",
99
"icon": "n8n.svg"
1010
}

N8n/config.blade.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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]',
6+
isset($item) ? $item->getconfig()->override_url : null,
7+
['placeholder' => __('app.apps.override'),
8+
'id' => 'override_url',
9+
'class' => 'form-control'
10+
]) !!}
11+
</div>
12+
13+
<div class="input">
14+
<label>{{ __('app.apps.apikey') }}(<a href="https://docs.n8n.io/api/authentication/#create-an-api-key" target="_blank">help?</a>)</label>
15+
{!! Form::input('password', 'config[password]', '',
16+
['placeholder' => __('app.apps.apikey'),
17+
'data-config' => 'password',
18+
'class' => 'form-control config-item'
19+
]) !!}
20+
</div>
21+
22+
<div class="input">
23+
<button style="margin-top: 32px;" class="btn test" id="test_config">Test</button>
24+
</div>
25+
</div>

N8n/livestats.blade.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<ul class="livestats">
2+
<li>
3+
<span class="title">Workflows</span>
4+
<strong>{!! $workflows !!}</strong>
5+
</li>
6+
<li>
7+
<span class="title">Active</span>
8+
<strong>{!! $active !!}</strong>
9+
</li>
10+
</ul>

0 commit comments

Comments
 (0)