including some more dashboard components
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace App\SupportedApps\FileBrowser;
|
||||
|
||||
class FileBrowser extends \App\SupportedApps implements \App\EnhancedApps
|
||||
{
|
||||
public $config;
|
||||
|
||||
//protected $login_first = true; // Uncomment if api requests need to be authed first
|
||||
//protected $method = 'POST'; // Uncomment if requests to the API should be set by POST
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
//$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set
|
||||
}
|
||||
|
||||
private function getToken()
|
||||
{
|
||||
$username = $this->config->username;
|
||||
$password = $this->config->password;
|
||||
$authHeader = $this->config->authHeader;
|
||||
|
||||
$attrs = [
|
||||
"headers" => [
|
||||
"Content-Type" => "application/json"
|
||||
],
|
||||
"body" => json_encode([
|
||||
"username" => $username,
|
||||
"password" => $password
|
||||
])
|
||||
];
|
||||
if ($authHeader !== null) {
|
||||
$attrs["headers"][$authHeader] = $username;
|
||||
}
|
||||
|
||||
$res = parent::execute($this->url("api/login"), $attrs, null, "POST");
|
||||
|
||||
switch ($res->getStatusCode()) {
|
||||
case 200:
|
||||
return $res->getBody()->getContents();
|
||||
case 403:
|
||||
throw new \Exception("Invalid username/password");
|
||||
default:
|
||||
throw new \Exception("Could not connect to FileBrowser");
|
||||
}
|
||||
}
|
||||
|
||||
private function formatBytes($bytes, $precision = 2) {
|
||||
$units = array('B', 'KB', 'MB', 'GB', 'TB');
|
||||
$bytes = max($bytes, 0);
|
||||
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
|
||||
$pow = min($pow, count($units) - 1);
|
||||
|
||||
$bytes /= pow(1024, $pow);
|
||||
|
||||
$value = round($bytes, $precision);
|
||||
$unit = $units[$pow];
|
||||
|
||||
return [
|
||||
"value" => $value,
|
||||
"unit" => $unit
|
||||
];
|
||||
}
|
||||
|
||||
public function test()
|
||||
{
|
||||
try {
|
||||
$token = $this->getToken();
|
||||
echo "Successfully communicated with the API";
|
||||
} catch (Exception $err) {
|
||||
echo $err->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public function livestats()
|
||||
{
|
||||
$status = "inactive";
|
||||
|
||||
$token = $this->getToken();
|
||||
$attrs = [
|
||||
"headers" => [
|
||||
"X-AUTH" => $token
|
||||
],
|
||||
];
|
||||
$res = parent::execute($this->url("api/usage"), $attrs);
|
||||
$details = json_decode($res->getBody());
|
||||
|
||||
if ($details != null) {
|
||||
$data["used"] = $this->formatBytes($details->used);
|
||||
$data["total"] = $this->formatBytes($details->total);
|
||||
}
|
||||
return parent::getLiveStats($status, $data);
|
||||
}
|
||||
|
||||
public function url($endpoint)
|
||||
{
|
||||
$api_url = parent::normaliseurl($this->config->url) . $endpoint;
|
||||
|
||||
return $api_url;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"appid": "ba05dd8e070851895ee6184eb9778cfa0753a490",
|
||||
"name": "FileBrowser",
|
||||
"website": "https://github.com/filebrowser/filebrowser",
|
||||
"license": "Apache License 2.0",
|
||||
"description": "filebrowser provides a file managing interface within a specified directory and it can be used to upload, delete, preview, rename and edit your files. It allows the creation of multiple users and each user can have its own directory. It can be used as a standalone app or as a middleware.",
|
||||
"enhanced": true,
|
||||
"tile_background": "dark",
|
||||
"icon": "filebrowser.svg"
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<h2>{{ __('app.apps.config') }} ({{ __('app.optional') }}) @include('items.enable')</h2>
|
||||
<div class="items" style="flex-direction:column">
|
||||
<div style="display:flex;flex-direction:row;">
|
||||
<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>
|
||||
<div style="display:flex;flex-direction:row;">
|
||||
<div class="input">
|
||||
<label>{{ __('app.apps.username') }}</label>
|
||||
{!! Form::text('config[username]', isset($item) ? $item->getconfig()->username : null, ['placeholder' => __('app.apps.username'), 'data-config' => 'username', 'class' => 'form-control config-item']) !!}
|
||||
</div>
|
||||
<div class="input">
|
||||
<label>{{ __('app.apps.password') }}</label>
|
||||
{!! Form::input('password', 'config[password]', '', ['placeholder' => __('app.apps.password'), 'data-config' => 'password', 'class' => 'form-control config-item']) !!}
|
||||
</div>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:row;">
|
||||
<div class="input">
|
||||
<label>Proxy Header (<a href="https://filebrowser.org/configuration/authentication-method#proxy-header" target="_blank">help?</a>)</label>
|
||||
{!! Form::text('config[authHeader]', isset($item) ? $item->getconfig()->authHeader : null, ['placeholder' => 'X-My-Header', 'data-config' => 'authHeader', 'class' => 'form-control config-item']) !!}
|
||||
<small>Also fill {{ __('app.apps.username') }}</small>
|
||||
</div>
|
||||
</div>
|
||||
<div class="input">
|
||||
<button style="margin-top: 32px;" class="btn test" id="test_config">Test</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,10 @@
|
||||
<ul class="livestats">
|
||||
<li>
|
||||
<span class="title">Used</span>
|
||||
<strong>{!! $used["value"] !!}<span>{!! $used["unit"] !!}</span></strong>
|
||||
</li>
|
||||
<li>
|
||||
<span class="title">Total</span>
|
||||
<strong>{!! $total["value"] !!}<span>{!! $total["unit"] !!}</span></strong>
|
||||
</li>
|
||||
</ul>
|
||||
Reference in New Issue
Block a user