2018-02-24 14:09:09 -06:00
|
|
|
<?php
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2018-02-24 14:09:09 -06:00
|
|
|
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\Subgroup;
|
|
|
|
|
use Pterodactyl\Extensions\Scribe\Attributes\ResponseFromTransformer;
|
|
|
|
|
use Pterodactyl\Facades\Fractal;
|
2018-02-24 14:09:09 -06:00
|
|
|
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
|
|
|
|
|
use Pterodactyl\Http\Requests\Api\Application\Servers\GetExternalServerRequest;
|
2026-10-05 18:10:18 -04:00
|
|
|
use Pterodactyl\Models\Server;
|
|
|
|
|
use Pterodactyl\Services\Servers\ServerFinderService;
|
|
|
|
|
use Pterodactyl\Transformers\Api\Application\ServerTransformer;
|
2018-02-24 14:09:09 -06:00
|
|
|
|
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.')]
|
2018-02-24 14:09:09 -06:00
|
|
|
class ExternalServerController extends ApplicationApiController
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve a specific server from the database using its external ID.
|
2026-10-05 18:10:18 -04:00
|
|
|
*
|
|
|
|
|
* @return ApiPayload
|
2018-02-24 14:09:09 -06:00
|
|
|
*/
|
2026-10-05 18:10:18 -04:00
|
|
|
#[Endpoint('Get server by external ID', 'Returns a single server by its external identifier.')]
|
|
|
|
|
#[ResponseFromTransformer(ServerTransformer::class, Server::class, factoryStates: ['withRelationships'], resourceKey: 'server')]
|
|
|
|
|
public function index(GetExternalServerRequest $request, ServerFinderService $finder, string $external_id): array
|
2018-02-24 14:09:09 -06:00
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
$server = $finder->byExternalId($external_id);
|
2022-05-22 14:10:01 -04:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
return Fractal::item($server)
|
2018-02-24 14:09:09 -06:00
|
|
|
->transformWith($this->getTransformer(ServerTransformer::class))
|
2026-10-05 18:10:18 -04:00
|
|
|
->toResponseArray();
|
2018-02-24 14:09:09 -06:00
|
|
|
}
|
|
|
|
|
}
|