mirror of
https://github.com/linuxserver/Heimdall-Apps.git
synced 2026-02-06 20:02:20 +08:00
55 lines
1.6 KiB
PHP
55 lines
1.6 KiB
PHP
<?php namespace App\SupportedApps\Octoprint;
|
|
|
|
use Carbon\Carbon;
|
|
|
|
class Octoprint 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
|
|
|
|
function __construct() {
|
|
}
|
|
|
|
public function test()
|
|
{
|
|
$attrs['headers'] = ['X-Api-Key' => $this->config->apikey];
|
|
$test = parent::appTest($this->url('api/version'), $attrs);
|
|
echo $test->status;
|
|
}
|
|
|
|
public function livestats()
|
|
{
|
|
$status = 'inactive';
|
|
$attrs['headers'] = ['X-Api-Key' => $this->config->apikey];
|
|
$res = parent::execute($this->url('api/job'), $attrs);
|
|
$details = json_decode($res->getBody());
|
|
|
|
$data = [];
|
|
|
|
$progress = $details->progress->completion;
|
|
|
|
$data['progress'] = @round($progress*100) ?? 0;
|
|
$seconds = $details->progress->printTimeLeft;
|
|
if($seconds === null) {
|
|
$data['estimated'] = 'N/A';
|
|
} elseif($seconds > 0) {
|
|
$data['estimated'] = Carbon::now()->addSeconds($seconds)->diffForHumans();
|
|
} else {
|
|
$data['estimated'] = 'N/A';
|
|
}
|
|
|
|
|
|
$status = ($data['progress'] < 100 && $progress !== null) ? 'active' : 'inactive';
|
|
|
|
return parent::getLiveStats($status, $data);
|
|
|
|
}
|
|
public function url($endpoint)
|
|
{
|
|
$api_url = parent::normaliseurl($this->config->url).$endpoint;
|
|
return $api_url;
|
|
}
|
|
}
|