Skip to content
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
53 changes: 52 additions & 1 deletion N8n/N8n.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,57 @@

namespace App\SupportedApps\N8n;

class N8n extends \App\SupportedApps
// use Barryvdh\Debugbar\Facades\Debugbar;
// Debugbar::info($data);

class N8n extends \App\SupportedApps implements \App\EnhancedApps
{
public $config;

public function __construct()
{
}

public function test()
{
$attrs = $this->getAttrs();
$test = parent::appTest($this->url("workflows"), $attrs);
echo $test->status;
}

public function livestats()
{
$status = "active";
$data = [];
$attrs = $this->getAttrs();

// Fetch workflows
$workflowsResponse = parent::execute($this->url("workflows"), $attrs);
$workflows = json_decode($workflowsResponse->getBody());

$data["workflows"] = count($workflows->data);

// Fetch active workflows
$activeResponse = parent::execute($this->url("workflows?active=true"), $attrs);
$active = json_decode($activeResponse->getBody());

$data["active"] = count($active->data);

return parent::getLiveStats($status, $data);
}

public function url($endpoint)
{
$api_url = parent::normaliseurl($this->config->url) . "api/v1/" . $endpoint;
return $api_url;
}
private function getAttrs()
{
return [
"headers" => [
"Accept" => "application/json",
"X-N8N-API-KEY" => $this->config->password
],
];
}
}
2 changes: 1 addition & 1 deletion N8n/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"website": "https://n8n.io",
"license": "Apache License 2.0",
"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.",
"enhanced": false,
"enhanced": true,
"tile_background": "light",
"icon": "n8n.svg"
}
25 changes: 25 additions & 0 deletions N8n/config.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<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') }}(<a href="https://docs.n8n.io/api/authentication/#create-an-api-key" target="_blank">help?</a>)</label>
{!! Form::input('password', 'config[password]', '',
['placeholder' => __('app.apps.apikey'),
'data-config' => 'password',
'class' => 'form-control config-item'
]) !!}
</div>

<div class="input">
<button style="margin-top: 32px;" class="btn test" id="test_config">Test</button>
</div>
</div>
10 changes: 10 additions & 0 deletions N8n/livestats.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<ul class="livestats">
<li>
<span class="title">Workflows</span>
<strong>{!! $workflows !!}</strong>
</li>
<li>
<span class="title">Active</span>
<strong>{!! $active !!}</strong>
</li>
</ul>