Files
pterodactyl-panel/app/Http/Controllers/Api/Application/Servers/ServerDetailsController.php
T

78 lines
3.0 KiB
PHP
Raw Normal View History

<?php
2026-10-05 18:10:18 -04:00
declare(strict_types=1);
namespace Pterodactyl\Http\Controllers\Api\Application\Servers;
2026-10-05 18:10:18 -04:00
use Knuckles\Scribe\Attributes\Endpoint;
use Knuckles\Scribe\Attributes\Group;
use Knuckles\Scribe\Attributes\Response as ScribeResponse;
use Knuckles\Scribe\Attributes\Subgroup;
use Pterodactyl\Contracts\Servers\UpdatesServerBuild;
use Pterodactyl\Contracts\Servers\UpdatesServerDetails;
use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Extensions\Scribe\Attributes\ResponseFromTransformer;
use Pterodactyl\Facades\Fractal;
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
2018-01-21 16:02:03 -06:00
use Pterodactyl\Http\Requests\Api\Application\Servers\UpdateServerBuildConfigurationRequest;
2026-10-05 18:10:18 -04:00
use Pterodactyl\Http\Requests\Api\Application\Servers\UpdateServerDetailsRequest;
use Pterodactyl\Models\Server;
use Pterodactyl\Transformers\Api\Application\ServerTransformer;
2026-10-05 18:10:18 -04:00
#[Group('Application API', 'Root administrator endpoints for managing panel resources using application API tokens.')]
#[Subgroup('Servers', 'Create, update, retrieve, manage, and delete servers.')]
class ServerDetailsController extends ApplicationApiController
{
2026-10-05 18:10:18 -04:00
private const array ALLOCATION_ERROR = [
'errors' => [
[
'code' => 'DisplayException',
'status' => '400',
'detail' => 'The requested default allocation is not currently assigned to this server.',
],
],
];
/**
2018-01-21 16:02:03 -06:00
* Update the details for a specific server.
*
2026-10-05 18:10:18 -04:00
*
* @return ApiPayload
*
* @throws DisplayException
*/
2026-10-05 18:10:18 -04:00
#[Endpoint('Update server details', 'Updates ownership and display details for a server.')]
#[ResponseFromTransformer(ServerTransformer::class, Server::class, factoryStates: ['withRelationships'], resourceKey: 'server')]
public function details(UpdateServerDetailsRequest $request, UpdatesServerDetails $details, Server $server): array
{
2026-10-05 18:10:18 -04:00
$updated = $details->update(
2022-05-22 14:10:01 -04:00
$server,
2026-10-05 18:10:18 -04:00
$request->payload()
2018-01-27 12:38:56 -06:00
);
2018-01-21 16:02:03 -06:00
2026-10-05 18:10:18 -04:00
return Fractal::item($updated)
2018-01-21 16:02:03 -06:00
->transformWith($this->getTransformer(ServerTransformer::class))
2026-10-05 18:10:18 -04:00
->toResponseArray();
2018-01-21 16:02:03 -06:00
}
/**
* Update the build details for a specific server.
*
2026-10-05 18:10:18 -04:00
*
* @return ApiPayload
*
* @throws DisplayException
2018-01-21 16:02:03 -06:00
*/
2026-10-05 18:10:18 -04:00
#[Endpoint('Update server build', 'Updates resource limits, feature limits, and allocations for a server.')]
#[ResponseFromTransformer(ServerTransformer::class, Server::class, factoryStates: ['withRelationships'], resourceKey: 'server')]
#[ScribeResponse(self::ALLOCATION_ERROR, status: 400, description: 'The requested allocation change is invalid.')]
public function build(UpdateServerBuildConfigurationRequest $request, UpdatesServerBuild $build, Server $server): array
2018-01-21 16:02:03 -06:00
{
2026-10-05 18:10:18 -04:00
$server = $build->update($server, $request->payload());
2026-10-05 18:10:18 -04:00
return Fractal::item($server)
->transformWith($this->getTransformer(ServerTransformer::class))
2026-10-05 18:10:18 -04:00
->toResponseArray();
}
}