ui(admin): implement basic server editing
This commit is contained in:
parent
d0a78ec067
commit
6362731d55
11 changed files with 220 additions and 90 deletions
|
@ -8,6 +8,8 @@ use Illuminate\Http\JsonResponse;
|
|||
use Spatie\QueryBuilder\QueryBuilder;
|
||||
use Pterodactyl\Services\Servers\ServerCreationService;
|
||||
use Pterodactyl\Services\Servers\ServerDeletionService;
|
||||
use Pterodactyl\Services\Servers\BuildModificationService;
|
||||
use Pterodactyl\Services\Servers\DetailsModificationService;
|
||||
use Pterodactyl\Transformers\Api\Application\ServerTransformer;
|
||||
use Pterodactyl\Exceptions\Http\QueryValueOutOfRangeHttpException;
|
||||
use Pterodactyl\Http\Requests\Api\Application\Servers\GetServerRequest;
|
||||
|
@ -15,23 +17,32 @@ use Pterodactyl\Http\Requests\Api\Application\Servers\GetServersRequest;
|
|||
use Pterodactyl\Http\Requests\Api\Application\Servers\ServerWriteRequest;
|
||||
use Pterodactyl\Http\Requests\Api\Application\Servers\StoreServerRequest;
|
||||
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
|
||||
use Pterodactyl\Http\Requests\Api\Application\Servers\UpdateServerRequest;
|
||||
|
||||
class ServerController extends ApplicationApiController
|
||||
{
|
||||
private ServerCreationService $creationService;
|
||||
private ServerDeletionService $deletionService;
|
||||
|
||||
private BuildModificationService $buildModificationService;
|
||||
private DetailsModificationService $detailsModificationService;
|
||||
|
||||
/**
|
||||
* ServerController constructor.
|
||||
*/
|
||||
public function __construct(
|
||||
ServerCreationService $creationService,
|
||||
ServerDeletionService $deletionService
|
||||
ServerDeletionService $deletionService,
|
||||
BuildModificationService $buildModificationService,
|
||||
DetailsModificationService $detailsModificationService
|
||||
) {
|
||||
parent::__construct();
|
||||
|
||||
$this->creationService = $creationService;
|
||||
$this->deletionService = $deletionService;
|
||||
|
||||
$this->buildModificationService = $buildModificationService;
|
||||
$this->detailsModificationService = $detailsModificationService;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -99,4 +110,24 @@ class ServerController extends ApplicationApiController
|
|||
|
||||
return $this->returnNoContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a server.
|
||||
*
|
||||
* @throws \Throwable
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
* @throws \Pterodactyl\Exceptions\Service\Deployment\NoViableAllocationException
|
||||
* @throws \Pterodactyl\Exceptions\Service\Deployment\NoViableNodeException
|
||||
*/
|
||||
public function update(UpdateServerRequest $request, Server $server): array
|
||||
{
|
||||
$server = $this->buildModificationService->handle($server, $request->validated());
|
||||
$server = $this->detailsModificationService->returnUpdatedModel()->handle($server, $request->validated());
|
||||
|
||||
return $this->fractal->item($server)
|
||||
->transformWith(ServerTransformer::class)
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ class UpdateServerBuildConfigurationRequest extends ServerWriteRequest
|
|||
'limits.threads' => $this->requiredToOptional('threads', $rules['threads'], true),
|
||||
'limits.disk' => $this->requiredToOptional('disk', $rules['disk'], true),
|
||||
|
||||
// Legacy rules to maintain backwards compatable API support without requiring
|
||||
// Legacy rules to maintain backwards compatible API support without requiring
|
||||
// a major version bump.
|
||||
//
|
||||
// @see https://github.com/pterodactyl/panel/issues/1500
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Http\Requests\Api\Application\Servers;
|
||||
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
class UpdateServerRequest extends ApplicationApiRequest
|
||||
{
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = Server::getRules();
|
||||
|
||||
return [
|
||||
'external_id' => $rules['external_id'],
|
||||
'name' => $rules['name'],
|
||||
'description' => array_merge(['nullable'], $rules['description']),
|
||||
'owner_id' => $rules['owner_id'],
|
||||
'oom_killer' => 'sometimes|boolean',
|
||||
|
||||
'memory' => $rules['memory'],
|
||||
'swap' => $rules['swap'],
|
||||
'disk' => $rules['disk'],
|
||||
'io' => $rules['io'],
|
||||
'threads' => $rules['threads'],
|
||||
'cpu' => $rules['cpu'],
|
||||
|
||||
'databases' => $rules['database_limit'],
|
||||
'allocations' => $rules['allocation_limit'],
|
||||
'backups' => $rules['backup_limit'],
|
||||
];
|
||||
}
|
||||
|
||||
public function validated(): array
|
||||
{
|
||||
$data = parent::validated();
|
||||
|
||||
return [
|
||||
'external_id' => array_get($data, 'external_id'),
|
||||
'name' => array_get($data, 'name'),
|
||||
'description' => array_get($data, 'description'),
|
||||
'owner_id' => array_get($data, 'owner_id'),
|
||||
'oom_disabled' => !array_get($data, 'oom_killer'),
|
||||
|
||||
'memory' => array_get($data, 'memory'),
|
||||
'swap' => array_get($data, 'swap'),
|
||||
'disk' => array_get($data, 'disk'),
|
||||
'io' => array_get($data, 'io'),
|
||||
'threads' => array_get($data, 'threads'),
|
||||
'cpu' => array_get($data, 'cpu'),
|
||||
|
||||
'database_limit' => array_get($data, 'databases'),
|
||||
'allocation_limit' => array_get($data, 'allocations'),
|
||||
'backup_limit' => array_get($data, 'backups'),
|
||||
];
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue