api(application): v2 backport
This commit is contained in:
parent
4cd0bee231
commit
67bf3e342e
172 changed files with 2922 additions and 1579 deletions
|
@ -2,26 +2,23 @@
|
|||
|
||||
namespace Pterodactyl\Transformers\Api\Application;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
use Pterodactyl\Models\Egg;
|
||||
use Pterodactyl\Models\Nest;
|
||||
use Pterodactyl\Models\Server;
|
||||
use League\Fractal\Resource\Item;
|
||||
use Pterodactyl\Models\EggVariable;
|
||||
use League\Fractal\Resource\Collection;
|
||||
use League\Fractal\Resource\NullResource;
|
||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||
use Pterodactyl\Transformers\Api\Transformer;
|
||||
|
||||
class EggTransformer extends BaseTransformer
|
||||
class EggTransformer extends Transformer
|
||||
{
|
||||
/**
|
||||
* Relationships that can be loaded onto this transformation.
|
||||
*/
|
||||
protected array $availableIncludes = [
|
||||
'nest',
|
||||
'servers',
|
||||
'config',
|
||||
'nest',
|
||||
'script',
|
||||
'servers',
|
||||
'variables',
|
||||
];
|
||||
|
||||
|
@ -50,19 +47,14 @@ class EggTransformer extends BaseTransformer
|
|||
'id' => $model->id,
|
||||
'uuid' => $model->uuid,
|
||||
'name' => $model->name,
|
||||
'nest' => $model->nest_id,
|
||||
'nest_id' => $model->nest_id,
|
||||
'author' => $model->author,
|
||||
'description' => $model->description,
|
||||
// "docker_image" is deprecated, but left here to avoid breaking too many things at once
|
||||
// in external software. We'll remove it down the road once things have gotten the chance
|
||||
// to upgrade to using "docker_images".
|
||||
'docker_image' => count($model->docker_images) > 0 ? Arr::first($model->docker_images) : '',
|
||||
'docker_images' => $model->docker_images,
|
||||
'config' => [
|
||||
'files' => $files,
|
||||
'startup' => json_decode($model->config_startup, true),
|
||||
'stop' => $model->config_stop,
|
||||
'logs' => json_decode($model->config_logs, true),
|
||||
'file_denylist' => $model->file_denylist,
|
||||
'extends' => $model->config_from,
|
||||
],
|
||||
|
@ -74,43 +66,11 @@ class EggTransformer extends BaseTransformer
|
|||
'container' => $model->script_container,
|
||||
'extends' => $model->copy_script_from,
|
||||
],
|
||||
$model->getCreatedAtColumn() => $this->formatTimestamp($model->created_at),
|
||||
$model->getUpdatedAtColumn() => $this->formatTimestamp($model->updated_at),
|
||||
'created_at' => self::formatTimestamp($model->created_at),
|
||||
'updated_at' => self::formatTimestamp($model->updated_at),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Include the Nest relationship for the given Egg in the transformation.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeNest(Egg $model): Item|NullResource
|
||||
{
|
||||
if (!$this->authorize(AdminAcl::RESOURCE_NESTS)) {
|
||||
return $this->null();
|
||||
}
|
||||
|
||||
$model->loadMissing('nest');
|
||||
|
||||
return $this->item($model->getRelation('nest'), $this->makeTransformer(NestTransformer::class), Nest::RESOURCE_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Include the Servers relationship for the given Egg in the transformation.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeServers(Egg $model): Collection|NullResource
|
||||
{
|
||||
if (!$this->authorize(AdminAcl::RESOURCE_SERVERS)) {
|
||||
return $this->null();
|
||||
}
|
||||
|
||||
$model->loadMissing('servers');
|
||||
|
||||
return $this->collection($model->getRelation('servers'), $this->makeTransformer(ServerTransformer::class), Server::RESOURCE_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Include more detailed information about the configuration if this Egg is
|
||||
* extending another.
|
||||
|
@ -121,8 +81,6 @@ class EggTransformer extends BaseTransformer
|
|||
return $this->null();
|
||||
}
|
||||
|
||||
$model->loadMissing('configFrom');
|
||||
|
||||
return $this->item($model, function (Egg $model) {
|
||||
return [
|
||||
'files' => json_decode($model->inherit_config_files),
|
||||
|
@ -133,6 +91,18 @@ class EggTransformer extends BaseTransformer
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Include the Nest relationship for the given Egg in the transformation.
|
||||
*/
|
||||
public function includeNest(Egg $model): Item|NullResource
|
||||
{
|
||||
if (!$this->authorize(AdminAcl::RESOURCE_NESTS)) {
|
||||
return $this->null();
|
||||
}
|
||||
|
||||
return $this->item($model->nest, new NestTransformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Include more detailed information about the script configuration if the
|
||||
* Egg is extending another.
|
||||
|
@ -143,8 +113,6 @@ class EggTransformer extends BaseTransformer
|
|||
return $this->null();
|
||||
}
|
||||
|
||||
$model->loadMissing('scriptFrom');
|
||||
|
||||
return $this->item($model, function (Egg $model) {
|
||||
return [
|
||||
'privileged' => $model->script_is_privileged,
|
||||
|
@ -155,10 +123,20 @@ class EggTransformer extends BaseTransformer
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Include the Servers relationship for the given Egg in the transformation.
|
||||
*/
|
||||
public function includeServers(Egg $model): Collection|NullResource
|
||||
{
|
||||
if (!$this->authorize(AdminAcl::RESOURCE_SERVERS)) {
|
||||
return $this->null();
|
||||
}
|
||||
|
||||
return $this->collection($model->servers, new ServerTransformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Include the variables that are defined for this Egg.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeVariables(Egg $model): Collection|NullResource
|
||||
{
|
||||
|
@ -168,10 +146,6 @@ class EggTransformer extends BaseTransformer
|
|||
|
||||
$model->loadMissing('variables');
|
||||
|
||||
return $this->collection(
|
||||
$model->getRelation('variables'),
|
||||
$this->makeTransformer(EggVariableTransformer::class),
|
||||
EggVariable::RESOURCE_NAME
|
||||
);
|
||||
return $this->collection($model->variables, new EggVariableTransformer());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue