[Breaking] Return server allocations automatically as a relation object
This commit is contained in:
parent
5c18fd1f0c
commit
bfb28f949d
3 changed files with 26 additions and 13 deletions
|
@ -28,10 +28,12 @@ abstract class ClientApiController extends ApplicationApiController
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the parsed includes for this request.
|
* Returns the parsed includes for this request.
|
||||||
|
*
|
||||||
|
* @return string[]
|
||||||
*/
|
*/
|
||||||
protected function parseIncludes()
|
protected function parseIncludes()
|
||||||
{
|
{
|
||||||
$includes = $this->request->query('include');
|
$includes = $this->request->query('include') ?? [];
|
||||||
|
|
||||||
if (! is_string($includes)) {
|
if (! is_string($includes)) {
|
||||||
return $includes;
|
return $includes;
|
||||||
|
|
|
@ -24,13 +24,11 @@ class AllocationTransformer extends BaseClientTransformer
|
||||||
*/
|
*/
|
||||||
public function transform(Allocation $model)
|
public function transform(Allocation $model)
|
||||||
{
|
{
|
||||||
$model->loadMissing('server');
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'ip' => $model->ip,
|
'ip' => $model->ip,
|
||||||
'alias' => $model->ip_alias,
|
'ip_alias' => $model->ip_alias,
|
||||||
'port' => $model->port,
|
'port' => $model->port,
|
||||||
'default' => $model->getRelation('server')->allocation_id === $model->id,
|
'is_default' => $model->server->allocation_id === $model->id,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,11 @@ use Pterodactyl\Models\Allocation;
|
||||||
|
|
||||||
class ServerTransformer extends BaseClientTransformer
|
class ServerTransformer extends BaseClientTransformer
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var string[]
|
||||||
|
*/
|
||||||
|
protected $defaultIncludes = ['allocations'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
|
@ -42,14 +47,6 @@ class ServerTransformer extends BaseClientTransformer
|
||||||
'port' => $server->node->daemonSFTP,
|
'port' => $server->node->daemonSFTP,
|
||||||
],
|
],
|
||||||
'description' => $server->description,
|
'description' => $server->description,
|
||||||
'allocations' => $server->allocations->map(function (Allocation $allocation) use ($server) {
|
|
||||||
return [
|
|
||||||
'ip' => $allocation->ip,
|
|
||||||
'ip_alias' => $allocation->ip_alias,
|
|
||||||
'port' => $allocation->port,
|
|
||||||
'is_default' => $allocation->id === $server->allocation_id,
|
|
||||||
];
|
|
||||||
}),
|
|
||||||
'limits' => [
|
'limits' => [
|
||||||
'memory' => $server->memory,
|
'memory' => $server->memory,
|
||||||
'swap' => $server->swap,
|
'swap' => $server->swap,
|
||||||
|
@ -67,6 +64,22 @@ class ServerTransformer extends BaseClientTransformer
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the allocations associated with this server.
|
||||||
|
*
|
||||||
|
* @param \Pterodactyl\Models\Server $server
|
||||||
|
* @return \League\Fractal\Resource\Collection
|
||||||
|
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||||
|
*/
|
||||||
|
public function includeAllocations(Server $server)
|
||||||
|
{
|
||||||
|
return $this->collection(
|
||||||
|
$server->allocations,
|
||||||
|
$this->makeTransformer(AllocationTransformer::class),
|
||||||
|
Allocation::RESOURCE_NAME
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the egg associated with this server.
|
* Returns the egg associated with this server.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue