Replace stats transformer with resource
This commit is contained in:
parent
032e4f2e31
commit
87a2fff3b7
5 changed files with 44 additions and 54 deletions
|
@ -2,40 +2,20 @@
|
|||
|
||||
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Illuminate\Cache\Repository;
|
||||
use Pterodactyl\Transformers\Api\Client\StatsTransformer;
|
||||
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
|
||||
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
|
||||
use Pterodactyl\Http\Requests\Api\Client\Servers\GetServerRequest;
|
||||
|
||||
class ResourceUtilizationController extends ClientApiController
|
||||
{
|
||||
/**
|
||||
* ResourceUtilizationController constructor.
|
||||
*/
|
||||
public function __construct(private Repository $cache, private DaemonServerRepository $repository)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current resource utilization for a server. This value is cached for up to
|
||||
* 20 seconds at a time to ensure that repeated requests to this endpoint do not cause
|
||||
* a flood of unnecessary API calls.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
||||
*/
|
||||
public function __invoke(GetServerRequest $request, Server $server): array
|
||||
{
|
||||
$key = "resources:$server->uuid";
|
||||
$stats = $this->cache->remember($key, Carbon::now()->addSeconds(20), function () use ($server) {
|
||||
return $this->repository->setServer($server)->getDetails();
|
||||
});
|
||||
|
||||
return $this->fractal->item($stats)
|
||||
->transformWith($this->getTransformer(StatsTransformer::class))
|
||||
->toArray();
|
||||
return $server->getStats();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue