api(application): v2 backport
This commit is contained in:
parent
4cd0bee231
commit
67bf3e342e
172 changed files with 2922 additions and 1579 deletions
|
@ -7,8 +7,9 @@ use League\Fractal\Resource\Item;
|
|||
use League\Fractal\Resource\Collection;
|
||||
use League\Fractal\Resource\NullResource;
|
||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||
use Pterodactyl\Transformers\Api\Transformer;
|
||||
|
||||
class NodeTransformer extends BaseTransformer
|
||||
class NodeTransformer extends Transformer
|
||||
{
|
||||
/**
|
||||
* List of resources that can be included.
|
||||
|
@ -27,9 +28,9 @@ class NodeTransformer extends BaseTransformer
|
|||
* Return a node transformed into a format that can be consumed by the
|
||||
* external administrative API.
|
||||
*/
|
||||
public function transform(Node $node): array
|
||||
public function transform(Node $model): array
|
||||
{
|
||||
$response = collect($node->toArray())->mapWithKeys(function ($value, $key) {
|
||||
$response = collect($model->toArray())->mapWithKeys(function ($value, $key) {
|
||||
// I messed up early in 2016 when I named this column as poorly
|
||||
// as I did. This is the tragic result of my mistakes.
|
||||
$key = ($key === 'daemonSFTP') ? 'daemonSftp' : $key;
|
||||
|
@ -37,10 +38,10 @@ class NodeTransformer extends BaseTransformer
|
|||
return [snake_case($key) => $value];
|
||||
})->toArray();
|
||||
|
||||
$response[$node->getUpdatedAtColumn()] = $this->formatTimestamp($node->updated_at);
|
||||
$response[$node->getCreatedAtColumn()] = $this->formatTimestamp($node->created_at);
|
||||
$response['created_at'] = self::formatTimestamp($model->created_at);
|
||||
$response['updated_at'] = self::formatTimestamp($model->updated_at);
|
||||
|
||||
$resources = $node->servers()->select(['memory', 'disk'])->get();
|
||||
$resources = $model->servers()->select(['memory', 'disk'])->get();
|
||||
|
||||
$response['allocated_resources'] = [
|
||||
'memory' => $resources->sum('memory'),
|
||||
|
@ -51,9 +52,7 @@ class NodeTransformer extends BaseTransformer
|
|||
}
|
||||
|
||||
/**
|
||||
* Return the nodes associated with this location.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
* Return the allocations associated with this node.
|
||||
*/
|
||||
public function includeAllocations(Node $node): Collection|NullResource
|
||||
{
|
||||
|
@ -61,19 +60,11 @@ class NodeTransformer extends BaseTransformer
|
|||
return $this->null();
|
||||
}
|
||||
|
||||
$node->loadMissing('allocations');
|
||||
|
||||
return $this->collection(
|
||||
$node->getRelation('allocations'),
|
||||
$this->makeTransformer(AllocationTransformer::class),
|
||||
'allocation'
|
||||
);
|
||||
return $this->collection($node->allocations, new AllocationTransformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the nodes associated with this location.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
* Return the location associated with this node.
|
||||
*/
|
||||
public function includeLocation(Node $node): Item|NullResource
|
||||
{
|
||||
|
@ -81,19 +72,11 @@ class NodeTransformer extends BaseTransformer
|
|||
return $this->null();
|
||||
}
|
||||
|
||||
$node->loadMissing('location');
|
||||
|
||||
return $this->item(
|
||||
$node->getRelation('location'),
|
||||
$this->makeTransformer(LocationTransformer::class),
|
||||
'location'
|
||||
);
|
||||
return $this->item($node->location, new LocationTransformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the nodes associated with this location.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
* Return the servers associated with this node.
|
||||
*/
|
||||
public function includeServers(Node $node): Collection|NullResource
|
||||
{
|
||||
|
@ -101,12 +84,6 @@ class NodeTransformer extends BaseTransformer
|
|||
return $this->null();
|
||||
}
|
||||
|
||||
$node->loadMissing('servers');
|
||||
|
||||
return $this->collection(
|
||||
$node->getRelation('servers'),
|
||||
$this->makeTransformer(ServerTransformer::class),
|
||||
'server'
|
||||
);
|
||||
return $this->collection($node->servers, new ServerTransformer());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue