Remove labels/mounts if empty.

This commit is contained in:
notCharles 2024-06-02 13:43:25 -04:00
parent aa55a7ed83
commit 0b0952650e

View File

@ -40,7 +40,7 @@ class ServerConfigurationStructureService
*/ */
protected function returnFormat(Server $server): array protected function returnFormat(Server $server): array
{ {
return [ $response = [
'uuid' => $server->uuid, 'uuid' => $server->uuid,
'meta' => [ 'meta' => [
'name' => $server->name, 'name' => $server->name,
@ -50,7 +50,6 @@ class ServerConfigurationStructureService
'environment' => $this->environment->handle($server), 'environment' => $this->environment->handle($server),
'invocation' => $server->startup, 'invocation' => $server->startup,
'skip_egg_scripts' => $server->skip_scripts, 'skip_egg_scripts' => $server->skip_scripts,
'labels' => $server->docker_labels,
'build' => [ 'build' => [
'memory_limit' => $server->memory, 'memory_limit' => $server->memory,
'swap' => $server->swap, 'swap' => $server->swap,
@ -72,17 +71,27 @@ class ServerConfigurationStructureService
], ],
'mappings' => $server->getAllocationMappings(), 'mappings' => $server->getAllocationMappings(),
], ],
'mounts' => $server->mounts->map(function (Mount $mount) {
return [
'source' => $mount->source,
'target' => $mount->target,
'read_only' => $mount->read_only,
];
}),
'egg' => [ 'egg' => [
'id' => $server->egg->uuid, 'id' => $server->egg->uuid,
'file_denylist' => $server->egg->inherit_file_denylist, 'file_denylist' => $server->egg->inherit_file_denylist,
], ],
]; ];
if (!empty($server->docker_labels)) {
$response['labels'] = $server->docker_labels;
}
if ($server->mounts->isNotEmpty()) {
$response['mounts'] = $server->mounts->map(function (Mount $mount) {
return [
'source' => $mount->source,
'target' => $mount->target,
'read_only' => $mount->read_only,
];
})->toArray();
}
return $response;
} }
} }