Make server listing and single server view API endpoints work
This commit is contained in:
parent
74bdbea6a4
commit
a497a3d153
39 changed files with 367 additions and 176 deletions
71
app/Transformers/Api/Application/AllocationTransformer.php
Normal file
71
app/Transformers/Api/Application/AllocationTransformer.php
Normal file
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Transformers\Api\Application;
|
||||
|
||||
use Pterodactyl\Models\Allocation;
|
||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||
|
||||
class AllocationTransformer extends BaseTransformer
|
||||
{
|
||||
/**
|
||||
* Relationships that can be loaded onto allocation transformations.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $availableIncludes = ['node', 'server'];
|
||||
|
||||
/**
|
||||
* Return a generic transformed allocation array.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Allocation $allocation
|
||||
* @return array
|
||||
*/
|
||||
public function transform(Allocation $allocation)
|
||||
{
|
||||
return [
|
||||
'id' => $allocation->id,
|
||||
'ip' => $allocation->ip,
|
||||
'alias' => $allocation->ip_alias,
|
||||
'port' => $allocation->port,
|
||||
'assigned' => ! is_null($allocation->server_id),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the node relationship onto a given transformation.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Allocation $allocation
|
||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||
*/
|
||||
public function includeNode(Allocation $allocation)
|
||||
{
|
||||
if (! $this->authorize(AdminAcl::RESOURCE_NODES)) {
|
||||
return $this->null();
|
||||
}
|
||||
|
||||
$allocation->loadMissing('node');
|
||||
|
||||
return $this->item(
|
||||
$allocation->getRelation('node'), $this->makeTransformer(NodeTransformer::class), 'node'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the server relationship onto a given transformation.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Allocation $allocation
|
||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||
*/
|
||||
public function includeServer(Allocation $allocation)
|
||||
{
|
||||
if (! $this->authorize(AdminAcl::RESOURCE_SERVERS)) {
|
||||
return $this->null();
|
||||
}
|
||||
|
||||
$allocation->loadMissing('server');
|
||||
|
||||
return $this->item(
|
||||
$allocation->getRelation('server'), $this->makeTransformer(ServerTransformer::class), 'server'
|
||||
);
|
||||
}
|
||||
}
|
Reference in a new issue