api: cleanup controllers

This commit is contained in:
Matthew Penner 2021-03-05 10:03:12 -07:00
parent 00c42225e8
commit f78aaea6a3
47 changed files with 323 additions and 764 deletions

View File

@ -7,22 +7,14 @@ use Webmozart\Assert\Assert;
use Illuminate\Http\Response; use Illuminate\Http\Response;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Container\Container; use Illuminate\Container\Container;
use Illuminate\Support\Facades\Log;
use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Extensions\Spatie\Fractalistic\Fractal; use Pterodactyl\Extensions\Spatie\Fractalistic\Fractal;
use Pterodactyl\Transformers\Api\Application\BaseTransformer; use Pterodactyl\Transformers\Api\Application\BaseTransformer;
abstract class ApplicationApiController extends Controller abstract class ApplicationApiController extends Controller
{ {
/** protected Request $request;
* @var \Illuminate\Http\Request protected Fractal $fractal;
*/
protected $request;
/**
* @var \Pterodactyl\Extensions\Spatie\Fractalistic\Fractal
*/
protected $fractal;
/** /**
* ApplicationApiController constructor. * ApplicationApiController constructor.
@ -56,11 +48,9 @@ abstract class ApplicationApiController extends Controller
/** /**
* Return an instance of an application transformer. * Return an instance of an application transformer.
* *
* @return \Pterodactyl\Transformers\Api\Application\BaseTransformer
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException * @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function getTransformer(string $abstract) public function getTransformer(string $abstract): BaseTransformer
{ {
/** @var \Pterodactyl\Transformers\Api\Application\BaseTransformer $transformer */ /** @var \Pterodactyl\Transformers\Api\Application\BaseTransformer $transformer */
$transformer = Container::getInstance()->make($abstract); $transformer = Container::getInstance()->make($abstract);
@ -72,6 +62,14 @@ abstract class ApplicationApiController extends Controller
return $transformer; return $transformer;
} }
/**
* Return a HTTP/201 response for the API.
*/
protected function returnAccepted(): Response
{
return new Response('', Response::HTTP_ACCEPTED);
}
/** /**
* Return a HTTP/204 response for the API. * Return a HTTP/204 response for the API.
*/ */

View File

@ -2,6 +2,7 @@
namespace Pterodactyl\Http\Controllers\Api\Application\Databases; namespace Pterodactyl\Http\Controllers\Api\Application\Databases;
use Illuminate\Http\Response;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Pterodactyl\Models\DatabaseHost; use Pterodactyl\Models\DatabaseHost;
use Spatie\QueryBuilder\QueryBuilder; use Spatie\QueryBuilder\QueryBuilder;
@ -101,10 +102,10 @@ class DatabaseController extends ApplicationApiController
* *
* @throws \Exception * @throws \Exception
*/ */
public function delete(DeleteDatabaseRequest $request, DatabaseHost $databaseHost): JsonResponse public function delete(DeleteDatabaseRequest $request, DatabaseHost $databaseHost): Response
{ {
$databaseHost->delete(); $databaseHost->delete();
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); return $this->returnNoContent();
} }
} }

View File

@ -4,6 +4,7 @@ namespace Pterodactyl\Http\Controllers\Api\Application\Eggs;
use Pterodactyl\Models\Egg; use Pterodactyl\Models\Egg;
use Pterodactyl\Models\Nest; use Pterodactyl\Models\Nest;
use Illuminate\Http\Response;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Pterodactyl\Contracts\Repository\EggRepositoryInterface; use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
use Pterodactyl\Transformers\Api\Application\EggTransformer; use Pterodactyl\Transformers\Api\Application\EggTransformer;
@ -16,15 +17,10 @@ use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
class EggController extends ApplicationApiController class EggController extends ApplicationApiController
{ {
/** private EggRepositoryInterface $repository;
* @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface
*/
private $repository;
/** /**
* EggController constructor. * EggController constructor.
*
* @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository
*/ */
public function __construct(EggRepositoryInterface $repository) public function __construct(EggRepositoryInterface $repository)
{ {
@ -36,10 +32,6 @@ class EggController extends ApplicationApiController
/** /**
* Return an array of all eggs on a given nest. * Return an array of all eggs on a given nest.
* *
* @param \Pterodactyl\Http\Requests\Api\Application\Eggs\GetEggsRequest $request
* @param \Pterodactyl\Models\Nest $nest
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException * @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function index(GetEggsRequest $request, Nest $nest): array public function index(GetEggsRequest $request, Nest $nest): array
@ -56,10 +48,6 @@ class EggController extends ApplicationApiController
/** /**
* Returns a single egg. * Returns a single egg.
* *
* @param \Pterodactyl\Http\Requests\Api\Application\Eggs\GetEggRequest $request
* @param \Pterodactyl\Models\Egg $egg
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException * @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function view(GetEggRequest $request, Egg $egg): array public function view(GetEggRequest $request, Egg $egg): array
@ -72,9 +60,6 @@ class EggController extends ApplicationApiController
/** /**
* Creates a new egg. * Creates a new egg.
* *
* @param \Pterodactyl\Http\Requests\Api\Application\Eggs\StoreEggRequest $request
*
* @return \Illuminate\Http\JsonResponse
* @throws \Illuminate\Contracts\Container\BindingResolutionException * @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function store(StoreEggRequest $request): JsonResponse public function store(StoreEggRequest $request): JsonResponse
@ -89,10 +74,6 @@ class EggController extends ApplicationApiController
/** /**
* Updates an egg. * Updates an egg.
* *
* @param \Pterodactyl\Http\Requests\Api\Application\Eggs\UpdateEggRequest $request
* @param \Pterodactyl\Models\Egg $egg
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException * @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function update(UpdateEggRequest $request, Egg $egg): array public function update(UpdateEggRequest $request, Egg $egg): array
@ -107,16 +88,12 @@ class EggController extends ApplicationApiController
/** /**
* Deletes an egg. * Deletes an egg.
* *
* @param \Pterodactyl\Http\Requests\Api\Application\Eggs\DeleteEggRequest $request
* @param \Pterodactyl\Models\Egg $egg
*
* @return \Illuminate\Http\JsonResponse
* @throws \Exception * @throws \Exception
*/ */
public function delete(DeleteEggRequest $request, Egg $egg): JsonResponse public function delete(DeleteEggRequest $request, Egg $egg): Response
{ {
$egg->delete(); $egg->delete();
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); return $this->returnNoContent();
} }
} }

View File

@ -2,6 +2,7 @@
namespace Pterodactyl\Http\Controllers\Api\Application\Locations; namespace Pterodactyl\Http\Controllers\Api\Application\Locations;
use Illuminate\Http\Response;
use Pterodactyl\Models\Location; use Pterodactyl\Models\Location;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Spatie\QueryBuilder\QueryBuilder; use Spatie\QueryBuilder\QueryBuilder;
@ -44,6 +45,8 @@ class LocationController extends ApplicationApiController
/** /**
* Return all of the locations currently registered on the Panel. * Return all of the locations currently registered on the Panel.
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function index(GetLocationsRequest $request): array public function index(GetLocationsRequest $request): array
{ {
@ -66,6 +69,8 @@ class LocationController extends ApplicationApiController
/** /**
* Return a single location. * Return a single location.
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function view(GetLocationRequest $request, Location $location): array public function view(GetLocationRequest $request, Location $location): array
{ {
@ -79,6 +84,7 @@ class LocationController extends ApplicationApiController
* new location attached. * new location attached.
* *
* @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function store(StoreLocationRequest $request): JsonResponse public function store(StoreLocationRequest $request): JsonResponse
{ {
@ -115,10 +121,10 @@ class LocationController extends ApplicationApiController
* *
* @throws \Pterodactyl\Exceptions\Service\Location\HasActiveNodesException * @throws \Pterodactyl\Exceptions\Service\Location\HasActiveNodesException
*/ */
public function delete(DeleteLocationRequest $request, Location $location): JsonResponse public function delete(DeleteLocationRequest $request, Location $location): Response
{ {
$this->deletionService->handle($location); $this->deletionService->handle($location);
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); return $this->returnNoContent();
} }
} }

View File

@ -3,6 +3,7 @@
namespace Pterodactyl\Http\Controllers\Api\Application\Mounts; namespace Pterodactyl\Http\Controllers\Api\Application\Mounts;
use Pterodactyl\Models\Mount; use Pterodactyl\Models\Mount;
use Illuminate\Http\Response;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Spatie\QueryBuilder\QueryBuilder; use Spatie\QueryBuilder\QueryBuilder;
use Pterodactyl\Transformers\Api\Application\MountTransformer; use Pterodactyl\Transformers\Api\Application\MountTransformer;
@ -12,8 +13,8 @@ use Pterodactyl\Http\Requests\Api\Application\Mounts\GetMountsRequest;
use Pterodactyl\Http\Requests\Api\Application\Mounts\MountEggsRequest; use Pterodactyl\Http\Requests\Api\Application\Mounts\MountEggsRequest;
use Pterodactyl\Http\Requests\Api\Application\Mounts\MountNodesRequest; use Pterodactyl\Http\Requests\Api\Application\Mounts\MountNodesRequest;
use Pterodactyl\Http\Requests\Api\Application\Mounts\StoreMountRequest; use Pterodactyl\Http\Requests\Api\Application\Mounts\StoreMountRequest;
use Pterodactyl\Http\Requests\Api\Application\Mounts\UpdateMountRequest;
use Pterodactyl\Http\Requests\Api\Application\Mounts\DeleteMountRequest; use Pterodactyl\Http\Requests\Api\Application\Mounts\DeleteMountRequest;
use Pterodactyl\Http\Requests\Api\Application\Mounts\UpdateMountRequest;
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController; use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
class MountController extends ApplicationApiController class MountController extends ApplicationApiController
@ -29,9 +30,6 @@ class MountController extends ApplicationApiController
/** /**
* Returns an array of all mount. * Returns an array of all mount.
* *
* @param \Pterodactyl\Http\Requests\Api\Application\Mounts\GetMountsRequest $request
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException * @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function index(GetMountsRequest $request): array public function index(GetMountsRequest $request): array
@ -56,10 +54,6 @@ class MountController extends ApplicationApiController
/** /**
* Returns a single mount. * Returns a single mount.
* *
* @param \Pterodactyl\Http\Requests\Api\Application\Mounts\GetMountRequest $request
* @param \Pterodactyl\Models\Mount $mount
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException * @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function view(GetMountRequest $request, Mount $mount): array public function view(GetMountRequest $request, Mount $mount): array
@ -72,9 +66,6 @@ class MountController extends ApplicationApiController
/** /**
* Creates a new mount. * Creates a new mount.
* *
* @param \Pterodactyl\Http\Requests\Api\Application\Mounts\StoreMountRequest $request
*
* @return \Illuminate\Http\JsonResponse
* @throws \Illuminate\Contracts\Container\BindingResolutionException * @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function store(StoreMountRequest $request): JsonResponse public function store(StoreMountRequest $request): JsonResponse
@ -89,10 +80,6 @@ class MountController extends ApplicationApiController
/** /**
* Updates a mount. * Updates a mount.
* *
* @param \Pterodactyl\Http\Requests\Api\Application\Mounts\UpdateMountRequest $request
* @param \Pterodactyl\Models\Mount $mount
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException * @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function update(UpdateMountRequest $request, Mount $mount): array public function update(UpdateMountRequest $request, Mount $mount): array
@ -107,26 +94,19 @@ class MountController extends ApplicationApiController
/** /**
* Deletes a mount. * Deletes a mount.
* *
* @param \Pterodactyl\Http\Requests\Api\Application\Mounts\DeleteMountRequest $request
* @param \Pterodactyl\Models\Mount $mount
*
* @return \Illuminate\Http\JsonResponse
* @throws \Exception * @throws \Exception
*/ */
public function delete(DeleteMountRequest $request, Mount $mount): JsonResponse public function delete(DeleteMountRequest $request, Mount $mount): Response
{ {
$mount->delete(); $mount->delete();
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); return $this->returnNoContent();
} }
/** /**
* ? * Attaches eggs to a mount.
* *
* @param \Pterodactyl\Http\Requests\Api\Application\Mounts\MountEggsRequest $request * @throws \Illuminate\Contracts\Container\BindingResolutionException
* @param \Pterodactyl\Models\Mount $mount
*
* @return array
*/ */
public function addEggs(MountEggsRequest $request, Mount $mount): array public function addEggs(MountEggsRequest $request, Mount $mount): array
{ {
@ -143,12 +123,9 @@ class MountController extends ApplicationApiController
} }
/** /**
* ? * Attaches nodes to a mount.
* *
* @param \Pterodactyl\Http\Requests\Api\Application\Mounts\MountNodesRequest $request * @throws \Illuminate\Contracts\Container\BindingResolutionException
* @param \Pterodactyl\Models\Mount $mount
*
* @return array
*/ */
public function addNodes(MountNodesRequest $request, Mount $mount): array public function addNodes(MountNodesRequest $request, Mount $mount): array
{ {
@ -165,12 +142,9 @@ class MountController extends ApplicationApiController
} }
/** /**
* ? * Detaches eggs from a mount.
* *
* @param \Pterodactyl\Http\Requests\Api\Application\Mounts\MountEggsRequest $request * @throws \Illuminate\Contracts\Container\BindingResolutionException
* @param \Pterodactyl\Models\Mount $mount
*
* @return array
*/ */
public function deleteEggs(MountEggsRequest $request, Mount $mount): array public function deleteEggs(MountEggsRequest $request, Mount $mount): array
{ {
@ -187,12 +161,9 @@ class MountController extends ApplicationApiController
} }
/** /**
* ? * Detaches nodes from a mount.
* *
* @param \Pterodactyl\Http\Requests\Api\Application\Mounts\MountNodesRequest $request * @throws \Illuminate\Contracts\Container\BindingResolutionException
* @param \Pterodactyl\Models\Mount $mount
*
* @return array
*/ */
public function deleteNodes(MountNodesRequest $request, Mount $mount): array public function deleteNodes(MountNodesRequest $request, Mount $mount): array
{ {

View File

@ -3,7 +3,7 @@
namespace Pterodactyl\Http\Controllers\Api\Application\Nests; namespace Pterodactyl\Http\Controllers\Api\Application\Nests;
use Pterodactyl\Models\Nest; use Pterodactyl\Models\Nest;
use Illuminate\Http\JsonResponse; use Illuminate\Http\Response;
use Pterodactyl\Services\Nests\NestUpdateService; use Pterodactyl\Services\Nests\NestUpdateService;
use Pterodactyl\Services\Nests\NestCreationService; use Pterodactyl\Services\Nests\NestCreationService;
use Pterodactyl\Services\Nests\NestDeletionService; use Pterodactyl\Services\Nests\NestDeletionService;
@ -13,31 +13,16 @@ use Pterodactyl\Http\Requests\Api\Application\Nests\GetNestRequest;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Pterodactyl\Http\Requests\Api\Application\Nests\GetNestsRequest; use Pterodactyl\Http\Requests\Api\Application\Nests\GetNestsRequest;
use Pterodactyl\Http\Requests\Api\Application\Nests\StoreNestRequest; use Pterodactyl\Http\Requests\Api\Application\Nests\StoreNestRequest;
use Pterodactyl\Http\Requests\Api\Application\Nests\UpdateNestRequest;
use Pterodactyl\Http\Requests\Api\Application\Nests\DeleteNestRequest; use Pterodactyl\Http\Requests\Api\Application\Nests\DeleteNestRequest;
use Pterodactyl\Http\Requests\Api\Application\Nests\UpdateNestRequest;
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController; use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
class NestController extends ApplicationApiController class NestController extends ApplicationApiController
{ {
/** private NestRepositoryInterface $repository;
* @var \Pterodactyl\Contracts\Repository\NestRepositoryInterface protected NestCreationService $nestCreationService;
*/ protected NestDeletionService $nestDeletionService;
private $repository; protected NestUpdateService $nestUpdateService;
/**
* @var \Pterodactyl\Services\Nests\NestCreationService
*/
protected $nestCreationService;
/**
* @var \Pterodactyl\Services\Nests\NestDeletionService
*/
protected $nestDeletionService;
/**
* @var \Pterodactyl\Services\Nests\NestUpdateService
*/
protected $nestUpdateService;
/** /**
* NestController constructor. * NestController constructor.
@ -59,6 +44,8 @@ class NestController extends ApplicationApiController
/** /**
* Return all Nests that exist on the Panel. * Return all Nests that exist on the Panel.
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function index(GetNestsRequest $request): array public function index(GetNestsRequest $request): array
{ {
@ -79,10 +66,6 @@ class NestController extends ApplicationApiController
/** /**
* Return information about a single Nest model. * Return information about a single Nest model.
* *
* @param \Pterodactyl\Http\Requests\Api\Application\Nests\GetNestRequest $request
* @param \Pterodactyl\Models\Nest $nest
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException * @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function view(GetNestRequest $request, Nest $nest): array public function view(GetNestRequest $request, Nest $nest): array
@ -95,9 +78,6 @@ class NestController extends ApplicationApiController
/** /**
* Creates a new nest. * Creates a new nest.
* *
* @param \Pterodactyl\Http\Requests\Api\Application\Nests\StoreNestRequest $request
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException * @throws \Illuminate\Contracts\Container\BindingResolutionException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Model\DataValidationException
*/ */
@ -113,10 +93,6 @@ class NestController extends ApplicationApiController
/** /**
* Updates an existing nest. * Updates an existing nest.
* *
* @param \Pterodactyl\Http\Requests\Api\Application\Nests\UpdateNestRequest $request
* @param \Pterodactyl\Models\Nest $nest
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException * @throws \Illuminate\Contracts\Container\BindingResolutionException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
@ -133,16 +109,12 @@ class NestController extends ApplicationApiController
/** /**
* Deletes an existing nest. * Deletes an existing nest.
* *
* @param \Pterodactyl\Http\Requests\Api\Application\Nests\DeleteNestRequest $request
* @param \Pterodactyl\Models\Nest $nest
*
* @return \Illuminate\Http\JsonResponse
* @throws \Pterodactyl\Exceptions\Service\HasActiveServersException * @throws \Pterodactyl\Exceptions\Service\HasActiveServersException
*/ */
public function delete(DeleteNestRequest $request, Nest $nest): JsonResponse public function delete(DeleteNestRequest $request, Nest $nest): Response
{ {
$this->nestDeletionService->handle($nest->id); $this->nestDeletionService->handle($nest->id);
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); return $this->returnNoContent();
} }
} }

View File

@ -3,7 +3,7 @@
namespace Pterodactyl\Http\Controllers\Api\Application\Nodes; namespace Pterodactyl\Http\Controllers\Api\Application\Nodes;
use Pterodactyl\Models\Node; use Pterodactyl\Models\Node;
use Illuminate\Http\JsonResponse; use Illuminate\Http\Response;
use Pterodactyl\Models\Allocation; use Pterodactyl\Models\Allocation;
use Pterodactyl\Services\Allocations\AssignmentService; use Pterodactyl\Services\Allocations\AssignmentService;
use Pterodactyl\Services\Allocations\AllocationDeletionService; use Pterodactyl\Services\Allocations\AllocationDeletionService;
@ -15,21 +15,11 @@ use Pterodactyl\Http\Requests\Api\Application\Allocations\DeleteAllocationReques
class AllocationController extends ApplicationApiController class AllocationController extends ApplicationApiController
{ {
/** private AssignmentService $assignmentService;
* @var \Pterodactyl\Services\Allocations\AssignmentService private AllocationDeletionService $deletionService;
*/
private $assignmentService;
/**
* @var \Pterodactyl\Services\Allocations\AllocationDeletionService
*/
private $deletionService;
/** /**
* AllocationController constructor. * AllocationController constructor.
*
* @param \Pterodactyl\Services\Allocations\AssignmentService $assignmentService
* @param \Pterodactyl\Services\Allocations\AllocationDeletionService $deletionService
*/ */
public function __construct( public function __construct(
AssignmentService $assignmentService, AssignmentService $assignmentService,
@ -44,10 +34,6 @@ class AllocationController extends ApplicationApiController
/** /**
* Return all of the allocations that exist for a given node. * Return all of the allocations that exist for a given node.
* *
* @param \Pterodactyl\Http\Requests\Api\Application\Allocations\GetAllocationsRequest $request
* @param \Pterodactyl\Models\Node $node
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException * @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function index(GetAllocationsRequest $request, Node $node): array public function index(GetAllocationsRequest $request, Node $node): array
@ -62,36 +48,28 @@ class AllocationController extends ApplicationApiController
/** /**
* Store new allocations for a given node. * Store new allocations for a given node.
* *
* @param \Pterodactyl\Http\Requests\Api\Application\Allocations\StoreAllocationRequest $request * @throws \Pterodactyl\Exceptions\DisplayException
* @param \Pterodactyl\Models\Node $node
* @return \Illuminate\Http\JsonResponse
*
* @throws \Pterodactyl\Exceptions\Service\Allocation\CidrOutOfRangeException * @throws \Pterodactyl\Exceptions\Service\Allocation\CidrOutOfRangeException
* @throws \Pterodactyl\Exceptions\Service\Allocation\InvalidPortMappingException * @throws \Pterodactyl\Exceptions\Service\Allocation\InvalidPortMappingException
* @throws \Pterodactyl\Exceptions\Service\Allocation\PortOutOfRangeException * @throws \Pterodactyl\Exceptions\Service\Allocation\PortOutOfRangeException
* @throws \Pterodactyl\Exceptions\Service\Allocation\TooManyPortsInRangeException * @throws \Pterodactyl\Exceptions\Service\Allocation\TooManyPortsInRangeException
*/ */
public function store(StoreAllocationRequest $request, Node $node): JsonResponse public function store(StoreAllocationRequest $request, Node $node): Response
{ {
$this->assignmentService->handle($node, $request->validated()); $this->assignmentService->handle($node, $request->validated());
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); return $this->returnNoContent();
} }
/** /**
* Delete a specific allocation from the Panel. * Delete a specific allocation from the Panel.
* *
* @param \Pterodactyl\Http\Requests\Api\Application\Allocations\DeleteAllocationRequest $request
* @param \Pterodactyl\Models\Node $node
* @param \Pterodactyl\Models\Allocation $allocation
* @return \Illuminate\Http\JsonResponse
*
* @throws \Pterodactyl\Exceptions\Service\Allocation\ServerUsingAllocationException * @throws \Pterodactyl\Exceptions\Service\Allocation\ServerUsingAllocationException
*/ */
public function delete(DeleteAllocationRequest $request, Node $node, Allocation $allocation): JsonResponse public function delete(DeleteAllocationRequest $request, Node $node, Allocation $allocation): Response
{ {
$this->deletionService->handle($allocation); $this->deletionService->handle($allocation);
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); return $this->returnNoContent();
} }
} }

View File

@ -14,10 +14,9 @@ class NodeConfigurationController extends ApplicationApiController
* to remote machines so long as an API key is provided to the machine to make the request * to remote machines so long as an API key is provided to the machine to make the request
* with, and the node is known. * with, and the node is known.
* *
* @return string
* @throws \Illuminate\Contracts\Container\BindingResolutionException * @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function __invoke(GetNodeRequest $request, Node $node) public function __invoke(GetNodeRequest $request, Node $node): string
{ {
if ($request->query('format') === 'yaml') { if ($request->query('format') === 'yaml') {
return $node->getYamlConfiguration(); return $node->getYamlConfiguration();

View File

@ -3,6 +3,7 @@
namespace Pterodactyl\Http\Controllers\Api\Application\Nodes; namespace Pterodactyl\Http\Controllers\Api\Application\Nodes;
use Pterodactyl\Models\Node; use Pterodactyl\Models\Node;
use Illuminate\Http\Response;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Spatie\QueryBuilder\QueryBuilder; use Spatie\QueryBuilder\QueryBuilder;
use Pterodactyl\Services\Nodes\NodeUpdateService; use Pterodactyl\Services\Nodes\NodeUpdateService;
@ -20,34 +21,19 @@ use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
class NodeController extends ApplicationApiController class NodeController extends ApplicationApiController
{ {
/** private NodeRepositoryInterface $repository;
* @var \Pterodactyl\Services\Nodes\NodeCreationService private NodeCreationService $creationService;
*/ private NodeDeletionService $deletionService;
private $creationService; private NodeUpdateService $updateService;
/**
* @var \Pterodactyl\Services\Nodes\NodeDeletionService
*/
private $deletionService;
/**
* @var \Pterodactyl\Contracts\Repository\NodeRepositoryInterface
*/
private $repository;
/**
* @var \Pterodactyl\Services\Nodes\NodeUpdateService
*/
private $updateService;
/** /**
* NodeController constructor. * NodeController constructor.
*/ */
public function __construct( public function __construct(
NodeRepositoryInterface $repository,
NodeCreationService $creationService, NodeCreationService $creationService,
NodeDeletionService $deletionService, NodeDeletionService $deletionService,
NodeUpdateService $updateService, NodeUpdateService $updateService
NodeRepositoryInterface $repository
) { ) {
parent::__construct(); parent::__construct();
@ -59,6 +45,8 @@ class NodeController extends ApplicationApiController
/** /**
* Return all of the nodes currently available on the Panel. * Return all of the nodes currently available on the Panel.
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function index(GetNodesRequest $request): array public function index(GetNodesRequest $request): array
{ {
@ -81,6 +69,8 @@ class NodeController extends ApplicationApiController
/** /**
* Return data for a single instance of a node. * Return data for a single instance of a node.
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function view(GetNodeRequest $request, Node $node): array public function view(GetNodeRequest $request, Node $node): array
{ {
@ -94,6 +84,7 @@ class NodeController extends ApplicationApiController
* status response on success. * status response on success.
* *
* @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function store(StoreNodeRequest $request): JsonResponse public function store(StoreNodeRequest $request): JsonResponse
{ {
@ -133,10 +124,10 @@ class NodeController extends ApplicationApiController
* *
* @throws \Pterodactyl\Exceptions\Service\HasActiveServersException * @throws \Pterodactyl\Exceptions\Service\HasActiveServersException
*/ */
public function delete(DeleteNodeRequest $request, Node $node): JsonResponse public function delete(DeleteNodeRequest $request, Node $node): Response
{ {
$this->deletionService->handle($node); $this->deletionService->handle($node);
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); return $this->returnNoContent();
} }
} }

View File

@ -9,10 +9,7 @@ use Pterodactyl\Http\Requests\Api\Application\Nodes\GetDeployableNodesRequest;
class NodeDeploymentController extends ApplicationApiController class NodeDeploymentController extends ApplicationApiController
{ {
/** private FindViableNodesService $viableNodesService;
* @var \Pterodactyl\Services\Deployment\FindViableNodesService
*/
private $viableNodesService;
/** /**
* NodeDeploymentController constructor. * NodeDeploymentController constructor.
@ -29,6 +26,7 @@ class NodeDeploymentController extends ApplicationApiController
* similarly to the server creation process, but allows you to pass the deployment object * similarly to the server creation process, but allows you to pass the deployment object
* to this endpoint and get back a list of all Nodes satisfying the requirements. * to this endpoint and get back a list of all Nodes satisfying the requirements.
* *
* @throws \Illuminate\Contracts\Container\BindingResolutionException
* @throws \Pterodactyl\Exceptions\Service\Deployment\NoViableNodeException * @throws \Pterodactyl\Exceptions\Service\Deployment\NoViableNodeException
*/ */
public function __invoke(GetDeployableNodesRequest $request): array public function __invoke(GetDeployableNodesRequest $request): array

View File

@ -2,6 +2,7 @@
namespace Pterodactyl\Http\Controllers\Api\Application\Roles; namespace Pterodactyl\Http\Controllers\Api\Application\Roles;
use Illuminate\Http\Response;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Pterodactyl\Models\AdminRole; use Pterodactyl\Models\AdminRole;
use Pterodactyl\Transformers\Api\Application\AdminRoleTransformer; use Pterodactyl\Transformers\Api\Application\AdminRoleTransformer;
@ -82,10 +83,10 @@ class RoleController extends ApplicationApiController
* *
* @throws \Exception * @throws \Exception
*/ */
public function delete(DeleteRoleRequest $request, AdminRole $role): JsonResponse public function delete(DeleteRoleRequest $request, AdminRole $role): Response
{ {
$role->delete(); $role->delete();
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); return $this->returnNoContent();
} }
} }

View File

@ -18,20 +18,9 @@ use Pterodactyl\Http\Requests\Api\Application\Servers\Databases\StoreServerDatab
class DatabaseController extends ApplicationApiController class DatabaseController extends ApplicationApiController
{ {
/** private DatabaseManagementService $databaseManagementService;
* @var \Pterodactyl\Services\Databases\DatabaseManagementService private DatabasePasswordService $databasePasswordService;
*/ private DatabaseRepositoryInterface $repository;
private $databaseManagementService;
/**
* @var \Pterodactyl\Services\Databases\DatabasePasswordService
*/
private $databasePasswordService;
/**
* @var \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface
*/
private $repository;
/** /**
* DatabaseController constructor. * DatabaseController constructor.
@ -51,6 +40,8 @@ class DatabaseController extends ApplicationApiController
/** /**
* Return a listing of all databases currently available to a single * Return a listing of all databases currently available to a single
* server. * server.
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function index(GetServerDatabasesRequest $request, Server $server): array public function index(GetServerDatabasesRequest $request, Server $server): array
{ {
@ -61,6 +52,8 @@ class DatabaseController extends ApplicationApiController
/** /**
* Return a single server database. * Return a single server database.
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function view(GetServerDatabaseRequest $request, Server $server, Database $database): array public function view(GetServerDatabaseRequest $request, Server $server, Database $database): array
{ {
@ -74,11 +67,11 @@ class DatabaseController extends ApplicationApiController
* *
* @throws \Throwable * @throws \Throwable
*/ */
public function resetPassword(ServerDatabaseWriteRequest $request, Server $server, Database $database): JsonResponse public function resetPassword(ServerDatabaseWriteRequest $request, Server $server, Database $database): Response
{ {
$this->databasePasswordService->handle($database); $this->databasePasswordService->handle($database);
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); return $this->returnNoContent();
} }
/** /**
@ -106,12 +99,12 @@ class DatabaseController extends ApplicationApiController
/** /**
* Handle a request to delete a specific server database from the Panel. * Handle a request to delete a specific server database from the Panel.
* *
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException * @throws \Exception
*/ */
public function delete(ServerDatabaseWriteRequest $request, Database $database): JsonResponse public function delete(ServerDatabaseWriteRequest $request, Database $database): Response
{ {
$this->databaseManagementService->delete($database); $this->databaseManagementService->delete($database);
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); return $this->returnNoContent();
} }
} }

View File

@ -10,6 +10,8 @@ class ExternalServerController extends ApplicationApiController
{ {
/** /**
* Retrieve a specific server from the database using its external ID. * Retrieve a specific server from the database using its external ID.
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function index(GetExternalServerRequest $request): array public function index(GetExternalServerRequest $request): array
{ {

View File

@ -92,11 +92,6 @@ class ServerController extends ApplicationApiController
/** /**
* Deletes a server. * Deletes a server.
* *
* @param \Pterodactyl\Http\Requests\Api\Application\Servers\ServerWriteRequest $request
* @param \Pterodactyl\Models\Server $server
* @param string $force
*
* @return \Illuminate\Http\Response
* @throws \Pterodactyl\Exceptions\DisplayException * @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Throwable * @throws \Throwable
*/ */

View File

@ -12,15 +12,8 @@ use Pterodactyl\Http\Requests\Api\Application\Servers\UpdateServerBuildConfigura
class ServerDetailsController extends ApplicationApiController class ServerDetailsController extends ApplicationApiController
{ {
/** private BuildModificationService $buildModificationService;
* @var \Pterodactyl\Services\Servers\BuildModificationService private DetailsModificationService $detailsModificationService;
*/
private $buildModificationService;
/**
* @var \Pterodactyl\Services\Servers\DetailsModificationService
*/
private $detailsModificationService;
/** /**
* ServerDetailsController constructor. * ServerDetailsController constructor.
@ -38,9 +31,7 @@ class ServerDetailsController extends ApplicationApiController
/** /**
* Update the details for a specific server. * Update the details for a specific server.
* *
* @throws \Pterodactyl\Exceptions\DisplayException * @throws \Throwable
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/ */
public function details(UpdateServerDetailsRequest $request, Server $server): array public function details(UpdateServerDetailsRequest $request, Server $server): array
{ {
@ -57,13 +48,7 @@ class ServerDetailsController extends ApplicationApiController
/** /**
* Update the build details for a specific server. * Update the build details for a specific server.
* *
* @param \Pterodactyl\Http\Requests\Api\Application\Servers\UpdateServerBuildConfigurationRequest $request * @throws \Throwable
* @param \Pterodactyl\Models\Server $server
* @return array
*
* @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/ */
public function build(UpdateServerBuildConfigurationRequest $request, Server $server): array public function build(UpdateServerBuildConfigurationRequest $request, Server $server): array
{ {

View File

@ -11,15 +11,8 @@ use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
class ServerManagementController extends ApplicationApiController class ServerManagementController extends ApplicationApiController
{ {
/** private ReinstallServerService $reinstallServerService;
* @var \Pterodactyl\Services\Servers\ReinstallServerService private SuspensionService $suspensionService;
*/
private $reinstallServerService;
/**
* @var \Pterodactyl\Services\Servers\SuspensionService
*/
private $suspensionService;
/** /**
* SuspensionController constructor. * SuspensionController constructor.
@ -61,9 +54,7 @@ class ServerManagementController extends ApplicationApiController
/** /**
* Mark a server as needing to be reinstalled. * Mark a server as needing to be reinstalled.
* *
* @throws \Pterodactyl\Exceptions\DisplayException * @throws \Throwable
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/ */
public function reinstall(ServerWriteRequest $request, Server $server): Response public function reinstall(ServerWriteRequest $request, Server $server): Response
{ {

View File

@ -11,10 +11,7 @@ use Pterodactyl\Http\Requests\Api\Application\Servers\UpdateServerStartupRequest
class StartupController extends ApplicationApiController class StartupController extends ApplicationApiController
{ {
/** private StartupModificationService $modificationService;
* @var \Pterodactyl\Services\Servers\StartupModificationService
*/
private $modificationService;
/** /**
* StartupController constructor. * StartupController constructor.
@ -29,10 +26,7 @@ class StartupController extends ApplicationApiController
/** /**
* Update the startup and environment settings for a specific server. * Update the startup and environment settings for a specific server.
* *
* @throws \Illuminate\Validation\ValidationException * @throws \Throwable
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/ */
public function index(UpdateServerStartupRequest $request, Server $server): array public function index(UpdateServerStartupRequest $request, Server $server): array
{ {

View File

@ -10,6 +10,8 @@ class ExternalUserController extends ApplicationApiController
{ {
/** /**
* Retrieve a specific user from the database using their external ID. * Retrieve a specific user from the database using their external ID.
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function index(GetExternalUserRequest $request): array public function index(GetExternalUserRequest $request): array
{ {

View File

@ -3,6 +3,7 @@
namespace Pterodactyl\Http\Controllers\Api\Application\Users; namespace Pterodactyl\Http\Controllers\Api\Application\Users;
use Pterodactyl\Models\User; use Pterodactyl\Models\User;
use Illuminate\Http\Response;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Spatie\QueryBuilder\QueryBuilder; use Spatie\QueryBuilder\QueryBuilder;
use Pterodactyl\Services\Users\UserUpdateService; use Pterodactyl\Services\Users\UserUpdateService;
@ -20,25 +21,10 @@ use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
class UserController extends ApplicationApiController class UserController extends ApplicationApiController
{ {
/** private UserRepositoryInterface $repository;
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface private UserCreationService $creationService;
*/ private UserDeletionService $deletionService;
private $repository; private UserUpdateService $updateService;
/**
* @var \Pterodactyl\Services\Users\UserCreationService
*/
private $creationService;
/**
* @var \Pterodactyl\Services\Users\UserDeletionService
*/
private $deletionService;
/**
* @var \Pterodactyl\Services\Users\UserUpdateService
*/
private $updateService;
/** /**
* UserController constructor. * UserController constructor.
@ -62,9 +48,6 @@ class UserController extends ApplicationApiController
* of a collection of users including any defined relations passed in * of a collection of users including any defined relations passed in
* the request. * the request.
* *
* @param \Pterodactyl\Http\Requests\Api\Application\Users\GetUsersRequest $request
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException * @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function index(GetUsersRequest $request): array public function index(GetUsersRequest $request): array
@ -89,6 +72,8 @@ class UserController extends ApplicationApiController
/** /**
* Handle a request to view a single user. Includes any relations that * Handle a request to view a single user. Includes any relations that
* were defined in the request. * were defined in the request.
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function view(GetUserRequest $request, User $user): array public function view(GetUserRequest $request, User $user): array
{ {
@ -146,10 +131,10 @@ class UserController extends ApplicationApiController
* *
* @throws \Pterodactyl\Exceptions\DisplayException * @throws \Pterodactyl\Exceptions\DisplayException
*/ */
public function delete(DeleteUserRequest $request, User $user): JsonResponse public function delete(DeleteUserRequest $request, User $user): Response
{ {
$this->deletionService->handle($user); $this->deletionService->handle($user);
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); return $this->returnNoContent();
} }
} }

View File

@ -7,15 +7,10 @@ use Pterodactyl\Services\Helpers\SoftwareVersionService;
class VersionController extends ApplicationApiController class VersionController extends ApplicationApiController
{ {
/**
* @var \Pterodactyl\Services\Helpers\SoftwareVersionService
*/
private SoftwareVersionService $softwareVersionService; private SoftwareVersionService $softwareVersionService;
/** /**
* VersionController constructor. * VersionController constructor.
*
* @param \Pterodactyl\Services\Helpers\SoftwareVersionService $softwareVersionService
*/ */
public function __construct(SoftwareVersionService $softwareVersionService) public function __construct(SoftwareVersionService $softwareVersionService)
{ {
@ -26,8 +21,6 @@ class VersionController extends ApplicationApiController
/** /**
* Returns version information. * Returns version information.
*
* @return \Illuminate\Http\JsonResponse
*/ */
public function __invoke(): JsonResponse public function __invoke(): JsonResponse
{ {

View File

@ -4,8 +4,8 @@ namespace Pterodactyl\Http\Controllers\Api\Client;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Http\Response; use Illuminate\Http\Response;
use Illuminate\Auth\AuthManager;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Illuminate\Auth\SessionGuard;
use Pterodactyl\Services\Users\UserUpdateService; use Pterodactyl\Services\Users\UserUpdateService;
use Pterodactyl\Transformers\Api\Client\AccountTransformer; use Pterodactyl\Transformers\Api\Client\AccountTransformer;
use Pterodactyl\Http\Requests\Api\Client\Account\UpdateEmailRequest; use Pterodactyl\Http\Requests\Api\Client\Account\UpdateEmailRequest;
@ -13,27 +13,25 @@ use Pterodactyl\Http\Requests\Api\Client\Account\UpdatePasswordRequest;
class AccountController extends ClientApiController class AccountController extends ClientApiController
{ {
/** private SessionGuard $sessionGuard;
* @var \Pterodactyl\Services\Users\UserUpdateService private UserUpdateService $updateService;
*/
private $updateService;
/**
* @var \Illuminate\Auth\SessionGuard
*/
private $sessionGuard;
/** /**
* AccountController constructor. * AccountController constructor.
*/ */
public function __construct(AuthManager $sessionGuard, UserUpdateService $updateService) public function __construct(SessionGuard $sessionGuard, UserUpdateService $updateService)
{ {
parent::__construct(); parent::__construct();
$this->updateService = $updateService;
$this->sessionGuard = $sessionGuard; $this->sessionGuard = $sessionGuard;
$this->updateService = $updateService;
} }
/**
* Get's information about the currently authenticated user.
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function index(Request $request): array public function index(Request $request): array
{ {
return $this->fractal->item($request->user()) return $this->fractal->item($request->user())
@ -51,7 +49,7 @@ class AccountController extends ClientApiController
{ {
$this->updateService->handle($request->user(), $request->validated()); $this->updateService->handle($request->user(), $request->validated());
return new JsonResponse([], Response::HTTP_NO_CONTENT); return $this->returnNoContent();
} }
/** /**
@ -67,6 +65,6 @@ class AccountController extends ClientApiController
$this->sessionGuard->logoutOtherDevices($request->input('password')); $this->sessionGuard->logoutOtherDevices($request->input('password'));
return new JsonResponse([], Response::HTTP_NO_CONTENT); return $this->returnNoContent();
} }
} }

View File

@ -2,8 +2,8 @@
namespace Pterodactyl\Http\Controllers\Api\Client; namespace Pterodactyl\Http\Controllers\Api\Client;
use Illuminate\Http\Response;
use Pterodactyl\Models\ApiKey; use Pterodactyl\Models\ApiKey;
use Illuminate\Http\JsonResponse;
use Pterodactyl\Exceptions\DisplayException; use Pterodactyl\Exceptions\DisplayException;
use Illuminate\Contracts\Encryption\Encrypter; use Illuminate\Contracts\Encryption\Encrypter;
use Pterodactyl\Services\Api\KeyCreationService; use Pterodactyl\Services\Api\KeyCreationService;
@ -15,42 +15,31 @@ use Pterodactyl\Http\Requests\Api\Client\Account\StoreApiKeyRequest;
class ApiKeyController extends ClientApiController class ApiKeyController extends ClientApiController
{ {
/** private Encrypter $encrypter;
* @var \Pterodactyl\Services\Api\KeyCreationService private ApiKeyRepository $repository;
*/ private KeyCreationService $keyCreationService;
private $keyCreationService;
/**
* @var \Illuminate\Contracts\Encryption\Encrypter
*/
private $encrypter;
/**
* @var \Pterodactyl\Repositories\Eloquent\ApiKeyRepository
*/
private $repository;
/** /**
* ApiKeyController constructor. * ApiKeyController constructor.
*/ */
public function __construct( public function __construct(
Encrypter $encrypter, Encrypter $encrypter,
KeyCreationService $keyCreationService, ApiKeyRepository $repository,
ApiKeyRepository $repository KeyCreationService $keyCreationService
) { ) {
parent::__construct(); parent::__construct();
$this->encrypter = $encrypter; $this->encrypter = $encrypter;
$this->keyCreationService = $keyCreationService;
$this->repository = $repository; $this->repository = $repository;
$this->keyCreationService = $keyCreationService;
} }
/** /**
* Returns all of the API keys that exist for the given client. * Returns all of the API keys that exist for the given client.
* *
* @return array * @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function index(ClientApiRequest $request) public function index(ClientApiRequest $request): array
{ {
return $this->fractal->collection($request->user()->apiKeys) return $this->fractal->collection($request->user()->apiKeys)
->transformWith($this->getTransformer(ApiKeyTransformer::class)) ->transformWith($this->getTransformer(ApiKeyTransformer::class))
@ -60,12 +49,11 @@ class ApiKeyController extends ClientApiController
/** /**
* Store a new API key for a user's account. * Store a new API key for a user's account.
* *
* @return array
*
* @throws \Pterodactyl\Exceptions\DisplayException * @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function store(StoreApiKeyRequest $request) public function store(StoreApiKeyRequest $request): array
{ {
if ($request->user()->apiKeys->count() >= 5) { if ($request->user()->apiKeys->count() >= 5) {
throw new DisplayException('You have reached the account limit for number of API keys.'); throw new DisplayException('You have reached the account limit for number of API keys.');
@ -87,10 +75,8 @@ class ApiKeyController extends ClientApiController
/** /**
* Deletes a given API key. * Deletes a given API key.
*
* @return \Illuminate\Http\JsonResponse
*/ */
public function delete(ClientApiRequest $request, string $identifier) public function delete(ClientApiRequest $request, string $identifier): Response
{ {
$response = $this->repository->deleteWhere([ $response = $this->repository->deleteWhere([
'key_type' => ApiKey::TYPE_ACCOUNT, 'key_type' => ApiKey::TYPE_ACCOUNT,
@ -102,6 +88,6 @@ class ApiKeyController extends ClientApiController
throw new NotFoundHttpException(); throw new NotFoundHttpException();
} }
return JsonResponse::create([], JsonResponse::HTTP_NO_CONTENT); return $this->returnNoContent();
} }
} }

View File

@ -15,7 +15,7 @@ abstract class ClientApiController extends ApplicationApiController
* *
* @return string[] * @return string[]
*/ */
protected function getIncludesForTransformer(BaseClientTransformer $transformer, array $merge = []) protected function getIncludesForTransformer(BaseClientTransformer $transformer, array $merge = []): array
{ {
$filtered = array_filter($this->parseIncludes(), function ($datum) use ($transformer) { $filtered = array_filter($this->parseIncludes(), function ($datum) use ($transformer) {
return in_array($datum, $transformer->getAvailableIncludes()); return in_array($datum, $transformer->getAvailableIncludes());
@ -29,7 +29,7 @@ abstract class ClientApiController extends ApplicationApiController
* *
* @return string[] * @return string[]
*/ */
protected function parseIncludes() protected function parseIncludes(): array
{ {
$includes = $this->request->query('include') ?? []; $includes = $this->request->query('include') ?? [];
@ -45,9 +45,9 @@ abstract class ClientApiController extends ApplicationApiController
/** /**
* Return an instance of an application transformer. * Return an instance of an application transformer.
* *
* @return \Pterodactyl\Transformers\Api\Client\BaseClientTransformer * @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function getTransformer(string $abstract) public function getTransformer(string $abstract): BaseClientTransformer
{ {
/** @var \Pterodactyl\Transformers\Api\Client\BaseClientTransformer $transformer */ /** @var \Pterodactyl\Transformers\Api\Client\BaseClientTransformer $transformer */
$transformer = Container::getInstance()->make($abstract); $transformer = Container::getInstance()->make($abstract);

View File

@ -13,10 +13,7 @@ use Pterodactyl\Http\Requests\Api\Client\GetServersRequest;
class ClientController extends ClientApiController class ClientController extends ClientApiController
{ {
/** private ServerRepository $repository;
* @var \Pterodactyl\Repositories\Eloquent\ServerRepository
*/
private $repository;
/** /**
* ClientController constructor. * ClientController constructor.
@ -31,6 +28,8 @@ class ClientController extends ClientApiController
/** /**
* Return all of the servers available to the client making the API * Return all of the servers available to the client making the API
* request, including servers the user has access to as a subuser. * request, including servers the user has access to as a subuser.
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function index(GetServersRequest $request): array public function index(GetServersRequest $request): array
{ {
@ -75,10 +74,8 @@ class ClientController extends ClientApiController
/** /**
* Returns all of the subuser permissions available on the system. * Returns all of the subuser permissions available on the system.
*
* @return array
*/ */
public function permissions() public function permissions(): array
{ {
return [ return [
'object' => 'system_permissions', 'object' => 'system_permissions',

View File

@ -3,6 +3,7 @@
namespace Pterodactyl\Http\Controllers\Api\Client\Servers; namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Pterodactyl\Models\Backup; use Pterodactyl\Models\Backup;
use Pterodactyl\Models\Server; use Pterodactyl\Models\Server;
use Pterodactyl\Models\AuditLog; use Pterodactyl\Models\AuditLog;
@ -20,25 +21,10 @@ use Pterodactyl\Http\Requests\Api\Client\Servers\Backups\StoreBackupRequest;
class BackupController extends ClientApiController class BackupController extends ClientApiController
{ {
/** private InitiateBackupService $initiateBackupService;
* @var \Pterodactyl\Services\Backups\InitiateBackupService private DeleteBackupService $deleteBackupService;
*/ private DownloadLinkService $downloadLinkService;
private $initiateBackupService; private DaemonBackupRepository $repository;
/**
* @var \Pterodactyl\Services\Backups\DeleteBackupService
*/
private $deleteBackupService;
/**
* @var \Pterodactyl\Services\Backups\DownloadLinkService
*/
private $downloadLinkService;
/**
* @var \Pterodactyl\Repositories\Wings\DaemonBackupRepository
*/
private $repository;
/** /**
* BackupController constructor. * BackupController constructor.
@ -61,9 +47,8 @@ class BackupController extends ClientApiController
* Returns all of the backups for a given server instance in a paginated * Returns all of the backups for a given server instance in a paginated
* result set. * result set.
* *
* @throws \Spatie\Fractalistic\Exceptions\InvalidTransformation
* @throws \Spatie\Fractalistic\Exceptions\NoTransformerSpecified
* @throws \Illuminate\Auth\Access\AuthorizationException * @throws \Illuminate\Auth\Access\AuthorizationException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function index(Request $request, Server $server): array public function index(Request $request, Server $server): array
{ {
@ -81,8 +66,6 @@ class BackupController extends ClientApiController
/** /**
* Starts the backup process for a server. * Starts the backup process for a server.
* *
* @throws \Spatie\Fractalistic\Exceptions\InvalidTransformation
* @throws \Spatie\Fractalistic\Exceptions\NoTransformerSpecified
* @throws \Throwable * @throws \Throwable
*/ */
public function store(StoreBackupRequest $request, Server $server): array public function store(StoreBackupRequest $request, Server $server): array
@ -108,9 +91,8 @@ class BackupController extends ClientApiController
/** /**
* Returns information about a single backup. * Returns information about a single backup.
* *
* @throws \Spatie\Fractalistic\Exceptions\InvalidTransformation
* @throws \Spatie\Fractalistic\Exceptions\NoTransformerSpecified
* @throws \Illuminate\Auth\Access\AuthorizationException * @throws \Illuminate\Auth\Access\AuthorizationException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function view(Request $request, Server $server, Backup $backup): array public function view(Request $request, Server $server, Backup $backup): array
{ {
@ -129,7 +111,7 @@ class BackupController extends ClientApiController
* *
* @throws \Throwable * @throws \Throwable
*/ */
public function delete(Request $request, Server $server, Backup $backup): JsonResponse public function delete(Request $request, Server $server, Backup $backup): Response
{ {
if (!$request->user()->can(Permission::ACTION_BACKUP_DELETE, $server)) { if (!$request->user()->can(Permission::ACTION_BACKUP_DELETE, $server)) {
throw new AuthorizationException(); throw new AuthorizationException();
@ -141,7 +123,7 @@ class BackupController extends ClientApiController
$this->deleteBackupService->handle($backup); $this->deleteBackupService->handle($backup);
}); });
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); return $this->returnNoContent();
} }
/** /**
@ -180,7 +162,7 @@ class BackupController extends ClientApiController
* *
* @throws \Throwable * @throws \Throwable
*/ */
public function restore(Request $request, Server $server, Backup $backup): JsonResponse public function restore(Request $request, Server $server, Backup $backup): Response
{ {
if (!$request->user()->can(Permission::ACTION_BACKUP_RESTORE, $server)) { if (!$request->user()->can(Permission::ACTION_BACKUP_RESTORE, $server)) {
throw new AuthorizationException(); throw new AuthorizationException();
@ -212,6 +194,6 @@ class BackupController extends ClientApiController
$this->repository->setServer($server)->restore($backup, $url ?? null, $request->input('truncate') === 'true'); $this->repository->setServer($server)->restore($backup, $url ?? null, $request->input('truncate') === 'true');
}); });
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); return $this->returnNoContent();
} }
} }

View File

@ -14,10 +14,7 @@ use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
class CommandController extends ClientApiController class CommandController extends ClientApiController
{ {
/** private DaemonCommandRepository $repository;
* @var \Pterodactyl\Repositories\Wings\DaemonCommandRepository
*/
private $repository;
/** /**
* CommandController constructor. * CommandController constructor.

View File

@ -42,6 +42,8 @@ class DatabaseController extends ClientApiController
/** /**
* Return all of the databases that belong to the given server. * Return all of the databases that belong to the given server.
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function index(GetDatabasesRequest $request, Server $server): array public function index(GetDatabasesRequest $request, Server $server): array
{ {
@ -71,11 +73,9 @@ class DatabaseController extends ClientApiController
* Rotates the password for the given server model and returns a fresh instance to * Rotates the password for the given server model and returns a fresh instance to
* the caller. * the caller.
* *
* @return array
*
* @throws \Throwable * @throws \Throwable
*/ */
public function rotatePassword(RotatePasswordRequest $request, Server $server, Database $database) public function rotatePassword(RotatePasswordRequest $request, Server $server, Database $database): array
{ {
$this->passwordService->handle($database); $this->passwordService->handle($database);
$database->refresh(); $database->refresh();
@ -89,12 +89,12 @@ class DatabaseController extends ClientApiController
/** /**
* Removes a database from the server. * Removes a database from the server.
* *
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException * @throws \Exception
*/ */
public function delete(DeleteDatabaseRequest $request, Server $server, Database $database): Response public function delete(DeleteDatabaseRequest $request, Server $server, Database $database): Response
{ {
$this->managementService->delete($database); $this->managementService->delete($database);
return Response::create('', Response::HTTP_NO_CONTENT); return $this->returnNoContent();
} }
} }

View File

@ -6,7 +6,6 @@ use Carbon\CarbonImmutable;
use Illuminate\Http\Response; use Illuminate\Http\Response;
use Pterodactyl\Models\Server; use Pterodactyl\Models\Server;
use Pterodactyl\Models\AuditLog; use Pterodactyl\Models\AuditLog;
use Illuminate\Http\JsonResponse;
use Pterodactyl\Services\Nodes\NodeJWTService; use Pterodactyl\Services\Nodes\NodeJWTService;
use Illuminate\Contracts\Routing\ResponseFactory; use Illuminate\Contracts\Routing\ResponseFactory;
use Pterodactyl\Repositories\Wings\DaemonFileRepository; use Pterodactyl\Repositories\Wings\DaemonFileRepository;
@ -26,28 +25,17 @@ use Pterodactyl\Http\Requests\Api\Client\Servers\Files\WriteFileContentRequest;
class FileController extends ClientApiController class FileController extends ClientApiController
{ {
/** private DaemonFileRepository $fileRepository;
* @var \Pterodactyl\Repositories\Wings\DaemonFileRepository private ResponseFactory $responseFactory;
*/ private NodeJWTService $jwtService;
private $fileRepository;
/**
* @var \Illuminate\Contracts\Routing\ResponseFactory
*/
private $responseFactory;
/**
* @var \Pterodactyl\Services\Nodes\NodeJWTService
*/
private $jwtService;
/** /**
* FileController constructor. * FileController constructor.
*/ */
public function __construct( public function __construct(
DaemonFileRepository $fileRepository,
ResponseFactory $responseFactory, ResponseFactory $responseFactory,
NodeJWTService $jwtService, NodeJWTService $jwtService
DaemonFileRepository $fileRepository
) { ) {
parent::__construct(); parent::__construct();
@ -60,6 +48,7 @@ class FileController extends ClientApiController
* Returns a listing of files in a given directory. * Returns a listing of files in a given directory.
* *
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException * @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function directory(ListFilesRequest $request, Server $server): array public function directory(ListFilesRequest $request, Server $server): array
{ {
@ -91,11 +80,9 @@ class FileController extends ClientApiController
* Generates a one-time token with a link that the user can use to * Generates a one-time token with a link that the user can use to
* download a given file. * download a given file.
* *
* @return array
*
* @throws \Throwable * @throws \Throwable
*/ */
public function download(GetFileContentsRequest $request, Server $server) public function download(GetFileContentsRequest $request, Server $server): array
{ {
$token = $server->audit(AuditLog::SERVER__FILESYSTEM_DOWNLOAD, function (AuditLog $audit, Server $server) use ($request) { $token = $server->audit(AuditLog::SERVER__FILESYSTEM_DOWNLOAD, function (AuditLog $audit, Server $server) use ($request) {
$audit->metadata = ['file' => $request->get('file')]; $audit->metadata = ['file' => $request->get('file')];
@ -124,9 +111,9 @@ class FileController extends ClientApiController
/** /**
* Writes the contents of the specified file to the server. * Writes the contents of the specified file to the server.
* *
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException * @throws \Throwable
*/ */
public function write(WriteFileContentRequest $request, Server $server): JsonResponse public function write(WriteFileContentRequest $request, Server $server): Response
{ {
$server->audit(AuditLog::SERVER__FILESYSTEM_WRITE, function (AuditLog $audit, Server $server) use ($request) { $server->audit(AuditLog::SERVER__FILESYSTEM_WRITE, function (AuditLog $audit, Server $server) use ($request) {
$audit->subaction = 'write_content'; $audit->subaction = 'write_content';
@ -137,7 +124,7 @@ class FileController extends ClientApiController
->putContent($request->get('file'), $request->getContent()); ->putContent($request->get('file'), $request->getContent());
}); });
return new JsonResponse([], Response::HTTP_NO_CONTENT); return $this->returnNoContent();
} }
/** /**
@ -145,7 +132,7 @@ class FileController extends ClientApiController
* *
* @throws \Throwable * @throws \Throwable
*/ */
public function create(CreateFolderRequest $request, Server $server): JsonResponse public function create(CreateFolderRequest $request, Server $server): Response
{ {
$server->audit(AuditLog::SERVER__FILESYSTEM_WRITE, function (AuditLog $audit, Server $server) use ($request) { $server->audit(AuditLog::SERVER__FILESYSTEM_WRITE, function (AuditLog $audit, Server $server) use ($request) {
$audit->subaction = 'create_folder'; $audit->subaction = 'create_folder';
@ -156,7 +143,7 @@ class FileController extends ClientApiController
->createDirectory($request->input('name'), $request->input('root', '/')); ->createDirectory($request->input('name'), $request->input('root', '/'));
}); });
return new JsonResponse([], Response::HTTP_NO_CONTENT); return $this->returnNoContent();
} }
/** /**
@ -164,7 +151,7 @@ class FileController extends ClientApiController
* *
* @throws \Throwable * @throws \Throwable
*/ */
public function rename(RenameFileRequest $request, Server $server): JsonResponse public function rename(RenameFileRequest $request, Server $server): Response
{ {
$server->audit(AuditLog::SERVER__FILESYSTEM_RENAME, function (AuditLog $audit, Server $server) use ($request) { $server->audit(AuditLog::SERVER__FILESYSTEM_RENAME, function (AuditLog $audit, Server $server) use ($request) {
$audit->metadata = ['root' => $request->input('root'), 'files' => $request->input('files')]; $audit->metadata = ['root' => $request->input('root'), 'files' => $request->input('files')];
@ -174,15 +161,15 @@ class FileController extends ClientApiController
->renameFiles($request->input('root'), $request->input('files')); ->renameFiles($request->input('root'), $request->input('files'));
}); });
return new JsonResponse([], Response::HTTP_NO_CONTENT); return $this->returnNoContent();
} }
/** /**
* Copies a file on the server. * Copies a file on the server.
* *
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException * @throws \Throwable
*/ */
public function copy(CopyFileRequest $request, Server $server): JsonResponse public function copy(CopyFileRequest $request, Server $server): Response
{ {
$server->audit(AuditLog::SERVER__FILESYSTEM_WRITE, function (AuditLog $audit, Server $server) use ($request) { $server->audit(AuditLog::SERVER__FILESYSTEM_WRITE, function (AuditLog $audit, Server $server) use ($request) {
$audit->subaction = 'copy_file'; $audit->subaction = 'copy_file';
@ -193,11 +180,11 @@ class FileController extends ClientApiController
->copyFile($request->input('location')); ->copyFile($request->input('location'));
}); });
return new JsonResponse([], Response::HTTP_NO_CONTENT); return $this->returnNoContent();
} }
/** /**
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException * @throws \Throwable
*/ */
public function compress(CompressFilesRequest $request, Server $server): array public function compress(CompressFilesRequest $request, Server $server): array
{ {
@ -220,9 +207,9 @@ class FileController extends ClientApiController
} }
/** /**
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException * @throws \Throwable
*/ */
public function decompress(DecompressFilesRequest $request, Server $server): JsonResponse public function decompress(DecompressFilesRequest $request, Server $server): Response
{ {
$file = $server->audit(AuditLog::SERVER__FILESYSTEM_DECOMPRESS, function (AuditLog $audit, Server $server) use ($request) { $file = $server->audit(AuditLog::SERVER__FILESYSTEM_DECOMPRESS, function (AuditLog $audit, Server $server) use ($request) {
// Allow up to five minutes for this request to process before timing out. // Allow up to five minutes for this request to process before timing out.
@ -234,15 +221,15 @@ class FileController extends ClientApiController
->decompressFile($request->input('root'), $request->input('file')); ->decompressFile($request->input('root'), $request->input('file'));
}); });
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); return $this->returnNoContent();
} }
/** /**
* Deletes files or folders for the server in the given root directory. * Deletes files or folders for the server in the given root directory.
* *
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException * @throws \Throwable
*/ */
public function delete(DeleteFileRequest $request, Server $server): JsonResponse public function delete(DeleteFileRequest $request, Server $server): Response
{ {
$server->audit(AuditLog::SERVER__FILESYSTEM_DELETE, function (AuditLog $audit, Server $server) use ($request) { $server->audit(AuditLog::SERVER__FILESYSTEM_DELETE, function (AuditLog $audit, Server $server) use ($request) {
$audit->metadata = ['root' => $request->input('root'), 'files' => $request->input('files')]; $audit->metadata = ['root' => $request->input('root'), 'files' => $request->input('files')];
@ -254,7 +241,7 @@ class FileController extends ClientApiController
); );
}); });
return new JsonResponse([], Response::HTTP_NO_CONTENT); return $this->returnNoContent();
} }
/** /**
@ -262,7 +249,7 @@ class FileController extends ClientApiController
* *
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException * @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
*/ */
public function chmod(ChmodFilesRequest $request, Server $server): JsonResponse public function chmod(ChmodFilesRequest $request, Server $server): Response
{ {
$this->fileRepository->setServer($server) $this->fileRepository->setServer($server)
->chmodFiles( ->chmodFiles(
@ -270,17 +257,15 @@ class FileController extends ClientApiController
$request->input('files') $request->input('files')
); );
return new JsonResponse([], Response::HTTP_NO_CONTENT); return $this->returnNoContent();
} }
/** /**
* Requests that a file be downloaded from a remote location by Wings. * Requests that a file be downloaded from a remote location by Wings.
* *
* @param $request
*
* @throws \Throwable * @throws \Throwable
*/ */
public function pull(PullFileRequest $request, Server $server): JsonResponse public function pull(PullFileRequest $request, Server $server): Response
{ {
$server->audit(AuditLog::SERVER__FILESYSTEM_PULL, function (AuditLog $audit, Server $server) use ($request) { $server->audit(AuditLog::SERVER__FILESYSTEM_PULL, function (AuditLog $audit, Server $server) use ($request) {
$audit->metadata = ['directory' => $request->input('directory'), 'url' => $request->input('url')]; $audit->metadata = ['directory' => $request->input('directory'), 'url' => $request->input('url')];
@ -288,6 +273,6 @@ class FileController extends ClientApiController
$this->fileRepository->setServer($server)->pull($request->input('url'), $request->input('directory')); $this->fileRepository->setServer($server)->pull($request->input('url'), $request->input('directory'));
}); });
return new JsonResponse([], Response::HTTP_NO_CONTENT); return $this->returnNoContent();
} }
} }

View File

@ -12,17 +12,13 @@ use Pterodactyl\Http\Requests\Api\Client\Servers\Files\UploadFileRequest;
class FileUploadController extends ClientApiController class FileUploadController extends ClientApiController
{ {
/** private NodeJWTService $jwtService;
* @var \Pterodactyl\Services\Nodes\NodeJWTService
*/
private $jwtService;
/** /**
* FileUploadController constructor. * FileUploadController constructor.
*/ */
public function __construct( public function __construct(NodeJWTService $jwtService)
NodeJWTService $jwtService {
) {
parent::__construct(); parent::__construct();
$this->jwtService = $jwtService; $this->jwtService = $jwtService;
@ -30,10 +26,8 @@ class FileUploadController extends ClientApiController
/** /**
* Returns a url where files can be uploaded to. * Returns a url where files can be uploaded to.
*
* @return \Illuminate\Http\JsonResponse
*/ */
public function __invoke(UploadFileRequest $request, Server $server) public function __invoke(UploadFileRequest $request, Server $server): JsonResponse
{ {
return new JsonResponse([ return new JsonResponse([
'object' => 'signed_url', 'object' => 'signed_url',
@ -45,10 +39,8 @@ class FileUploadController extends ClientApiController
/** /**
* Returns a url where files can be uploaded to. * Returns a url where files can be uploaded to.
*
* @return string
*/ */
protected function getUploadUrl(Server $server, User $user) protected function getUploadUrl(Server $server, User $user): string
{ {
$token = $this->jwtService $token = $this->jwtService
->setExpiresAt(CarbonImmutable::now()->addMinutes(15)->toDateTimeImmutable()) ->setExpiresAt(CarbonImmutable::now()->addMinutes(15)->toDateTimeImmutable())

View File

@ -2,8 +2,8 @@
namespace Pterodactyl\Http\Controllers\Api\Client\Servers; namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
use Illuminate\Http\Response;
use Pterodactyl\Models\Server; use Pterodactyl\Models\Server;
use Illuminate\Http\JsonResponse;
use Pterodactyl\Models\Allocation; use Pterodactyl\Models\Allocation;
use Pterodactyl\Exceptions\DisplayException; use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Repositories\Eloquent\ServerRepository; use Pterodactyl\Repositories\Eloquent\ServerRepository;
@ -19,20 +19,9 @@ use Pterodactyl\Http\Requests\Api\Client\Servers\Network\SetPrimaryAllocationReq
class NetworkAllocationController extends ClientApiController class NetworkAllocationController extends ClientApiController
{ {
/** private AllocationRepository $repository;
* @var \Pterodactyl\Repositories\Eloquent\AllocationRepository private ServerRepository $serverRepository;
*/ private FindAssignableAllocationService $assignableAllocationService;
private $repository;
/**
* @var \Pterodactyl\Repositories\Eloquent\ServerRepository
*/
private $serverRepository;
/**
* @var \Pterodactyl\Services\Allocations\FindAssignableAllocationService
*/
private $assignableAllocationService;
/** /**
* NetworkController constructor. * NetworkController constructor.
@ -50,8 +39,10 @@ class NetworkAllocationController extends ClientApiController
} }
/** /**
* Lists all of the allocations available to a server and wether or * Lists all of the allocations available to a server and whether or
* not they are currently assigned as the primary for this server. * not they are currently assigned as the primary for this server.
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function index(GetNetworkRequest $request, Server $server): array public function index(GetNetworkRequest $request, Server $server): array
{ {
@ -65,6 +56,7 @@ class NetworkAllocationController extends ClientApiController
* *
* @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function update(UpdateAllocationRequest $request, Server $server, Allocation $allocation): array public function update(UpdateAllocationRequest $request, Server $server, Allocation $allocation): array
{ {
@ -82,6 +74,7 @@ class NetworkAllocationController extends ClientApiController
* *
* @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function setPrimary(SetPrimaryAllocationRequest $request, Server $server, Allocation $allocation): array public function setPrimary(SetPrimaryAllocationRequest $request, Server $server, Allocation $allocation): array
{ {
@ -94,9 +87,9 @@ class NetworkAllocationController extends ClientApiController
/** /**
* Set the notes for the allocation for a server. * Set the notes for the allocation for a server.
*s.
* *
* @throws \Pterodactyl\Exceptions\DisplayException * @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function store(NewAllocationRequest $request, Server $server): array public function store(NewAllocationRequest $request, Server $server): array
{ {
@ -114,11 +107,9 @@ class NetworkAllocationController extends ClientApiController
/** /**
* Delete an allocation from a server. * Delete an allocation from a server.
* *
* @return \Illuminate\Http\JsonResponse
*
* @throws \Pterodactyl\Exceptions\DisplayException * @throws \Pterodactyl\Exceptions\DisplayException
*/ */
public function delete(DeleteAllocationRequest $request, Server $server, Allocation $allocation) public function delete(DeleteAllocationRequest $request, Server $server, Allocation $allocation): Response
{ {
if ($allocation->id === $server->allocation_id) { if ($allocation->id === $server->allocation_id) {
throw new DisplayException('You cannot delete the primary allocation for this server.'); throw new DisplayException('You cannot delete the primary allocation for this server.');
@ -129,6 +120,6 @@ class NetworkAllocationController extends ClientApiController
'server_id' => null, 'server_id' => null,
]); ]);
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); return $this->returnNoContent();
} }
} }

View File

@ -10,10 +10,7 @@ use Pterodactyl\Http\Requests\Api\Client\Servers\SendPowerRequest;
class PowerController extends ClientApiController class PowerController extends ClientApiController
{ {
/** private DaemonPowerRepository $repository;
* @var \Pterodactyl\Repositories\Wings\DaemonPowerRepository
*/
private $repository;
/** /**
* PowerController constructor. * PowerController constructor.

View File

@ -10,10 +10,7 @@ use Pterodactyl\Http\Requests\Api\Client\Servers\GetServerRequest;
class ResourceUtilizationController extends ClientApiController class ResourceUtilizationController extends ClientApiController
{ {
/** private DaemonServerRepository $repository;
* @var \Pterodactyl\Repositories\Wings\DaemonServerRepository
*/
private $repository;
/** /**
* ResourceUtilizationController constructor. * ResourceUtilizationController constructor.
@ -29,6 +26,7 @@ class ResourceUtilizationController extends ClientApiController
* Return the current resource utilization for a server. * Return the current resource utilization for a server.
* *
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException * @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function __invoke(GetServerRequest $request, Server $server): array public function __invoke(GetServerRequest $request, Server $server): array
{ {

View File

@ -8,7 +8,6 @@ use Illuminate\Http\Request;
use Illuminate\Http\Response; use Illuminate\Http\Response;
use Pterodactyl\Models\Server; use Pterodactyl\Models\Server;
use Pterodactyl\Models\Schedule; use Pterodactyl\Models\Schedule;
use Illuminate\Http\JsonResponse;
use Pterodactyl\Helpers\Utilities; use Pterodactyl\Helpers\Utilities;
use Pterodactyl\Exceptions\DisplayException; use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Repositories\Eloquent\ScheduleRepository; use Pterodactyl\Repositories\Eloquent\ScheduleRepository;
@ -25,15 +24,8 @@ use Pterodactyl\Http\Requests\Api\Client\Servers\Schedules\TriggerScheduleReques
class ScheduleController extends ClientApiController class ScheduleController extends ClientApiController
{ {
/** private ScheduleRepository $repository;
* @var \Pterodactyl\Repositories\Eloquent\ScheduleRepository private ProcessScheduleService $service;
*/
private $repository;
/**
* @var \Pterodactyl\Services\Schedules\ProcessScheduleService
*/
private $service;
/** /**
* ScheduleController constructor. * ScheduleController constructor.
@ -49,9 +41,9 @@ class ScheduleController extends ClientApiController
/** /**
* Returns all of the schedules belonging to a given server. * Returns all of the schedules belonging to a given server.
* *
* @return array * @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function index(ViewScheduleRequest $request, Server $server) public function index(ViewScheduleRequest $request, Server $server): array
{ {
$schedules = $server->schedule; $schedules = $server->schedule;
$schedules->loadMissing('tasks'); $schedules->loadMissing('tasks');
@ -64,12 +56,11 @@ class ScheduleController extends ClientApiController
/** /**
* Store a new schedule for a server. * Store a new schedule for a server.
* *
* @return array
*
* @throws \Pterodactyl\Exceptions\DisplayException * @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function store(StoreScheduleRequest $request, Server $server) public function store(StoreScheduleRequest $request, Server $server): array
{ {
/** @var \Pterodactyl\Models\Schedule $model */ /** @var \Pterodactyl\Models\Schedule $model */
$model = $this->repository->create([ $model = $this->repository->create([
@ -92,9 +83,9 @@ class ScheduleController extends ClientApiController
/** /**
* Returns a specific schedule for the server. * Returns a specific schedule for the server.
* *
* @return array * @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function view(ViewScheduleRequest $request, Server $server, Schedule $schedule) public function view(ViewScheduleRequest $request, Server $server, Schedule $schedule): array
{ {
if ($schedule->server_id !== $server->id) { if ($schedule->server_id !== $server->id) {
throw new NotFoundHttpException(); throw new NotFoundHttpException();
@ -110,13 +101,12 @@ class ScheduleController extends ClientApiController
/** /**
* Updates a given schedule with the new data provided. * Updates a given schedule with the new data provided.
* *
* @return array
*
* @throws \Pterodactyl\Exceptions\DisplayException * @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function update(UpdateScheduleRequest $request, Server $server, Schedule $schedule) public function update(UpdateScheduleRequest $request, Server $server, Schedule $schedule): array
{ {
$active = (bool) $request->input('is_active'); $active = (bool) $request->input('is_active');
@ -150,31 +140,27 @@ class ScheduleController extends ClientApiController
* Executes a given schedule immediately rather than waiting on it's normally scheduled time * Executes a given schedule immediately rather than waiting on it's normally scheduled time
* to pass. This does not care about the schedule state. * to pass. This does not care about the schedule state.
* *
* @return \Illuminate\Http\JsonResponse
*
* @throws \Throwable * @throws \Throwable
*/ */
public function execute(TriggerScheduleRequest $request, Server $server, Schedule $schedule) public function execute(TriggerScheduleRequest $request, Server $server, Schedule $schedule): Response
{ {
if (!$schedule->is_active) { if (!$schedule->is_active) {
throw new BadRequestHttpException('Cannot trigger schedule exection for a schedule that is not currently active.'); throw new BadRequestHttpException('Cannot trigger schedule exception for a schedule that is not currently active.');
} }
$this->service->handle($schedule, true); $this->service->handle($schedule, true);
return new JsonResponse([], JsonResponse::HTTP_ACCEPTED); return $this->returnAccepted();
} }
/** /**
* Deletes a schedule and it's associated tasks. * Deletes a schedule and it's associated tasks.
*
* @return \Illuminate\Http\JsonResponse
*/ */
public function delete(DeleteScheduleRequest $request, Server $server, Schedule $schedule) public function delete(DeleteScheduleRequest $request, Server $server, Schedule $schedule): Response
{ {
$this->repository->delete($schedule->id); $this->repository->delete($schedule->id);
return new JsonResponse([], Response::HTTP_NO_CONTENT); return $this->returnNoContent();
} }
/** /**

View File

@ -6,7 +6,6 @@ use Pterodactyl\Models\Task;
use Illuminate\Http\Response; use Illuminate\Http\Response;
use Pterodactyl\Models\Server; use Pterodactyl\Models\Server;
use Pterodactyl\Models\Schedule; use Pterodactyl\Models\Schedule;
use Illuminate\Http\JsonResponse;
use Pterodactyl\Models\Permission; use Pterodactyl\Models\Permission;
use Pterodactyl\Repositories\Eloquent\TaskRepository; use Pterodactyl\Repositories\Eloquent\TaskRepository;
use Pterodactyl\Exceptions\Http\HttpForbiddenException; use Pterodactyl\Exceptions\Http\HttpForbiddenException;
@ -19,10 +18,7 @@ use Pterodactyl\Http\Requests\Api\Client\Servers\Schedules\StoreTaskRequest;
class ScheduleTaskController extends ClientApiController class ScheduleTaskController extends ClientApiController
{ {
/** private TaskRepository $repository;
* @var \Pterodactyl\Repositories\Eloquent\TaskRepository
*/
private $repository;
/** /**
* ScheduleTaskController constructor. * ScheduleTaskController constructor.
@ -37,12 +33,11 @@ class ScheduleTaskController extends ClientApiController
/** /**
* Create a new task for a given schedule and store it in the database. * Create a new task for a given schedule and store it in the database.
* *
* @return array
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Service\ServiceLimitExceededException * @throws \Pterodactyl\Exceptions\Service\ServiceLimitExceededException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function store(StoreTaskRequest $request, Server $server, Schedule $schedule) public function store(StoreTaskRequest $request, Server $server, Schedule $schedule): array
{ {
$limit = config('pterodactyl.client_features.schedules.per_schedule_task_limit', 10); $limit = config('pterodactyl.client_features.schedules.per_schedule_task_limit', 10);
if ($schedule->tasks()->count() >= $limit) { if ($schedule->tasks()->count() >= $limit) {
@ -69,12 +64,11 @@ class ScheduleTaskController extends ClientApiController
/** /**
* Updates a given task for a server. * Updates a given task for a server.
* *
* @return array
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function update(StoreTaskRequest $request, Server $server, Schedule $schedule, Task $task) public function update(StoreTaskRequest $request, Server $server, Schedule $schedule, Task $task): array
{ {
if ($schedule->id !== $task->schedule_id || $server->id !== $schedule->server_id) { if ($schedule->id !== $task->schedule_id || $server->id !== $schedule->server_id) {
throw new NotFoundHttpException(); throw new NotFoundHttpException();
@ -95,11 +89,9 @@ class ScheduleTaskController extends ClientApiController
* Delete a given task for a schedule. If there are subsequent tasks stored in the database * Delete a given task for a schedule. If there are subsequent tasks stored in the database
* for this schedule their sequence IDs are decremented properly. * for this schedule their sequence IDs are decremented properly.
* *
* @return \Illuminate\Http\JsonResponse
*
* @throws \Exception * @throws \Exception
*/ */
public function delete(ClientApiRequest $request, Server $server, Schedule $schedule, Task $task) public function delete(ClientApiRequest $request, Server $server, Schedule $schedule, Task $task): Response
{ {
if ($task->schedule_id !== $schedule->id || $schedule->server_id !== $server->id) { if ($task->schedule_id !== $schedule->id || $schedule->server_id !== $server->id) {
throw new NotFoundHttpException(); throw new NotFoundHttpException();
@ -115,6 +107,6 @@ class ScheduleTaskController extends ClientApiController
$task->delete(); $task->delete();
return new JsonResponse(null, Response::HTTP_NO_CONTENT); return $this->returnNoContent();
} }
} }

View File

@ -11,15 +11,8 @@ use Pterodactyl\Http\Requests\Api\Client\Servers\GetServerRequest;
class ServerController extends ClientApiController class ServerController extends ClientApiController
{ {
/** private SubuserRepository $repository;
* @var \Pterodactyl\Repositories\Eloquent\SubuserRepository private GetUserPermissionsService $permissionsService;
*/
private $repository;
/**
* @var \Pterodactyl\Services\Servers\GetUserPermissionsService
*/
private $permissionsService;
/** /**
* ServerController constructor. * ServerController constructor.
@ -35,6 +28,8 @@ class ServerController extends ClientApiController
/** /**
* Transform an individual server into a response that can be consumed by a * Transform an individual server into a response that can be consumed by a
* client using the API. * client using the API.
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function index(GetServerRequest $request, Server $server): array public function index(GetServerRequest $request, Server $server): array
{ {

View File

@ -4,7 +4,6 @@ namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
use Illuminate\Http\Response; use Illuminate\Http\Response;
use Pterodactyl\Models\Server; use Pterodactyl\Models\Server;
use Illuminate\Http\JsonResponse;
use Pterodactyl\Repositories\Eloquent\ServerRepository; use Pterodactyl\Repositories\Eloquent\ServerRepository;
use Pterodactyl\Services\Servers\ReinstallServerService; use Pterodactyl\Services\Servers\ReinstallServerService;
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController; use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
@ -15,15 +14,8 @@ use Pterodactyl\Http\Requests\Api\Client\Servers\Settings\ReinstallServerRequest
class SettingsController extends ClientApiController class SettingsController extends ClientApiController
{ {
/** private ServerRepository $repository;
* @var \Pterodactyl\Repositories\Eloquent\ServerRepository private ReinstallServerService $reinstallServerService;
*/
private $repository;
/**
* @var \Pterodactyl\Services\Servers\ReinstallServerService
*/
private $reinstallServerService;
/** /**
* SettingsController constructor. * SettingsController constructor.
@ -41,42 +33,36 @@ class SettingsController extends ClientApiController
/** /**
* Renames a server. * Renames a server.
* *
* @return \Illuminate\Http\JsonResponse
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/ */
public function rename(RenameServerRequest $request, Server $server) public function rename(RenameServerRequest $request, Server $server): Response
{ {
$this->repository->update($server->id, [ $this->repository->update($server->id, [
'name' => $request->input('name'), 'name' => $request->input('name'),
]); ]);
return new JsonResponse([], Response::HTTP_NO_CONTENT); return $this->returnNoContent();
} }
/** /**
* Reinstalls the server on the daemon. * Reinstalls the server on the daemon.
* *
* @return \Illuminate\Http\JsonResponse
*
* @throws \Throwable * @throws \Throwable
*/ */
public function reinstall(ReinstallServerRequest $request, Server $server) public function reinstall(ReinstallServerRequest $request, Server $server): Response
{ {
$this->reinstallServerService->handle($server); $this->reinstallServerService->handle($server);
return new JsonResponse([], Response::HTTP_ACCEPTED); return $this->returnAccepted();
} }
/** /**
* Changes the Docker image in use by the server. * Changes the Docker image in use by the server.
* *
* @return \Illuminate\Http\JsonResponse
*
* @throws \Throwable * @throws \Throwable
*/ */
public function dockerImage(SetDockerImageRequest $request, Server $server) public function dockerImage(SetDockerImageRequest $request, Server $server): Response
{ {
if (!in_array($server->image, $server->egg->docker_images)) { if (!in_array($server->image, $server->egg->docker_images)) {
throw new BadRequestHttpException('This server\'s Docker image has been manually set by an administrator and cannot be updated.'); throw new BadRequestHttpException('This server\'s Docker image has been manually set by an administrator and cannot be updated.');
@ -84,6 +70,6 @@ class SettingsController extends ClientApiController
$server->forceFill(['image' => $request->input('docker_image')])->saveOrFail(); $server->forceFill(['image' => $request->input('docker_image')])->saveOrFail();
return new JsonResponse([], Response::HTTP_NO_CONTENT); return $this->returnNoContent();
} }
} }

View File

@ -14,20 +14,9 @@ use Pterodactyl\Http\Requests\Api\Client\Servers\Startup\UpdateStartupVariableRe
class StartupController extends ClientApiController class StartupController extends ClientApiController
{ {
/** private VariableValidatorService $service;
* @var \Pterodactyl\Services\Servers\VariableValidatorService private ServerVariableRepository $repository;
*/ private StartupCommandService $startupCommandService;
private $service;
/**
* @var \Pterodactyl\Repositories\Eloquent\ServerVariableRepository
*/
private $repository;
/**
* @var \Pterodactyl\Services\Servers\StartupCommandService
*/
private $startupCommandService;
/** /**
* StartupController constructor. * StartupController constructor.
@ -44,9 +33,9 @@ class StartupController extends ClientApiController
/** /**
* Returns the startup information for the server including all of the variables. * Returns the startup information for the server including all of the variables.
* *
* @return array * @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function index(GetStartupRequest $request, Server $server) public function index(GetStartupRequest $request, Server $server): array
{ {
$startup = $this->startupCommandService->handle($server, false); $startup = $this->startupCommandService->handle($server, false);
@ -65,13 +54,12 @@ class StartupController extends ClientApiController
/** /**
* Updates a single variable for a server. * Updates a single variable for a server.
* *
* @return array
*
* @throws \Illuminate\Validation\ValidationException * @throws \Illuminate\Validation\ValidationException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function update(UpdateStartupVariableRequest $request, Server $server) public function update(UpdateStartupVariableRequest $request, Server $server): array
{ {
/** @var \Pterodactyl\Models\EggVariable $variable */ /** @var \Pterodactyl\Models\EggVariable $variable */
$variable = $server->variables()->where('env_variable', $request->input('key'))->first(); $variable = $server->variables()->where('env_variable', $request->input('key'))->first();

View File

@ -3,8 +3,8 @@
namespace Pterodactyl\Http\Controllers\Api\Client\Servers; namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Pterodactyl\Models\Server; use Pterodactyl\Models\Server;
use Illuminate\Http\JsonResponse;
use Pterodactyl\Models\Permission; use Pterodactyl\Models\Permission;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Pterodactyl\Repositories\Eloquent\SubuserRepository; use Pterodactyl\Repositories\Eloquent\SubuserRepository;
@ -20,20 +20,9 @@ use Pterodactyl\Http\Requests\Api\Client\Servers\Subusers\UpdateSubuserRequest;
class SubuserController extends ClientApiController class SubuserController extends ClientApiController
{ {
/** private SubuserRepository $repository;
* @var \Pterodactyl\Repositories\Eloquent\SubuserRepository private SubuserCreationService $creationService;
*/ private DaemonServerRepository $serverRepository;
private $repository;
/**
* @var \Pterodactyl\Services\Subusers\SubuserCreationService
*/
private $creationService;
/**
* @var \Pterodactyl\Repositories\Wings\DaemonServerRepository
*/
private $serverRepository;
/** /**
* SubuserController constructor. * SubuserController constructor.
@ -53,9 +42,9 @@ class SubuserController extends ClientApiController
/** /**
* Return the users associated with this server instance. * Return the users associated with this server instance.
* *
* @return array * @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function index(GetSubuserRequest $request, Server $server) public function index(GetSubuserRequest $request, Server $server): array
{ {
return $this->fractal->collection($server->subusers) return $this->fractal->collection($server->subusers)
->transformWith($this->getTransformer(SubuserTransformer::class)) ->transformWith($this->getTransformer(SubuserTransformer::class))
@ -65,9 +54,9 @@ class SubuserController extends ClientApiController
/** /**
* Returns a single subuser associated with this server instance. * Returns a single subuser associated with this server instance.
* *
* @return array * @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function view(GetSubuserRequest $request) public function view(GetSubuserRequest $request): array
{ {
$subuser = $request->attributes->get('subuser'); $subuser = $request->attributes->get('subuser');
@ -79,14 +68,12 @@ class SubuserController extends ClientApiController
/** /**
* Create a new subuser for the given server. * Create a new subuser for the given server.
* *
* @return array
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Service\Subuser\ServerSubuserExistsException * @throws \Pterodactyl\Exceptions\Service\Subuser\ServerSubuserExistsException
* @throws \Pterodactyl\Exceptions\Service\Subuser\UserIsServerOwnerException * @throws \Pterodactyl\Exceptions\Service\Subuser\UserIsServerOwnerException
* @throws \Throwable * @throws \Throwable
*/ */
public function store(StoreSubuserRequest $request, Server $server) public function store(StoreSubuserRequest $request, Server $server): array
{ {
$response = $this->creationService->handle( $response = $this->creationService->handle(
$server, $server,
@ -104,6 +91,7 @@ class SubuserController extends ClientApiController
* *
* @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/ */
public function update(UpdateSubuserRequest $request, Server $server): array public function update(UpdateSubuserRequest $request, Server $server): array
{ {
@ -139,10 +127,8 @@ class SubuserController extends ClientApiController
/** /**
* Removes a subusers from a server's assignment. * Removes a subusers from a server's assignment.
*
* @return \Illuminate\Http\JsonResponse
*/ */
public function delete(DeleteSubuserRequest $request, Server $server) public function delete(DeleteSubuserRequest $request, Server $server): Response
{ {
/** @var \Pterodactyl\Models\Subuser $subuser */ /** @var \Pterodactyl\Models\Subuser $subuser */
$subuser = $request->attributes->get('subuser'); $subuser = $request->attributes->get('subuser');
@ -156,7 +142,7 @@ class SubuserController extends ClientApiController
Log::warning($exception, ['user_id' => $subuser->user_id, 'server_id' => $server->id]); Log::warning($exception, ['user_id' => $subuser->user_id, 'server_id' => $server->id]);
} }
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); return $this->returnNoContent();
} }
/** /**

View File

@ -14,15 +14,8 @@ use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
class WebsocketController extends ClientApiController class WebsocketController extends ClientApiController
{ {
/** private NodeJWTService $jwtService;
* @var \Pterodactyl\Services\Nodes\NodeJWTService private GetUserPermissionsService $permissionsService;
*/
private $jwtService;
/**
* @var \Pterodactyl\Services\Servers\GetUserPermissionsService
*/
private $permissionsService;
/** /**
* WebsocketController constructor. * WebsocketController constructor.
@ -40,12 +33,10 @@ class WebsocketController extends ClientApiController
/** /**
* Generates a one-time token that is sent along in every websocket call to the Daemon. * Generates a one-time token that is sent along in every websocket call to the Daemon.
* This is a signed JWT that the Daemon then uses the verify the user's identity, and * This is a signed JWT that the Daemon then uses the verify the user's identity, and
* allows us to continually renew this token and avoid users mainitaining sessions wrongly, * allows us to continually renew this token and avoid users maintaining sessions wrongly,
* as well as ensure that user's only perform actions they're allowed to. * as well as ensure that user's only perform actions they're allowed to.
*
* @return \Illuminate\Http\JsonResponse
*/ */
public function __invoke(ClientApiRequest $request, Server $server) public function __invoke(ClientApiRequest $request, Server $server): JsonResponse
{ {
$user = $request->user(); $user = $request->user();
if ($user->cannot(Permission::ACTION_WEBSOCKET_CONNECT, $server)) { if ($user->cannot(Permission::ACTION_WEBSOCKET_CONNECT, $server)) {

View File

@ -14,20 +14,9 @@ use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
class TwoFactorController extends ClientApiController class TwoFactorController extends ClientApiController
{ {
/** private ToggleTwoFactorService $toggleTwoFactorService;
* @var \Pterodactyl\Services\Users\TwoFactorSetupService private TwoFactorSetupService $setupService;
*/ private Factory $validation;
private $setupService;
/**
* @var \Illuminate\Contracts\Validation\Factory
*/
private $validation;
/**
* @var \Pterodactyl\Services\Users\ToggleTwoFactorService
*/
private $toggleTwoFactorService;
/** /**
* TwoFactorController constructor. * TwoFactorController constructor.
@ -39,9 +28,9 @@ class TwoFactorController extends ClientApiController
) { ) {
parent::__construct(); parent::__construct();
$this->toggleTwoFactorService = $toggleTwoFactorService;
$this->setupService = $setupService; $this->setupService = $setupService;
$this->validation = $validation; $this->validation = $validation;
$this->toggleTwoFactorService = $toggleTwoFactorService;
} }
/** /**
@ -49,12 +38,10 @@ class TwoFactorController extends ClientApiController
* it on their account. If two-factor is already enabled this endpoint * it on their account. If two-factor is already enabled this endpoint
* will return a 400 error. * will return a 400 error.
* *
* @return \Illuminate\Http\JsonResponse
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/ */
public function index(Request $request) public function index(Request $request): JsonResponse
{ {
if ($request->user()->use_totp) { if ($request->user()->use_totp) {
throw new BadRequestHttpException('Two-factor authentication is already enabled on this account.'); throw new BadRequestHttpException('Two-factor authentication is already enabled on this account.');
@ -70,17 +57,9 @@ class TwoFactorController extends ClientApiController
/** /**
* Updates a user's account to have two-factor enabled. * Updates a user's account to have two-factor enabled.
* *
* @return \Illuminate\Http\JsonResponse * @throws \Throwable
*
* @throws \Illuminate\Validation\ValidationException
* @throws \PragmaRX\Google2FA\Exceptions\IncompatibleWithGoogleAuthenticatorException
* @throws \PragmaRX\Google2FA\Exceptions\InvalidCharactersException
* @throws \PragmaRX\Google2FA\Exceptions\SecretKeyTooShortException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Pterodactyl\Exceptions\Service\User\TwoFactorAuthenticationTokenInvalid
*/ */
public function store(Request $request) public function store(Request $request): JsonResponse
{ {
$validator = $this->validation->make($request->all(), [ $validator = $this->validation->make($request->all(), [
'code' => 'required|string', 'code' => 'required|string',
@ -103,10 +82,8 @@ class TwoFactorController extends ClientApiController
/** /**
* Disables two-factor authentication on an account if the password provided * Disables two-factor authentication on an account if the password provided
* is valid. * is valid.
*
* @return \Illuminate\Http\JsonResponse
*/ */
public function delete(Request $request) public function delete(Request $request): JsonResponse
{ {
if (!password_verify($request->input('password') ?? '', $request->user()->password)) { if (!password_verify($request->input('password') ?? '', $request->user()->password)) {
throw new BadRequestHttpException('The password provided was not valid.'); throw new BadRequestHttpException('The password provided was not valid.');
@ -120,6 +97,6 @@ class TwoFactorController extends ClientApiController
'use_totp' => false, 'use_totp' => false,
]); ]);
return new JsonResponse([], Response::HTTP_NO_CONTENT); return $this->returnNoContent();
} }
} }

View File

@ -17,15 +17,8 @@ class BackupRemoteUploadController extends Controller
{ {
public const PART_SIZE = 5 * 1024 * 1024 * 1024; public const PART_SIZE = 5 * 1024 * 1024 * 1024;
/** private BackupRepository $repository;
* @var \Pterodactyl\Repositories\Eloquent\BackupRepository private BackupManager $backupManager;
*/
private $repository;
/**
* @var \Pterodactyl\Extensions\Backups\BackupManager
*/
private $backupManager;
/** /**
* BackupRemoteUploadController constructor. * BackupRemoteUploadController constructor.
@ -37,15 +30,13 @@ class BackupRemoteUploadController extends Controller
} }
/** /**
* Returns the required presigned urls to upload a backup to S3 cloud storage. * Returns the required pre-signed urls to upload a backup to S3 cloud storage.
*
* @return \Illuminate\Http\JsonResponse
* *
* @throws \Exception * @throws \Exception
* @throws \Throwable * @throws \Throwable
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException * @throws \Illuminate\Database\Eloquent\ModelNotFoundException
*/ */
public function __invoke(Request $request, string $backup) public function __invoke(Request $request, string $backup): JsonResponse
{ {
// Get the size query parameter. // Get the size query parameter.
$size = (int) $request->query('size'); $size = (int) $request->query('size');

View File

@ -4,6 +4,7 @@ namespace Pterodactyl\Http\Controllers\Api\Remote\Backups;
use Carbon\CarbonImmutable; use Carbon\CarbonImmutable;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Pterodactyl\Models\Backup; use Pterodactyl\Models\Backup;
use Pterodactyl\Models\Server; use Pterodactyl\Models\Server;
use Pterodactyl\Models\AuditLog; use Pterodactyl\Models\AuditLog;
@ -18,15 +19,8 @@ use Pterodactyl\Http\Requests\Api\Remote\ReportBackupCompleteRequest;
class BackupStatusController extends Controller class BackupStatusController extends Controller
{ {
/** private BackupRepository $repository;
* @var \Pterodactyl\Repositories\Eloquent\BackupRepository private BackupManager $backupManager;
*/
private $repository;
/**
* @var \Pterodactyl\Extensions\Backups\BackupManager
*/
private $backupManager;
/** /**
* BackupStatusController constructor. * BackupStatusController constructor.
@ -40,11 +34,9 @@ class BackupStatusController extends Controller
/** /**
* Handles updating the state of a backup. * Handles updating the state of a backup.
* *
* @return \Illuminate\Http\JsonResponse
*
* @throws \Throwable * @throws \Throwable
*/ */
public function index(ReportBackupCompleteRequest $request, string $backup) public function index(ReportBackupCompleteRequest $request, string $backup): Response
{ {
/** @var \Pterodactyl\Models\Backup $model */ /** @var \Pterodactyl\Models\Backup $model */
$model = Backup::query()->where('uuid', $backup)->firstOrFail(); $model = Backup::query()->where('uuid', $backup)->firstOrFail();
@ -77,7 +69,7 @@ class BackupStatusController extends Controller
} }
}); });
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); return new Response('', Response::HTTP_NO_CONTENT);
} }
/** /**
@ -88,11 +80,9 @@ class BackupStatusController extends Controller
* The only thing the successful field does is update the entry value for the audit logs * The only thing the successful field does is update the entry value for the audit logs
* table tracking for this restoration. * table tracking for this restoration.
* *
* @return \Illuminate\Http\JsonResponse
*
* @throws \Throwable * @throws \Throwable
*/ */
public function restore(Request $request, string $backup) public function restore(Request $request, string $backup): Response
{ {
/** @var \Pterodactyl\Models\Backup $model */ /** @var \Pterodactyl\Models\Backup $model */
$model = Backup::query()->where('uuid', $backup)->firstOrFail(); $model = Backup::query()->where('uuid', $backup)->firstOrFail();
@ -108,7 +98,7 @@ class BackupStatusController extends Controller
$server->update(['status' => null]); $server->update(['status' => null]);
}); });
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); return new Response('', Response::HTTP_NO_CONTENT);
} }
/** /**

View File

@ -10,15 +10,8 @@ use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
class EggInstallController extends Controller class EggInstallController extends Controller
{ {
/** private EnvironmentService $environment;
* @var \Pterodactyl\Services\Servers\EnvironmentService private ServerRepositoryInterface $repository;
*/
private $environment;
/**
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
*/
private $repository;
/** /**
* EggInstallController constructor. * EggInstallController constructor.

View File

@ -3,13 +3,13 @@
namespace Pterodactyl\Http\Controllers\Api\Remote\Servers; namespace Pterodactyl\Http\Controllers\Api\Remote\Servers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Pterodactyl\Models\Server; use Pterodactyl\Models\Server;
use Pterodactyl\Models\AuditLog; use Pterodactyl\Models\AuditLog;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Illuminate\Database\Query\Builder; use Illuminate\Database\Query\Builder;
use Illuminate\Database\Query\JoinClause; use Illuminate\Database\Query\JoinClause;
use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Repositories\Eloquent\NodeRepository;
use Pterodactyl\Services\Eggs\EggConfigurationService; use Pterodactyl\Services\Eggs\EggConfigurationService;
use Pterodactyl\Repositories\Eloquent\ServerRepository; use Pterodactyl\Repositories\Eloquent\ServerRepository;
use Pterodactyl\Http\Resources\Wings\ServerConfigurationCollection; use Pterodactyl\Http\Resources\Wings\ServerConfigurationCollection;
@ -17,46 +17,30 @@ use Pterodactyl\Services\Servers\ServerConfigurationStructureService;
class ServerDetailsController extends Controller class ServerDetailsController extends Controller
{ {
/** private ServerRepository $repository;
* @var \Pterodactyl\Services\Eggs\EggConfigurationService private ServerConfigurationStructureService $configurationStructureService;
*/ private EggConfigurationService $eggConfigurationService;
private $eggConfigurationService;
/** /**
* @var \Pterodactyl\Repositories\Eloquent\ServerRepository * ServerDetailsController constructor.
*/
private $repository;
/**
* @var \Pterodactyl\Services\Servers\ServerConfigurationStructureService
*/
private $configurationStructureService;
/**
* ServerConfigurationController constructor.
*/ */
public function __construct( public function __construct(
ServerRepository $repository, ServerRepository $repository,
ServerConfigurationStructureService $configurationStructureService, ServerConfigurationStructureService $configurationStructureService,
EggConfigurationService $eggConfigurationService, EggConfigurationService $eggConfigurationService
NodeRepository $nodeRepository
) { ) {
$this->eggConfigurationService = $eggConfigurationService;
$this->repository = $repository; $this->repository = $repository;
$this->configurationStructureService = $configurationStructureService; $this->configurationStructureService = $configurationStructureService;
$this->eggConfigurationService = $eggConfigurationService;
} }
/** /**
* Returns details about the server that allows Wings to self-recover and ensure * Returns details about the server that allows Wings to self-recover and ensure
* that the state of the server matches the Panel at all times. * that the state of the server matches the Panel at all times.
* *
* @param string $uuid
*
* @return \Illuminate\Http\JsonResponse
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/ */
public function __invoke(Request $request, $uuid) public function __invoke(Request $request, string $uuid): JsonResponse
{ {
$server = $this->repository->getByUuid($uuid); $server = $this->repository->getByUuid($uuid);
@ -68,10 +52,8 @@ class ServerDetailsController extends Controller
/** /**
* Lists all servers with their configurations that are assigned to the requesting node. * Lists all servers with their configurations that are assigned to the requesting node.
*
* @return \Pterodactyl\Http\Resources\Wings\ServerConfigurationCollection
*/ */
public function list(Request $request) public function list(Request $request): ServerConfigurationCollection
{ {
/** @var \Pterodactyl\Models\Node $node */ /** @var \Pterodactyl\Models\Node $node */
$node = $request->attributes->get('node'); $node = $request->attributes->get('node');
@ -93,12 +75,9 @@ class ServerDetailsController extends Controller
* do not get incorrectly stuck in installing/restoring from backup states since * do not get incorrectly stuck in installing/restoring from backup states since
* a Wings reboot would completely stop those processes. * a Wings reboot would completely stop those processes.
* *
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\JsonResponse
*
* @throws \Throwable * @throws \Throwable
*/ */
public function resetState(Request $request) public function resetState(Request $request): Response
{ {
$node = $request->attributes->get('node'); $node = $request->attributes->get('node');
@ -147,6 +126,6 @@ class ServerDetailsController extends Controller
->whereIn('status', [Server::STATUS_INSTALLING, Server::STATUS_RESTORING_BACKUP]) ->whereIn('status', [Server::STATUS_INSTALLING, Server::STATUS_RESTORING_BACKUP])
->update(['status' => null]); ->update(['status' => null]);
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); return new Response('', JsonResponse::HTTP_NO_CONTENT);
} }
} }

View File

@ -12,10 +12,7 @@ use Pterodactyl\Http\Requests\Api\Remote\InstallationDataRequest;
class ServerInstallController extends Controller class ServerInstallController extends Controller
{ {
/** private ServerRepository $repository;
* @var \Pterodactyl\Repositories\Eloquent\ServerRepository
*/
private $repository;
/** /**
* ServerInstallController constructor. * ServerInstallController constructor.
@ -28,16 +25,14 @@ class ServerInstallController extends Controller
/** /**
* Returns installation information for a server. * Returns installation information for a server.
* *
* @return \Illuminate\Http\JsonResponse
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/ */
public function index(Request $request, string $uuid) public function index(Request $request, string $uuid): JsonResponse
{ {
$server = $this->repository->getByUuid($uuid); $server = $this->repository->getByUuid($uuid);
$egg = $server->egg; $egg = $server->egg;
return JsonResponse::create([ return new JsonResponse([
'container_image' => $egg->copy_script_container, 'container_image' => $egg->copy_script_container,
'entrypoint' => $egg->copy_script_entry, 'entrypoint' => $egg->copy_script_entry,
'script' => $egg->copy_script_install, 'script' => $egg->copy_script_install,
@ -47,12 +42,10 @@ class ServerInstallController extends Controller
/** /**
* Updates the installation state of a server. * Updates the installation state of a server.
* *
* @return \Illuminate\Http\JsonResponse
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Model\DataValidationException
*/ */
public function store(InstallationDataRequest $request, string $uuid) public function store(InstallationDataRequest $request, string $uuid): Response
{ {
$server = $this->repository->getByUuid($uuid); $server = $this->repository->getByUuid($uuid);
@ -63,6 +56,6 @@ class ServerInstallController extends Controller
$this->repository->update($server->id, ['status' => $status], true, true); $this->repository->update($server->id, ['status' => $status], true, true);
return new JsonResponse([], Response::HTTP_NO_CONTENT); return new Response('', Response::HTTP_NO_CONTENT);
} }
} }

View File

@ -6,7 +6,6 @@ use Carbon\CarbonImmutable;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Http\Response; use Illuminate\Http\Response;
use Illuminate\Http\JsonResponse;
use Pterodactyl\Models\Allocation; use Pterodactyl\Models\Allocation;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Pterodactyl\Models\ServerTransfer; use Pterodactyl\Models\ServerTransfer;
@ -21,35 +20,12 @@ use Pterodactyl\Services\Servers\ServerConfigurationStructureService;
class ServerTransferController extends Controller class ServerTransferController extends Controller
{ {
/** private ConnectionInterface $connection;
* @var \Illuminate\Database\ConnectionInterface private ServerRepository $repository;
*/ private DaemonServerRepository $daemonServerRepository;
private $connection; private DaemonTransferRepository $daemonTransferRepository;
private ServerConfigurationStructureService $configurationStructureService;
/** private NodeJWTService $jwtService;
* @var \Pterodactyl\Repositories\Eloquent\ServerRepository
*/
private $repository;
/**
* @var \Pterodactyl\Repositories\Wings\DaemonServerRepository
*/
private $daemonServerRepository;
/**
* @var \Pterodactyl\Repositories\Wings\DaemonTransferRepository
*/
private $daemonTransferRepository;
/**
* @var \Pterodactyl\Services\Servers\ServerConfigurationStructureService
*/
private $configurationStructureService;
/**
* @var \Pterodactyl\Services\Nodes\NodeJWTService
*/
private $jwtService;
/** /**
* ServerTransferController constructor. * ServerTransferController constructor.
@ -73,12 +49,10 @@ class ServerTransferController extends Controller
/** /**
* The daemon notifies us about the archive status. * The daemon notifies us about the archive status.
* *
* @return \Illuminate\Http\JsonResponse
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Throwable * @throws \Throwable
*/ */
public function archive(Request $request, string $uuid) public function archive(Request $request, string $uuid): Response
{ {
$server = $this->repository->getByUuid($uuid); $server = $this->repository->getByUuid($uuid);
@ -122,17 +96,15 @@ class ServerTransferController extends Controller
->notify($server, $data, $server->node, $token->toString()); ->notify($server, $data, $server->node, $token->toString());
}); });
return new JsonResponse([], Response::HTTP_NO_CONTENT); return new Response('', Response::HTTP_NO_CONTENT);
} }
/** /**
* The daemon notifies us about a transfer failure. * The daemon notifies us about a transfer failure.
* *
* @return \Illuminate\Http\JsonResponse
*
* @throws \Throwable * @throws \Throwable
*/ */
public function failure(string $uuid) public function failure(string $uuid): Response
{ {
$server = $this->repository->getByUuid($uuid); $server = $this->repository->getByUuid($uuid);
@ -142,11 +114,9 @@ class ServerTransferController extends Controller
/** /**
* The daemon notifies us about a transfer success. * The daemon notifies us about a transfer success.
* *
* @return \Illuminate\Http\JsonResponse
*
* @throws \Throwable * @throws \Throwable
*/ */
public function success(string $uuid) public function success(string $uuid): Response
{ {
$server = $this->repository->getByUuid($uuid); $server = $this->repository->getByUuid($uuid);
$transfer = $server->transfer; $transfer = $server->transfer;
@ -173,7 +143,7 @@ class ServerTransferController extends Controller
}); });
// Delete the server from the old node making sure to point it to the old node so // Delete the server from the old node making sure to point it to the old node so
// that we do not delete it from the new node the server was transfered to. // that we do not delete it from the new node the server was transferred to.
try { try {
$this->daemonServerRepository $this->daemonServerRepository
->setServer($server) ->setServer($server)
@ -183,18 +153,16 @@ class ServerTransferController extends Controller
Log::warning($exception, ['transfer_id' => $server->transfer->id]); Log::warning($exception, ['transfer_id' => $server->transfer->id]);
} }
return new JsonResponse([], Response::HTTP_NO_CONTENT); return new Response('', Response::HTTP_NO_CONTENT);
} }
/** /**
* Release all of the reserved allocations for this transfer and mark it as failed in * Release all of the reserved allocations for this transfer and mark it as failed in
* the database. * the database.
* *
* @return \Illuminate\Http\JsonResponse
*
* @throws \Throwable * @throws \Throwable
*/ */
protected function processFailedTransfer(ServerTransfer $transfer) protected function processFailedTransfer(ServerTransfer $transfer): Response
{ {
$this->connection->transaction(function () use (&$transfer) { $this->connection->transaction(function () use (&$transfer) {
$transfer->forceFill(['successful' => false])->saveOrFail(); $transfer->forceFill(['successful' => false])->saveOrFail();
@ -207,6 +175,6 @@ class ServerTransferController extends Controller
Allocation::query()->whereIn('id', $allocations)->update(['server_id' => null]); Allocation::query()->whereIn('id', $allocations)->update(['server_id' => null]);
}); });
return new JsonResponse([], Response::HTTP_NO_CONTENT); return new Response('', Response::HTTP_NO_CONTENT);
} }
} }

View File

@ -19,28 +19,17 @@ class SftpAuthenticationController extends Controller
{ {
use ThrottlesLogins; use ThrottlesLogins;
/** private UserRepository $userRepository;
* @var \Pterodactyl\Repositories\Eloquent\UserRepository private ServerRepository $serverRepository;
*/ private GetUserPermissionsService $permissionsService;
private $userRepository;
/** /**
* @var \Pterodactyl\Repositories\Eloquent\ServerRepository * SftpAuthenticationController constructor.
*/
private $serverRepository;
/**
* @var \Pterodactyl\Services\Servers\GetUserPermissionsService
*/
private $permissionsService;
/**
* SftpController constructor.
*/ */
public function __construct( public function __construct(
GetUserPermissionsService $permissionsService,
UserRepository $userRepository, UserRepository $userRepository,
ServerRepository $serverRepository ServerRepository $serverRepository,
GetUserPermissionsService $permissionsService
) { ) {
$this->userRepository = $userRepository; $this->userRepository = $userRepository;
$this->serverRepository = $serverRepository; $this->serverRepository = $serverRepository;