Added Sabnzbd support
This commit is contained in:
parent
b2dd3f803e
commit
758599804c
5 changed files with 88 additions and 1 deletions
|
@ -32,8 +32,9 @@ class Item extends Model
|
|||
'pFsense' => \App\SupportedApps\Pfsense::class,
|
||||
'Pihole' => \App\SupportedApps\Pihole::class,
|
||||
'Plex' => \App\SupportedApps\Plex::class,
|
||||
'UniFi' => \App\SupportedApps\Unifi::class,
|
||||
'Portainer' => \App\SupportedApps\Portainer::class,
|
||||
'UniFi' => \App\SupportedApps\Unifi::class,
|
||||
'Sabnzbd' => \App\SupportedApps\Sabnzbd::class,
|
||||
];
|
||||
}
|
||||
public static function supportedOptions()
|
||||
|
|
76
app/SupportedApps/Sabnzbd.php
Normal file
76
app/SupportedApps/Sabnzbd.php
Normal file
|
@ -0,0 +1,76 @@
|
|||
<?php namespace App\SupportedApps;
|
||||
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
class Sabnzbd implements Contracts\Applications, Contracts\Livestats {
|
||||
|
||||
public $config;
|
||||
|
||||
public function defaultColour()
|
||||
{
|
||||
return '#124019';
|
||||
}
|
||||
public function icon()
|
||||
{
|
||||
return 'supportedapps/sabnzbd.png';
|
||||
}
|
||||
public function configDetails()
|
||||
{
|
||||
return 'sabnzbd';
|
||||
}
|
||||
public function testConfig()
|
||||
{
|
||||
$res = $this->buildRequest('queue');
|
||||
switch($res->getStatusCode()) {
|
||||
case 200:
|
||||
echo 'Successfully connected to the API';
|
||||
break;
|
||||
case 401:
|
||||
echo 'Failed: Invalid credentials';
|
||||
break;
|
||||
case 404:
|
||||
echo 'Failed: Please make sure your URL is correct and that there is a trailing slash';
|
||||
break;
|
||||
default:
|
||||
echo 'Something went wrong... Code: '.$res->getStatusCode();
|
||||
break;
|
||||
}
|
||||
}
|
||||
public function executeConfig()
|
||||
{
|
||||
$output = '';
|
||||
$res = $this->buildRequest('queue');
|
||||
$data = json_decode($res->getBody());
|
||||
//$data->result->RemainingSizeMB = '10000000';
|
||||
//$data->result->DownloadRate = '100000000';
|
||||
$size = $data->queue->mbleft;
|
||||
$rate = $data->queue->kbpersec;
|
||||
$queue_size = format_bytes($size*1000*1000, false, ' <span>', '</span>');
|
||||
$current_speed = format_bytes($rate*1000, false, ' <span>');
|
||||
|
||||
if($size > 0 || $rate > 0) {
|
||||
$output = '
|
||||
<ul class="livestats">
|
||||
<li><span class="title">Queue</span><strong>'.$queue_size.'</strong></li>
|
||||
<li><span class="title">Speed</span><strong>'.$current_speed.'/s</span></strong></li>
|
||||
</ul>
|
||||
';
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
public function buildRequest($endpoint)
|
||||
{
|
||||
$config = $this->config;
|
||||
$url = $config->url;
|
||||
$apikey = $config->apikey;
|
||||
|
||||
$api_url = $url.'sabnzbd/api?output=json&apikey='.$apikey.'&mode='.$endpoint;
|
||||
|
||||
$client = new Client(['http_errors' => false]);
|
||||
$res = $client->request('GET', $api_url);
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -59,6 +59,7 @@ return [
|
|||
'apps.username' => 'Username',
|
||||
'apps.password' => 'Password',
|
||||
'apps.config' => 'Config',
|
||||
'apps.apikey' => 'Api Key',
|
||||
|
||||
'url' => 'Url',
|
||||
'title' => 'Title',
|
||||
|
|
9
resources/views/supportedapps/sabnzbd.blade.php
Normal file
9
resources/views/supportedapps/sabnzbd.blade.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<h2>{{ __('app.apps.config') }} ({{ __('app.optional') }})</h2>
|
||||
<div class="items">
|
||||
<input type="hidden" data-config="type" class="config-item" name="config[type]" value="\App\SupportedApps\Sabnzbd" />
|
||||
<div class="input">
|
||||
<label>{{ __('app.apps.apikey') }}</label>
|
||||
{!! Form::text('config[apikey]', null, array('placeholder' => __('app.apps.apikey'), 'data-config' => 'apikey', 'class' => 'form-control config-item')) !!}
|
||||
</div>
|
||||
<button id="test_config">Test</button>
|
||||
</div>
|
BIN
storage/app/public/supportedapps/sabnzbd.png
Normal file
BIN
storage/app/public/supportedapps/sabnzbd.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.8 KiB |
Loading…
Add table
Reference in a new issue