creationService = $creationService; $this->deletionService = $deletionService; } /** * Return all of the servers that currently exist on the Panel. */ public function index(GetServersRequest $request): array { $perPage = $request->query('per_page', 10); if ($perPage < 1) { $perPage = 10; } else if ($perPage > 100) { throw new BadRequestHttpException('"per_page" query parameter must be below 100.'); } $servers = QueryBuilder::for(Server::query()) ->allowedFilters(['uuid', 'name', 'image', 'external_id']) ->allowedSorts(['id', 'uuid']) ->paginate($perPage); return $this->fractal->collection($servers) ->transformWith($this->getTransformer(ServerTransformer::class)) ->toArray(); } /** * Create a new server on the system. * * @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 store(StoreServerRequest $request): JsonResponse { $server = $this->creationService->handle($request->validated(), $request->getDeploymentObject()); return $this->fractal->item($server) ->transformWith($this->getTransformer(ServerTransformer::class)) ->respond(201); } /** * Show a single server transformed for the application API. */ public function view(GetServerRequest $request, Server $server): array { return $this->fractal->item($server) ->transformWith($this->getTransformer(ServerTransformer::class)) ->toArray(); } /** * @throws \Pterodactyl\Exceptions\DisplayException */ public function delete(ServerWriteRequest $request, Server $server, string $force = ''): Response { $this->deletionService->withForce($force === 'force')->handle($server); return $this->returnNoContent(); } }