Cleanup code, add basic functionality for Nests
This commit is contained in:
parent
6c85be72fa
commit
88ac1ce1fd
37 changed files with 331 additions and 159 deletions
|
@ -19,15 +19,15 @@ class AdminRoleTransformer extends BaseTransformer
|
|||
/**
|
||||
* Return a transformed User model that can be consumed by external services.
|
||||
*
|
||||
* @param \Pterodactyl\Models\AdminRole $role
|
||||
* @param \Pterodactyl\Models\AdminRole $model
|
||||
* @return array
|
||||
*/
|
||||
public function transform(AdminRole $role): array
|
||||
public function transform(AdminRole $model): array
|
||||
{
|
||||
return [
|
||||
'id' => $role->id,
|
||||
'name' => $role->name,
|
||||
'description' => $role->description,
|
||||
'id' => $model->id,
|
||||
'name' => $model->name,
|
||||
'description' => $model->description,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,18 +29,19 @@ class AllocationTransformer extends BaseTransformer
|
|||
/**
|
||||
* Return a generic transformed allocation array.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Allocation $allocation
|
||||
* @param \Pterodactyl\Models\Allocation $model
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function transform(Allocation $allocation)
|
||||
public function transform(Allocation $model)
|
||||
{
|
||||
return [
|
||||
'id' => $allocation->id,
|
||||
'ip' => $allocation->ip,
|
||||
'alias' => $allocation->ip_alias,
|
||||
'port' => $allocation->port,
|
||||
'notes' => $allocation->notes,
|
||||
'assigned' => ! is_null($allocation->server_id),
|
||||
'id' => $model->id,
|
||||
'ip' => $model->ip,
|
||||
'alias' => $model->ip_alias,
|
||||
'port' => $model->port,
|
||||
'notes' => $model->notes,
|
||||
'assigned' => ! is_null($model->server_id),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -48,8 +49,10 @@ class AllocationTransformer extends BaseTransformer
|
|||
* Load the node relationship onto a given transformation.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Allocation $allocation
|
||||
*
|
||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function includeNode(Allocation $allocation)
|
||||
{
|
||||
|
@ -66,8 +69,10 @@ class AllocationTransformer extends BaseTransformer
|
|||
* Load the server relationship onto a given transformation.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Allocation $allocation
|
||||
*
|
||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function includeServer(Allocation $allocation)
|
||||
{
|
||||
|
|
|
@ -44,6 +44,7 @@ abstract class BaseTransformer extends TransformerAbstract
|
|||
* Set the HTTP request class being used for this request.
|
||||
*
|
||||
* @param \Pterodactyl\Models\ApiKey $key
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setKey(ApiKey $key)
|
||||
|
@ -69,6 +70,7 @@ abstract class BaseTransformer extends TransformerAbstract
|
|||
* models on a transformation request.
|
||||
*
|
||||
* @param string $resource
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize(string $resource): bool
|
||||
|
@ -82,8 +84,10 @@ abstract class BaseTransformer extends TransformerAbstract
|
|||
*
|
||||
* @param string $abstract
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return \Pterodactyl\Transformers\Api\Application\BaseTransformer
|
||||
*
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
protected function makeTransformer(string $abstract, array $parameters = [])
|
||||
|
@ -103,6 +107,7 @@ abstract class BaseTransformer extends TransformerAbstract
|
|||
* Return an ISO-8601 formatted timestamp to use in the API response.
|
||||
*
|
||||
* @param string $timestamp
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function formatTimestamp(string $timestamp): string
|
||||
|
|
|
@ -30,6 +30,7 @@ class DatabaseHostTransformer extends BaseTransformer
|
|||
* Transform database host into a representation for the application API.
|
||||
*
|
||||
* @param \Pterodactyl\Models\DatabaseHost $model
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function transform(DatabaseHost $model)
|
||||
|
@ -54,6 +55,7 @@ class DatabaseHostTransformer extends BaseTransformer
|
|||
* Include the databases associated with this host.
|
||||
*
|
||||
* @param \Pterodactyl\Models\DatabaseHost $model
|
||||
*
|
||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
|
|
|
@ -34,6 +34,7 @@ class EggTransformer extends BaseTransformer
|
|||
* the application api.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Egg $model
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function transform(Egg $model)
|
||||
|
@ -74,8 +75,10 @@ class EggTransformer extends BaseTransformer
|
|||
* Include the Nest relationship for the given Egg in the transformation.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Egg $model
|
||||
*
|
||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function includeNest(Egg $model)
|
||||
{
|
||||
|
@ -92,8 +95,10 @@ class EggTransformer extends BaseTransformer
|
|||
* Include the Servers relationship for the given Egg in the transformation.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Egg $model
|
||||
*
|
||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function includeServers(Egg $model)
|
||||
{
|
||||
|
@ -111,6 +116,7 @@ class EggTransformer extends BaseTransformer
|
|||
* extending another.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Egg $model
|
||||
*
|
||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||
*/
|
||||
public function includeConfig(Egg $model)
|
||||
|
@ -136,6 +142,7 @@ class EggTransformer extends BaseTransformer
|
|||
* Egg is extending another.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Egg $model
|
||||
*
|
||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||
*/
|
||||
public function includeScript(Egg $model)
|
||||
|
@ -160,8 +167,10 @@ class EggTransformer extends BaseTransformer
|
|||
* Include the variables that are defined for this Egg.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Egg $model
|
||||
*
|
||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function includeVariables(Egg $model)
|
||||
{
|
||||
|
|
|
@ -27,17 +27,17 @@ class LocationTransformer extends BaseTransformer
|
|||
/**
|
||||
* Return a generic transformed location array.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Location $location
|
||||
* @param \Pterodactyl\Models\Location $model
|
||||
* @return 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,
|
||||
$model->getUpdatedAtColumn() => $this->formatTimestamp($model->updated_at),
|
||||
$model->getCreatedAtColumn() => $this->formatTimestamp($model->created_at),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -28,12 +28,13 @@ class NodeTransformer extends BaseTransformer
|
|||
* Return a node transformed into a format that can be consumed by the
|
||||
* external administrative API.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Node $node
|
||||
* @param \Pterodactyl\Models\Node $model
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
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;
|
||||
|
@ -41,10 +42,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[$model->getUpdatedAtColumn()] = $this->formatTimestamp($model->updated_at);
|
||||
$response[$model->getCreatedAtColumn()] = $this->formatTimestamp($model->created_at);
|
||||
|
||||
$resources = $node->servers()->select(['memory', 'disk'])->get();
|
||||
$resources = $model->servers()->select(['memory', 'disk'])->get();
|
||||
|
||||
$response['allocated_resources'] = [
|
||||
'memory' => $resources->sum('memory'),
|
||||
|
@ -58,8 +59,10 @@ class NodeTransformer extends BaseTransformer
|
|||
* Return the nodes associated with this location.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Node $node
|
||||
*
|
||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function includeAllocations(Node $node)
|
||||
{
|
||||
|
@ -78,8 +81,10 @@ class NodeTransformer extends BaseTransformer
|
|||
* Return the nodes associated with this location.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Node $node
|
||||
*
|
||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function includeLocation(Node $node)
|
||||
{
|
||||
|
@ -98,8 +103,10 @@ class NodeTransformer extends BaseTransformer
|
|||
* Return the nodes associated with this location.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Node $node
|
||||
*
|
||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function includeServers(Node $node)
|
||||
{
|
||||
|
|
|
@ -54,45 +54,46 @@ class ServerTransformer extends BaseTransformer
|
|||
/**
|
||||
* Return a generic transformed server array.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @param \Pterodactyl\Models\Server $model
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function transform(Server $server): array
|
||||
public function transform(Server $model): array
|
||||
{
|
||||
return [
|
||||
'id' => $server->getKey(),
|
||||
'external_id' => $server->external_id,
|
||||
'uuid' => $server->uuid,
|
||||
'identifier' => $server->uuidShort,
|
||||
'name' => $server->name,
|
||||
'description' => $server->description,
|
||||
'suspended' => (bool) $server->suspended,
|
||||
'id' => $model->getKey(),
|
||||
'external_id' => $model->external_id,
|
||||
'uuid' => $model->uuid,
|
||||
'identifier' => $model->uuidShort,
|
||||
'name' => $model->name,
|
||||
'description' => $model->description,
|
||||
'suspended' => (bool) $model->suspended,
|
||||
'limits' => [
|
||||
'memory' => $server->memory,
|
||||
'swap' => $server->swap,
|
||||
'disk' => $server->disk,
|
||||
'io' => $server->io,
|
||||
'cpu' => $server->cpu,
|
||||
'threads' => $server->threads,
|
||||
'memory' => $model->memory,
|
||||
'swap' => $model->swap,
|
||||
'disk' => $model->disk,
|
||||
'io' => $model->io,
|
||||
'cpu' => $model->cpu,
|
||||
'threads' => $model->threads,
|
||||
],
|
||||
'feature_limits' => [
|
||||
'databases' => $server->database_limit,
|
||||
'allocations' => $server->allocation_limit,
|
||||
'backups' => $server->backup_limit,
|
||||
'databases' => $model->database_limit,
|
||||
'allocations' => $model->allocation_limit,
|
||||
'backups' => $model->backup_limit,
|
||||
],
|
||||
'user' => $server->owner_id,
|
||||
'node' => $server->node_id,
|
||||
'allocation' => $server->allocation_id,
|
||||
'nest' => $server->nest_id,
|
||||
'egg' => $server->egg_id,
|
||||
'user' => $model->owner_id,
|
||||
'node' => $model->node_id,
|
||||
'allocation' => $model->allocation_id,
|
||||
'nest' => $model->nest_id,
|
||||
'egg' => $model->egg_id,
|
||||
'container' => [
|
||||
'startup_command' => $server->startup,
|
||||
'image' => $server->image,
|
||||
'installed' => (int) $server->installed === 1,
|
||||
'environment' => $this->environmentService->handle($server),
|
||||
'startup_command' => $model->startup,
|
||||
'image' => $model->image,
|
||||
'installed' => (int) $model->installed === 1,
|
||||
'environment' => $this->environmentService->handle($model),
|
||||
],
|
||||
$server->getUpdatedAtColumn() => $this->formatTimestamp($server->updated_at),
|
||||
$server->getCreatedAtColumn() => $this->formatTimestamp($server->created_at),
|
||||
$model->getUpdatedAtColumn() => $this->formatTimestamp($model->updated_at),
|
||||
$model->getCreatedAtColumn() => $this->formatTimestamp($model->created_at),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -100,9 +101,11 @@ class ServerTransformer extends BaseTransformer
|
|||
* Return a generic array of allocations for this server.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
*
|
||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function includeAllocations(Server $server)
|
||||
{
|
||||
|
@ -119,9 +122,11 @@ class ServerTransformer extends BaseTransformer
|
|||
* Return a generic array of data about subusers for this server.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
*
|
||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function includeSubusers(Server $server)
|
||||
{
|
||||
|
@ -138,9 +143,11 @@ class ServerTransformer extends BaseTransformer
|
|||
* Return a generic array of data about subusers for this server.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
*
|
||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function includeUser(Server $server)
|
||||
{
|
||||
|
@ -157,9 +164,11 @@ class ServerTransformer extends BaseTransformer
|
|||
* Return a generic array with nest information for this server.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
*
|
||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function includeNest(Server $server)
|
||||
{
|
||||
|
@ -176,9 +185,11 @@ class ServerTransformer extends BaseTransformer
|
|||
* Return a generic array with egg information for this server.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
*
|
||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function includeEgg(Server $server)
|
||||
{
|
||||
|
@ -195,9 +206,11 @@ class ServerTransformer extends BaseTransformer
|
|||
* Return a generic array of data about subusers for this server.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
*
|
||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function includeVariables(Server $server)
|
||||
{
|
||||
|
@ -214,9 +227,11 @@ class ServerTransformer extends BaseTransformer
|
|||
* Return a generic array with location information for this server.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
*
|
||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function includeLocation(Server $server)
|
||||
{
|
||||
|
@ -233,9 +248,11 @@ class ServerTransformer extends BaseTransformer
|
|||
* Return a generic array with node information for this server.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
*
|
||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function includeNode(Server $server)
|
||||
{
|
||||
|
@ -252,9 +269,11 @@ class ServerTransformer extends BaseTransformer
|
|||
* Return a generic array with database information for this server.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
*
|
||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function includeDatabases(Server $server)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue