2018-02-28 03:28:43 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Transformers\Api\Client;
|
|
|
|
|
2019-09-22 22:30:53 +00:00
|
|
|
use Pterodactyl\Models\Egg;
|
2018-02-28 03:28:43 +00:00
|
|
|
use Pterodactyl\Models\Server;
|
2019-12-28 20:03:19 +00:00
|
|
|
use Pterodactyl\Models\Subuser;
|
2020-07-09 04:04:45 +00:00
|
|
|
use Pterodactyl\Models\Allocation;
|
2018-02-28 03:28:43 +00:00
|
|
|
|
|
|
|
class ServerTransformer extends BaseClientTransformer
|
|
|
|
{
|
2019-09-22 22:30:53 +00:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2019-12-28 20:03:19 +00:00
|
|
|
protected $availableIncludes = ['egg', 'subusers'];
|
2019-09-22 22:30:53 +00:00
|
|
|
|
2018-02-28 03:28:43 +00:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getResourceName(): string
|
|
|
|
{
|
|
|
|
return Server::RESOURCE_NAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transform a server model into a representation that can be returned
|
|
|
|
* to a client.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Models\Server $server
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function transform(Server $server): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'server_owner' => $this->getKey()->user_id === $server->owner_id,
|
|
|
|
'identifier' => $server->uuidShort,
|
|
|
|
'uuid' => $server->uuid,
|
|
|
|
'name' => $server->name,
|
2018-05-28 21:11:23 +00:00
|
|
|
'node' => $server->node->name,
|
2019-12-07 23:58:37 +00:00
|
|
|
'sftp_details' => [
|
|
|
|
'ip' => $server->node->fqdn,
|
|
|
|
'port' => $server->node->daemonSFTP,
|
|
|
|
],
|
2018-02-28 03:28:43 +00:00
|
|
|
'description' => $server->description,
|
2020-07-09 04:04:45 +00:00
|
|
|
'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,
|
|
|
|
];
|
|
|
|
}),
|
2018-02-28 03:28:43 +00:00
|
|
|
'limits' => [
|
|
|
|
'memory' => $server->memory,
|
|
|
|
'swap' => $server->swap,
|
|
|
|
'disk' => $server->disk,
|
|
|
|
'io' => $server->io,
|
|
|
|
'cpu' => $server->cpu,
|
|
|
|
],
|
2018-03-02 02:08:27 +00:00
|
|
|
'feature_limits' => [
|
|
|
|
'databases' => $server->database_limit,
|
|
|
|
'allocations' => $server->allocation_limit,
|
2020-04-26 19:12:29 +00:00
|
|
|
'backups' => $server->backup_limit,
|
2018-03-02 02:08:27 +00:00
|
|
|
],
|
2020-04-26 00:58:09 +00:00
|
|
|
'is_suspended' => $server->suspended !== 0,
|
|
|
|
'is_installing' => $server->installed !== 1,
|
2018-02-28 03:28:43 +00:00
|
|
|
];
|
|
|
|
}
|
2019-09-22 22:30:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the egg associated with this server.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Models\Server $server
|
|
|
|
* @return \League\Fractal\Resource\Item
|
|
|
|
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
|
|
*/
|
|
|
|
public function includeEgg(Server $server)
|
|
|
|
{
|
|
|
|
return $this->item($server->egg, $this->makeTransformer(EggTransformer::class), Egg::RESOURCE_NAME);
|
|
|
|
}
|
2019-12-28 20:03:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the subusers associated with this server.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Models\Server $server
|
|
|
|
* @return \League\Fractal\Resource\Collection
|
|
|
|
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
|
|
*/
|
|
|
|
public function includeSubusers(Server $server)
|
|
|
|
{
|
|
|
|
return $this->collection($server->subusers, $this->makeTransformer(SubuserTransformer::class), Subuser::RESOURCE_NAME);
|
|
|
|
}
|
2018-02-28 03:28:43 +00:00
|
|
|
}
|