api(application): v2 backport

This commit is contained in:
Matthew Penner 2022-12-14 17:05:46 -07:00
parent 4cd0bee231
commit 67bf3e342e
No known key found for this signature in database
172 changed files with 2922 additions and 1579 deletions

View file

@ -6,8 +6,9 @@ use Pterodactyl\Models\Location;
use League\Fractal\Resource\Collection;
use League\Fractal\Resource\NullResource;
use Pterodactyl\Services\Acl\Api\AdminAcl;
use Pterodactyl\Transformers\Api\Transformer;
class LocationTransformer extends BaseTransformer
class LocationTransformer extends Transformer
{
/**
* List of resources that can be included.
@ -25,37 +26,19 @@ class LocationTransformer extends BaseTransformer
/**
* Return a generic transformed location array.
*/
public function transform(Location $location): array
public function transform(Location $model): array
{
return [
'id' => $location->id,
'short' => $location->short,
'long' => $location->long,
$location->getUpdatedAtColumn() => $this->formatTimestamp($location->updated_at),
$location->getCreatedAtColumn() => $this->formatTimestamp($location->created_at),
'id' => $model->id,
'short' => $model->short,
'long' => $model->long,
'created_at' => self::formatTimestamp($model->created_at),
'updated_at' => self::formatTimestamp($model->updated_at),
];
}
/**
* Return the nodes associated with this location.
*
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
*/
public function includeServers(Location $location): Collection|NullResource
{
if (!$this->authorize(AdminAcl::RESOURCE_SERVERS)) {
return $this->null();
}
$location->loadMissing('servers');
return $this->collection($location->getRelation('servers'), $this->makeTransformer(ServerTransformer::class), 'server');
}
/**
* Return the nodes associated with this location.
*
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
*/
public function includeNodes(Location $location): Collection|NullResource
{
@ -63,8 +46,18 @@ class LocationTransformer extends BaseTransformer
return $this->null();
}
$location->loadMissing('nodes');
return $this->collection($location->nodes, new NodeTransformer());
}
return $this->collection($location->getRelation('nodes'), $this->makeTransformer(NodeTransformer::class), 'node');
/**
* Return the nodes associated with this location.
*/
public function includeServers(Location $location): Collection|NullResource
{
if (!$this->authorize(AdminAcl::RESOURCE_SERVERS)) {
return $this->null();
}
return $this->collection($location->servers, new ServerTransformer());
}
}