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

@ -12,9 +12,10 @@ use Illuminate\Container\Container;
use Pterodactyl\Models\EggVariable;
use League\Fractal\Resource\Collection;
use League\Fractal\Resource\NullResource;
use Pterodactyl\Transformers\Api\Transformer;
use Pterodactyl\Services\Servers\StartupCommandService;
class ServerTransformer extends BaseClientTransformer
class ServerTransformer extends Transformer
{
protected array $defaultIncludes = ['allocations', 'variables'];
@ -67,22 +68,16 @@ class ServerTransformer extends BaseClientTransformer
'backups' => $server->backup_limit,
],
'status' => $server->status,
// This field is deprecated, please use "status".
'is_suspended' => $server->isSuspended(),
// This field is deprecated, please use "status".
'is_installing' => !$server->isInstalled(),
'is_transferring' => !is_null($server->transfer),
];
}
/**
* Returns the allocations associated with this server.
*
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
*/
public function includeAllocations(Server $server): Collection
{
$transformer = $this->makeTransformer(AllocationTransformer::class);
$transformer = new AllocationTransformer();
$user = $this->request->user();
// While we include this permission, we do need to actually handle it slightly different here
@ -96,42 +91,31 @@ class ServerTransformer extends BaseClientTransformer
$primary = clone $server->allocation;
$primary->notes = null;
return $this->collection([$primary], $transformer, Allocation::RESOURCE_NAME);
return $this->collection([$primary], $transformer);
}
return $this->collection($server->allocations, $transformer, Allocation::RESOURCE_NAME);
return $this->collection($server->allocations, $transformer);
}
/**
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
*/
public function includeVariables(Server $server): Collection|NullResource
{
if (!$this->request->user()->can(Permission::ACTION_STARTUP_READ, $server)) {
return $this->null();
}
return $this->collection(
$server->variables->where('user_viewable', true),
$this->makeTransformer(EggVariableTransformer::class),
EggVariable::RESOURCE_NAME
);
return $this->collection($server->variables->where('user_viewable', true), new EggVariableTransformer());
}
/**
* Returns the egg associated with this server.
*
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
*/
public function includeEgg(Server $server): Item
{
return $this->item($server->egg, $this->makeTransformer(EggTransformer::class), Egg::RESOURCE_NAME);
return $this->item($server->egg, new EggTransformer());
}
/**
* Returns the subusers associated with this server.
*
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
*/
public function includeSubusers(Server $server): Collection|NullResource
{
@ -139,6 +123,6 @@ class ServerTransformer extends BaseClientTransformer
return $this->null();
}
return $this->collection($server->subusers, $this->makeTransformer(SubuserTransformer::class), Subuser::RESOURCE_NAME);
return $this->collection($server->subusers, new SubuserTransformer());
}
}