mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 15:44:45 +02:00
correctly transform eggs that use inheritance (application api) (#217)
This commit is contained in:
parent
73babfa2b3
commit
e715e92f9d
@ -5,7 +5,6 @@ namespace App\Transformers\Api\Application;
|
|||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
use App\Models\Egg;
|
use App\Models\Egg;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use League\Fractal\Resource\Item;
|
|
||||||
use App\Models\EggVariable;
|
use App\Models\EggVariable;
|
||||||
use League\Fractal\Resource\Collection;
|
use League\Fractal\Resource\Collection;
|
||||||
use League\Fractal\Resource\NullResource;
|
use League\Fractal\Resource\NullResource;
|
||||||
@ -39,7 +38,11 @@ class EggTransformer extends BaseTransformer
|
|||||||
*/
|
*/
|
||||||
public function transform(Egg $model): array
|
public function transform(Egg $model): array
|
||||||
{
|
{
|
||||||
$files = json_decode($model->config_files, true, 512, JSON_THROW_ON_ERROR);
|
$model->loadMissing('configFrom');
|
||||||
|
|
||||||
|
$files = json_decode($model->inherit_config_files, true, 512, JSON_THROW_ON_ERROR);
|
||||||
|
|
||||||
|
$model->loadMissing('scriptFrom');
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => $model->id,
|
'id' => $model->id,
|
||||||
@ -54,18 +57,18 @@ class EggTransformer extends BaseTransformer
|
|||||||
'docker_images' => $model->docker_images,
|
'docker_images' => $model->docker_images,
|
||||||
'config' => [
|
'config' => [
|
||||||
'files' => $files,
|
'files' => $files,
|
||||||
'startup' => json_decode($model->config_startup, true),
|
'startup' => json_decode($model->inherit_config_startup, true),
|
||||||
'stop' => $model->config_stop,
|
'stop' => $model->inherit_config_stop,
|
||||||
'logs' => json_decode($model->config_logs, true),
|
'logs' => json_decode($model->inherit_config_logs, true),
|
||||||
'file_denylist' => $model->file_denylist,
|
'file_denylist' => $model->inherit_file_denylist,
|
||||||
'extends' => $model->config_from,
|
'extends' => $model->config_from,
|
||||||
],
|
],
|
||||||
'startup' => $model->startup,
|
'startup' => $model->startup,
|
||||||
'script' => [
|
'script' => [
|
||||||
'privileged' => $model->script_is_privileged,
|
'privileged' => $model->script_is_privileged,
|
||||||
'install' => $model->script_install,
|
'install' => $model->copy_script_install,
|
||||||
'entry' => $model->script_entry,
|
'entry' => $model->copy_script_entry,
|
||||||
'container' => $model->script_container,
|
'container' => $model->copy_script_container,
|
||||||
'extends' => $model->copy_script_from,
|
'extends' => $model->copy_script_from,
|
||||||
],
|
],
|
||||||
$model->getCreatedAtColumn() => $this->formatTimestamp($model->created_at),
|
$model->getCreatedAtColumn() => $this->formatTimestamp($model->created_at),
|
||||||
@ -89,50 +92,6 @@ class EggTransformer extends BaseTransformer
|
|||||||
return $this->collection($model->getRelation('servers'), $this->makeTransformer(ServerTransformer::class), Server::RESOURCE_NAME);
|
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.
|
|
||||||
*/
|
|
||||||
public function includeConfig(Egg $model): Item|NullResource
|
|
||||||
{
|
|
||||||
if (is_null($model->config_from)) {
|
|
||||||
return $this->null();
|
|
||||||
}
|
|
||||||
|
|
||||||
$model->loadMissing('configFrom');
|
|
||||||
|
|
||||||
return $this->item($model, function (Egg $model) {
|
|
||||||
return [
|
|
||||||
'files' => json_decode($model->inherit_config_files),
|
|
||||||
'startup' => json_decode($model->inherit_config_startup),
|
|
||||||
'stop' => $model->inherit_config_stop,
|
|
||||||
'logs' => json_decode($model->inherit_config_logs),
|
|
||||||
];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Include more detailed information about the script configuration if the
|
|
||||||
* Egg is extending another.
|
|
||||||
*/
|
|
||||||
public function includeScript(Egg $model): Item|NullResource
|
|
||||||
{
|
|
||||||
if (is_null($model->copy_script_from)) {
|
|
||||||
return $this->null();
|
|
||||||
}
|
|
||||||
|
|
||||||
$model->loadMissing('scriptFrom');
|
|
||||||
|
|
||||||
return $this->item($model, function (Egg $model) {
|
|
||||||
return [
|
|
||||||
'privileged' => $model->script_is_privileged,
|
|
||||||
'install' => $model->copy_script_install,
|
|
||||||
'entry' => $model->copy_script_entry,
|
|
||||||
'container' => $model->copy_script_container,
|
|
||||||
];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Include the variables that are defined for this Egg.
|
* Include the variables that are defined for this Egg.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user