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\Support\Collection;
use Illuminate\Container\Container;
use Illuminate\Support\Facades\Log;
use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Extensions\Spatie\Fractalistic\Fractal;
use Pterodactyl\Transformers\Api\Application\BaseTransformer;
abstract class ApplicationApiController extends Controller
{
/**
* @var \Illuminate\Http\Request
*/
protected $request;
/**
* @var \Pterodactyl\Extensions\Spatie\Fractalistic\Fractal
*/
protected $fractal;
protected Request $request;
protected Fractal $fractal;
/**
* ApplicationApiController constructor.
@ -56,11 +48,9 @@ abstract class ApplicationApiController extends Controller
/**
* Return an instance of an application transformer.
*
* @return \Pterodactyl\Transformers\Api\Application\BaseTransformer
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function getTransformer(string $abstract)
public function getTransformer(string $abstract): BaseTransformer
{
/** @var \Pterodactyl\Transformers\Api\Application\BaseTransformer $transformer */
$transformer = Container::getInstance()->make($abstract);
@ -72,6 +62,14 @@ abstract class ApplicationApiController extends Controller
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.
*/

View File

@ -2,6 +2,7 @@
namespace Pterodactyl\Http\Controllers\Api\Application\Databases;
use Illuminate\Http\Response;
use Illuminate\Http\JsonResponse;
use Pterodactyl\Models\DatabaseHost;
use Spatie\QueryBuilder\QueryBuilder;
@ -101,10 +102,10 @@ class DatabaseController extends ApplicationApiController
*
* @throws \Exception
*/
public function delete(DeleteDatabaseRequest $request, DatabaseHost $databaseHost): JsonResponse
public function delete(DeleteDatabaseRequest $request, DatabaseHost $databaseHost): Response
{
$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\Nest;
use Illuminate\Http\Response;
use Illuminate\Http\JsonResponse;
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
use Pterodactyl\Transformers\Api\Application\EggTransformer;
@ -16,15 +17,10 @@ use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
class EggController extends ApplicationApiController
{
/**
* @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface
*/
private $repository;
private EggRepositoryInterface $repository;
/**
* EggController constructor.
*
* @param \Pterodactyl\Contracts\Repository\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.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Eggs\GetEggsRequest $request
* @param \Pterodactyl\Models\Nest $nest
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function index(GetEggsRequest $request, Nest $nest): array
@ -56,10 +48,6 @@ class EggController extends ApplicationApiController
/**
* 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
*/
public function view(GetEggRequest $request, Egg $egg): array
@ -72,9 +60,6 @@ class EggController extends ApplicationApiController
/**
* Creates a new egg.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Eggs\StoreEggRequest $request
*
* @return \Illuminate\Http\JsonResponse
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function store(StoreEggRequest $request): JsonResponse
@ -89,10 +74,6 @@ class EggController extends ApplicationApiController
/**
* Updates an egg.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Eggs\UpdateEggRequest $request
* @param \Pterodactyl\Models\Egg $egg
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function update(UpdateEggRequest $request, Egg $egg): array
@ -107,16 +88,12 @@ class EggController extends ApplicationApiController
/**
* Deletes an egg.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Eggs\DeleteEggRequest $request
* @param \Pterodactyl\Models\Egg $egg
*
* @return \Illuminate\Http\JsonResponse
* @throws \Exception
*/
public function delete(DeleteEggRequest $request, Egg $egg): JsonResponse
public function delete(DeleteEggRequest $request, Egg $egg): Response
{
$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;
use Illuminate\Http\Response;
use Pterodactyl\Models\Location;
use Illuminate\Http\JsonResponse;
use Spatie\QueryBuilder\QueryBuilder;
@ -44,6 +45,8 @@ class LocationController extends ApplicationApiController
/**
* Return all of the locations currently registered on the Panel.
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function index(GetLocationsRequest $request): array
{
@ -66,6 +69,8 @@ class LocationController extends ApplicationApiController
/**
* Return a single location.
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function view(GetLocationRequest $request, Location $location): array
{
@ -79,6 +84,7 @@ class LocationController extends ApplicationApiController
* new location attached.
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function store(StoreLocationRequest $request): JsonResponse
{
@ -115,10 +121,10 @@ class LocationController extends ApplicationApiController
*
* @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);
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
return $this->returnNoContent();
}
}

View File

@ -3,6 +3,7 @@
namespace Pterodactyl\Http\Controllers\Api\Application\Mounts;
use Pterodactyl\Models\Mount;
use Illuminate\Http\Response;
use Illuminate\Http\JsonResponse;
use Spatie\QueryBuilder\QueryBuilder;
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\MountNodesRequest;
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\UpdateMountRequest;
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
class MountController extends ApplicationApiController
@ -29,9 +30,6 @@ class MountController extends ApplicationApiController
/**
* Returns an array of all mount.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Mounts\GetMountsRequest $request
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function index(GetMountsRequest $request): array
@ -56,10 +54,6 @@ class MountController extends ApplicationApiController
/**
* 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
*/
public function view(GetMountRequest $request, Mount $mount): array
@ -72,9 +66,6 @@ class MountController extends ApplicationApiController
/**
* Creates a new mount.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Mounts\StoreMountRequest $request
*
* @return \Illuminate\Http\JsonResponse
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function store(StoreMountRequest $request): JsonResponse
@ -89,10 +80,6 @@ class MountController extends ApplicationApiController
/**
* Updates a mount.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Mounts\UpdateMountRequest $request
* @param \Pterodactyl\Models\Mount $mount
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function update(UpdateMountRequest $request, Mount $mount): array
@ -107,26 +94,19 @@ class MountController extends ApplicationApiController
/**
* Deletes a mount.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Mounts\DeleteMountRequest $request
* @param \Pterodactyl\Models\Mount $mount
*
* @return \Illuminate\Http\JsonResponse
* @throws \Exception
*/
public function delete(DeleteMountRequest $request, Mount $mount): JsonResponse
public function delete(DeleteMountRequest $request, Mount $mount): Response
{
$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
* @param \Pterodactyl\Models\Mount $mount
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
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
* @param \Pterodactyl\Models\Mount $mount
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
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
* @param \Pterodactyl\Models\Mount $mount
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
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
* @param \Pterodactyl\Models\Mount $mount
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function deleteNodes(MountNodesRequest $request, Mount $mount): array
{

View File

@ -3,7 +3,7 @@
namespace Pterodactyl\Http\Controllers\Api\Application\Nests;
use Pterodactyl\Models\Nest;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Response;
use Pterodactyl\Services\Nests\NestUpdateService;
use Pterodactyl\Services\Nests\NestCreationService;
use Pterodactyl\Services\Nests\NestDeletionService;
@ -13,31 +13,16 @@ use Pterodactyl\Http\Requests\Api\Application\Nests\GetNestRequest;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Pterodactyl\Http\Requests\Api\Application\Nests\GetNestsRequest;
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\UpdateNestRequest;
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
class NestController extends ApplicationApiController
{
/**
* @var \Pterodactyl\Contracts\Repository\NestRepositoryInterface
*/
private $repository;
/**
* @var \Pterodactyl\Services\Nests\NestCreationService
*/
protected $nestCreationService;
/**
* @var \Pterodactyl\Services\Nests\NestDeletionService
*/
protected $nestDeletionService;
/**
* @var \Pterodactyl\Services\Nests\NestUpdateService
*/
protected $nestUpdateService;
private NestRepositoryInterface $repository;
protected NestCreationService $nestCreationService;
protected NestDeletionService $nestDeletionService;
protected NestUpdateService $nestUpdateService;
/**
* NestController constructor.
@ -59,6 +44,8 @@ class NestController extends ApplicationApiController
/**
* Return all Nests that exist on the Panel.
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function index(GetNestsRequest $request): array
{
@ -79,10 +66,6 @@ class NestController extends ApplicationApiController
/**
* 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
*/
public function view(GetNestRequest $request, Nest $nest): array
@ -95,9 +78,6 @@ class NestController extends ApplicationApiController
/**
* Creates a new nest.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Nests\StoreNestRequest $request
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
*/
@ -113,10 +93,6 @@ class NestController extends ApplicationApiController
/**
* 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 \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
@ -133,16 +109,12 @@ class NestController extends ApplicationApiController
/**
* 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
*/
public function delete(DeleteNestRequest $request, Nest $nest): JsonResponse
public function delete(DeleteNestRequest $request, Nest $nest): Response
{
$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;
use Pterodactyl\Models\Node;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Response;
use Pterodactyl\Models\Allocation;
use Pterodactyl\Services\Allocations\AssignmentService;
use Pterodactyl\Services\Allocations\AllocationDeletionService;
@ -15,21 +15,11 @@ use Pterodactyl\Http\Requests\Api\Application\Allocations\DeleteAllocationReques
class AllocationController extends ApplicationApiController
{
/**
* @var \Pterodactyl\Services\Allocations\AssignmentService
*/
private $assignmentService;
/**
* @var \Pterodactyl\Services\Allocations\AllocationDeletionService
*/
private $deletionService;
private AssignmentService $assignmentService;
private AllocationDeletionService $deletionService;
/**
* AllocationController constructor.
*
* @param \Pterodactyl\Services\Allocations\AssignmentService $assignmentService
* @param \Pterodactyl\Services\Allocations\AllocationDeletionService $deletionService
*/
public function __construct(
AssignmentService $assignmentService,
@ -44,10 +34,6 @@ class AllocationController extends ApplicationApiController
/**
* 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
*/
public function index(GetAllocationsRequest $request, Node $node): array
@ -62,36 +48,28 @@ class AllocationController extends ApplicationApiController
/**
* Store new allocations for a given node.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Allocations\StoreAllocationRequest $request
* @param \Pterodactyl\Models\Node $node
* @return \Illuminate\Http\JsonResponse
*
* @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Pterodactyl\Exceptions\Service\Allocation\CidrOutOfRangeException
* @throws \Pterodactyl\Exceptions\Service\Allocation\InvalidPortMappingException
* @throws \Pterodactyl\Exceptions\Service\Allocation\PortOutOfRangeException
* @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());
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
return $this->returnNoContent();
}
/**
* 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
*/
public function delete(DeleteAllocationRequest $request, Node $node, Allocation $allocation): JsonResponse
public function delete(DeleteAllocationRequest $request, Node $node, Allocation $allocation): Response
{
$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
* with, and the node is known.
*
* @return string
* @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') {
return $node->getYamlConfiguration();

View File

@ -3,6 +3,7 @@
namespace Pterodactyl\Http\Controllers\Api\Application\Nodes;
use Pterodactyl\Models\Node;
use Illuminate\Http\Response;
use Illuminate\Http\JsonResponse;
use Spatie\QueryBuilder\QueryBuilder;
use Pterodactyl\Services\Nodes\NodeUpdateService;
@ -20,34 +21,19 @@ use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
class NodeController extends ApplicationApiController
{
/**
* @var \Pterodactyl\Services\Nodes\NodeCreationService
*/
private $creationService;
/**
* @var \Pterodactyl\Services\Nodes\NodeDeletionService
*/
private $deletionService;
/**
* @var \Pterodactyl\Contracts\Repository\NodeRepositoryInterface
*/
private $repository;
/**
* @var \Pterodactyl\Services\Nodes\NodeUpdateService
*/
private $updateService;
private NodeRepositoryInterface $repository;
private NodeCreationService $creationService;
private NodeDeletionService $deletionService;
private NodeUpdateService $updateService;
/**
* NodeController constructor.
*/
public function __construct(
NodeRepositoryInterface $repository,
NodeCreationService $creationService,
NodeDeletionService $deletionService,
NodeUpdateService $updateService,
NodeRepositoryInterface $repository
NodeUpdateService $updateService
) {
parent::__construct();
@ -59,6 +45,8 @@ class NodeController extends ApplicationApiController
/**
* Return all of the nodes currently available on the Panel.
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function index(GetNodesRequest $request): array
{
@ -81,6 +69,8 @@ class NodeController extends ApplicationApiController
/**
* Return data for a single instance of a node.
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function view(GetNodeRequest $request, Node $node): array
{
@ -94,6 +84,7 @@ class NodeController extends ApplicationApiController
* status response on success.
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function store(StoreNodeRequest $request): JsonResponse
{
@ -133,10 +124,10 @@ class NodeController extends ApplicationApiController
*
* @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);
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
{
/**
* @var \Pterodactyl\Services\Deployment\FindViableNodesService
*/
private $viableNodesService;
private FindViableNodesService $viableNodesService;
/**
* NodeDeploymentController constructor.
@ -29,6 +26,7 @@ class NodeDeploymentController extends ApplicationApiController
* 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.
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
* @throws \Pterodactyl\Exceptions\Service\Deployment\NoViableNodeException
*/
public function __invoke(GetDeployableNodesRequest $request): array

View File

@ -2,6 +2,7 @@
namespace Pterodactyl\Http\Controllers\Api\Application\Roles;
use Illuminate\Http\Response;
use Illuminate\Http\JsonResponse;
use Pterodactyl\Models\AdminRole;
use Pterodactyl\Transformers\Api\Application\AdminRoleTransformer;
@ -82,10 +83,10 @@ class RoleController extends ApplicationApiController
*
* @throws \Exception
*/
public function delete(DeleteRoleRequest $request, AdminRole $role): JsonResponse
public function delete(DeleteRoleRequest $request, AdminRole $role): Response
{
$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
{
/**
* @var \Pterodactyl\Services\Databases\DatabaseManagementService
*/
private $databaseManagementService;
/**
* @var \Pterodactyl\Services\Databases\DatabasePasswordService
*/
private $databasePasswordService;
/**
* @var \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface
*/
private $repository;
private DatabaseManagementService $databaseManagementService;
private DatabasePasswordService $databasePasswordService;
private DatabaseRepositoryInterface $repository;
/**
* DatabaseController constructor.
@ -51,6 +40,8 @@ class DatabaseController extends ApplicationApiController
/**
* Return a listing of all databases currently available to a single
* server.
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function index(GetServerDatabasesRequest $request, Server $server): array
{
@ -61,6 +52,8 @@ class DatabaseController extends ApplicationApiController
/**
* Return a single server database.
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function view(GetServerDatabaseRequest $request, Server $server, Database $database): array
{
@ -74,11 +67,11 @@ class DatabaseController extends ApplicationApiController
*
* @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);
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.
*
* @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);
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.
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function index(GetExternalServerRequest $request): array
{

View File

@ -92,11 +92,6 @@ class ServerController extends ApplicationApiController
/**
* 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 \Throwable
*/

View File

@ -12,15 +12,8 @@ use Pterodactyl\Http\Requests\Api\Application\Servers\UpdateServerBuildConfigura
class ServerDetailsController extends ApplicationApiController
{
/**
* @var \Pterodactyl\Services\Servers\BuildModificationService
*/
private $buildModificationService;
/**
* @var \Pterodactyl\Services\Servers\DetailsModificationService
*/
private $detailsModificationService;
private BuildModificationService $buildModificationService;
private DetailsModificationService $detailsModificationService;
/**
* ServerDetailsController constructor.
@ -38,9 +31,7 @@ class ServerDetailsController extends ApplicationApiController
/**
* Update the details for a specific server.
*
* @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Throwable
*/
public function details(UpdateServerDetailsRequest $request, Server $server): array
{
@ -57,13 +48,7 @@ class ServerDetailsController extends ApplicationApiController
/**
* Update the build details for a specific server.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Servers\UpdateServerBuildConfigurationRequest $request
* @param \Pterodactyl\Models\Server $server
* @return array
*
* @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Throwable
*/
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
{
/**
* @var \Pterodactyl\Services\Servers\ReinstallServerService
*/
private $reinstallServerService;
/**
* @var \Pterodactyl\Services\Servers\SuspensionService
*/
private $suspensionService;
private ReinstallServerService $reinstallServerService;
private SuspensionService $suspensionService;
/**
* SuspensionController constructor.
@ -61,9 +54,7 @@ class ServerManagementController extends ApplicationApiController
/**
* Mark a server as needing to be reinstalled.
*
* @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Throwable
*/
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
{
/**
* @var \Pterodactyl\Services\Servers\StartupModificationService
*/
private $modificationService;
private StartupModificationService $modificationService;
/**
* StartupController constructor.
@ -29,10 +26,7 @@ class StartupController extends ApplicationApiController
/**
* Update the startup and environment settings for a specific server.
*
* @throws \Illuminate\Validation\ValidationException
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Throwable
*/
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.
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function index(GetExternalUserRequest $request): array
{

View File

@ -3,6 +3,7 @@
namespace Pterodactyl\Http\Controllers\Api\Application\Users;
use Pterodactyl\Models\User;
use Illuminate\Http\Response;
use Illuminate\Http\JsonResponse;
use Spatie\QueryBuilder\QueryBuilder;
use Pterodactyl\Services\Users\UserUpdateService;
@ -20,25 +21,10 @@ use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
class UserController extends ApplicationApiController
{
/**
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface
*/
private $repository;
/**
* @var \Pterodactyl\Services\Users\UserCreationService
*/
private $creationService;
/**
* @var \Pterodactyl\Services\Users\UserDeletionService
*/
private $deletionService;
/**
* @var \Pterodactyl\Services\Users\UserUpdateService
*/
private $updateService;
private UserRepositoryInterface $repository;
private UserCreationService $creationService;
private UserDeletionService $deletionService;
private UserUpdateService $updateService;
/**
* UserController constructor.
@ -62,9 +48,6 @@ class UserController extends ApplicationApiController
* of a collection of users including any defined relations passed in
* the request.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Users\GetUsersRequest $request
*
* @return array
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
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
* were defined in the request.
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function view(GetUserRequest $request, User $user): array
{
@ -146,10 +131,10 @@ class UserController extends ApplicationApiController
*
* @throws \Pterodactyl\Exceptions\DisplayException
*/
public function delete(DeleteUserRequest $request, User $user): JsonResponse
public function delete(DeleteUserRequest $request, User $user): Response
{
$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
{
/**
* @var \Pterodactyl\Services\Helpers\SoftwareVersionService
*/
private SoftwareVersionService $softwareVersionService;
/**
* VersionController constructor.
*
* @param \Pterodactyl\Services\Helpers\SoftwareVersionService $softwareVersionService
*/
public function __construct(SoftwareVersionService $softwareVersionService)
{
@ -26,8 +21,6 @@ class VersionController extends ApplicationApiController
/**
* Returns version information.
*
* @return \Illuminate\Http\JsonResponse
*/
public function __invoke(): JsonResponse
{

View File

@ -4,8 +4,8 @@ namespace Pterodactyl\Http\Controllers\Api\Client;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Auth\AuthManager;
use Illuminate\Http\JsonResponse;
use Illuminate\Auth\SessionGuard;
use Pterodactyl\Services\Users\UserUpdateService;
use Pterodactyl\Transformers\Api\Client\AccountTransformer;
use Pterodactyl\Http\Requests\Api\Client\Account\UpdateEmailRequest;
@ -13,27 +13,25 @@ use Pterodactyl\Http\Requests\Api\Client\Account\UpdatePasswordRequest;
class AccountController extends ClientApiController
{
/**
* @var \Pterodactyl\Services\Users\UserUpdateService
*/
private $updateService;
/**
* @var \Illuminate\Auth\SessionGuard
*/
private $sessionGuard;
private SessionGuard $sessionGuard;
private UserUpdateService $updateService;
/**
* AccountController constructor.
*/
public function __construct(AuthManager $sessionGuard, UserUpdateService $updateService)
public function __construct(SessionGuard $sessionGuard, UserUpdateService $updateService)
{
parent::__construct();
$this->updateService = $updateService;
$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
{
return $this->fractal->item($request->user())
@ -51,7 +49,7 @@ class AccountController extends ClientApiController
{
$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'));
return new JsonResponse([], Response::HTTP_NO_CONTENT);
return $this->returnNoContent();
}
}

View File

@ -2,8 +2,8 @@
namespace Pterodactyl\Http\Controllers\Api\Client;
use Illuminate\Http\Response;
use Pterodactyl\Models\ApiKey;
use Illuminate\Http\JsonResponse;
use Pterodactyl\Exceptions\DisplayException;
use Illuminate\Contracts\Encryption\Encrypter;
use Pterodactyl\Services\Api\KeyCreationService;
@ -15,42 +15,31 @@ use Pterodactyl\Http\Requests\Api\Client\Account\StoreApiKeyRequest;
class ApiKeyController extends ClientApiController
{
/**
* @var \Pterodactyl\Services\Api\KeyCreationService
*/
private $keyCreationService;
/**
* @var \Illuminate\Contracts\Encryption\Encrypter
*/
private $encrypter;
/**
* @var \Pterodactyl\Repositories\Eloquent\ApiKeyRepository
*/
private $repository;
private Encrypter $encrypter;
private ApiKeyRepository $repository;
private KeyCreationService $keyCreationService;
/**
* ApiKeyController constructor.
*/
public function __construct(
Encrypter $encrypter,
KeyCreationService $keyCreationService,
ApiKeyRepository $repository
ApiKeyRepository $repository,
KeyCreationService $keyCreationService
) {
parent::__construct();
$this->encrypter = $encrypter;
$this->keyCreationService = $keyCreationService;
$this->repository = $repository;
$this->keyCreationService = $keyCreationService;
}
/**
* 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)
->transformWith($this->getTransformer(ApiKeyTransformer::class))
@ -60,12 +49,11 @@ class ApiKeyController extends ClientApiController
/**
* Store a new API key for a user's account.
*
* @return array
*
* @throws \Pterodactyl\Exceptions\DisplayException
* @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) {
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.
*
* @return \Illuminate\Http\JsonResponse
*/
public function delete(ClientApiRequest $request, string $identifier)
public function delete(ClientApiRequest $request, string $identifier): Response
{
$response = $this->repository->deleteWhere([
'key_type' => ApiKey::TYPE_ACCOUNT,
@ -102,6 +88,6 @@ class ApiKeyController extends ClientApiController
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[]
*/
protected function getIncludesForTransformer(BaseClientTransformer $transformer, array $merge = [])
protected function getIncludesForTransformer(BaseClientTransformer $transformer, array $merge = []): array
{
$filtered = array_filter($this->parseIncludes(), function ($datum) use ($transformer) {
return in_array($datum, $transformer->getAvailableIncludes());
@ -29,7 +29,7 @@ abstract class ClientApiController extends ApplicationApiController
*
* @return string[]
*/
protected function parseIncludes()
protected function parseIncludes(): array
{
$includes = $this->request->query('include') ?? [];
@ -45,9 +45,9 @@ abstract class ClientApiController extends ApplicationApiController
/**
* 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 */
$transformer = Container::getInstance()->make($abstract);

View File

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

View File

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

View File

@ -42,6 +42,8 @@ class DatabaseController extends ClientApiController
/**
* Return all of the databases that belong to the given server.
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
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
* the caller.
*
* @return array
*
* @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);
$database->refresh();
@ -89,12 +89,12 @@ class DatabaseController extends ClientApiController
/**
* Removes a database from the server.
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Exception
*/
public function delete(DeleteDatabaseRequest $request, Server $server, Database $database): Response
{
$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 Pterodactyl\Models\Server;
use Pterodactyl\Models\AuditLog;
use Illuminate\Http\JsonResponse;
use Pterodactyl\Services\Nodes\NodeJWTService;
use Illuminate\Contracts\Routing\ResponseFactory;
use Pterodactyl\Repositories\Wings\DaemonFileRepository;
@ -26,28 +25,17 @@ use Pterodactyl\Http\Requests\Api\Client\Servers\Files\WriteFileContentRequest;
class FileController extends ClientApiController
{
/**
* @var \Pterodactyl\Repositories\Wings\DaemonFileRepository
*/
private $fileRepository;
/**
* @var \Illuminate\Contracts\Routing\ResponseFactory
*/
private $responseFactory;
/**
* @var \Pterodactyl\Services\Nodes\NodeJWTService
*/
private $jwtService;
private DaemonFileRepository $fileRepository;
private ResponseFactory $responseFactory;
private NodeJWTService $jwtService;
/**
* FileController constructor.
*/
public function __construct(
DaemonFileRepository $fileRepository,
ResponseFactory $responseFactory,
NodeJWTService $jwtService,
DaemonFileRepository $fileRepository
NodeJWTService $jwtService
) {
parent::__construct();
@ -60,6 +48,7 @@ class FileController extends ClientApiController
* Returns a listing of files in a given directory.
*
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
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
* download a given file.
*
* @return array
*
* @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) {
$audit->metadata = ['file' => $request->get('file')];
@ -124,9 +111,9 @@ class FileController extends ClientApiController
/**
* 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) {
$audit->subaction = 'write_content';
@ -137,7 +124,7 @@ class FileController extends ClientApiController
->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
*/
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) {
$audit->subaction = 'create_folder';
@ -156,7 +143,7 @@ class FileController extends ClientApiController
->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
*/
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) {
$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'));
});
return new JsonResponse([], Response::HTTP_NO_CONTENT);
return $this->returnNoContent();
}
/**
* 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) {
$audit->subaction = 'copy_file';
@ -193,11 +180,11 @@ class FileController extends ClientApiController
->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
{
@ -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) {
// 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'));
});
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
return $this->returnNoContent();
}
/**
* 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) {
$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
*/
public function chmod(ChmodFilesRequest $request, Server $server): JsonResponse
public function chmod(ChmodFilesRequest $request, Server $server): Response
{
$this->fileRepository->setServer($server)
->chmodFiles(
@ -270,17 +257,15 @@ class FileController extends ClientApiController
$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.
*
* @param $request
*
* @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) {
$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'));
});
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
{
/**
* @var \Pterodactyl\Services\Nodes\NodeJWTService
*/
private $jwtService;
private NodeJWTService $jwtService;
/**
* FileUploadController constructor.
*/
public function __construct(
NodeJWTService $jwtService
) {
public function __construct(NodeJWTService $jwtService)
{
parent::__construct();
$this->jwtService = $jwtService;
@ -30,10 +26,8 @@ class FileUploadController extends ClientApiController
/**
* 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([
'object' => 'signed_url',
@ -45,10 +39,8 @@ class FileUploadController extends ClientApiController
/**
* 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
->setExpiresAt(CarbonImmutable::now()->addMinutes(15)->toDateTimeImmutable())

View File

@ -2,8 +2,8 @@
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
use Illuminate\Http\Response;
use Pterodactyl\Models\Server;
use Illuminate\Http\JsonResponse;
use Pterodactyl\Models\Allocation;
use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Repositories\Eloquent\ServerRepository;
@ -19,20 +19,9 @@ use Pterodactyl\Http\Requests\Api\Client\Servers\Network\SetPrimaryAllocationReq
class NetworkAllocationController extends ClientApiController
{
/**
* @var \Pterodactyl\Repositories\Eloquent\AllocationRepository
*/
private $repository;
/**
* @var \Pterodactyl\Repositories\Eloquent\ServerRepository
*/
private $serverRepository;
/**
* @var \Pterodactyl\Services\Allocations\FindAssignableAllocationService
*/
private $assignableAllocationService;
private AllocationRepository $repository;
private ServerRepository $serverRepository;
private FindAssignableAllocationService $assignableAllocationService;
/**
* 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.
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function index(GetNetworkRequest $request, Server $server): array
{
@ -65,6 +56,7 @@ class NetworkAllocationController extends ClientApiController
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
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\Repository\RecordNotFoundException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
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.
*s.
*
* @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function store(NewAllocationRequest $request, Server $server): array
{
@ -114,11 +107,9 @@ class NetworkAllocationController extends ClientApiController
/**
* Delete an allocation from a server.
*
* @return \Illuminate\Http\JsonResponse
*
* @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) {
throw new DisplayException('You cannot delete the primary allocation for this server.');
@ -129,6 +120,6 @@ class NetworkAllocationController extends ClientApiController
'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
{
/**
* @var \Pterodactyl\Repositories\Wings\DaemonPowerRepository
*/
private $repository;
private DaemonPowerRepository $repository;
/**
* PowerController constructor.

View File

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

View File

@ -8,7 +8,6 @@ use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Pterodactyl\Models\Server;
use Pterodactyl\Models\Schedule;
use Illuminate\Http\JsonResponse;
use Pterodactyl\Helpers\Utilities;
use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Repositories\Eloquent\ScheduleRepository;
@ -25,15 +24,8 @@ use Pterodactyl\Http\Requests\Api\Client\Servers\Schedules\TriggerScheduleReques
class ScheduleController extends ClientApiController
{
/**
* @var \Pterodactyl\Repositories\Eloquent\ScheduleRepository
*/
private $repository;
/**
* @var \Pterodactyl\Services\Schedules\ProcessScheduleService
*/
private $service;
private ScheduleRepository $repository;
private ProcessScheduleService $service;
/**
* ScheduleController constructor.
@ -49,9 +41,9 @@ class ScheduleController extends ClientApiController
/**
* 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->loadMissing('tasks');
@ -64,12 +56,11 @@ class ScheduleController extends ClientApiController
/**
* Store a new schedule for a server.
*
* @return array
*
* @throws \Pterodactyl\Exceptions\DisplayException
* @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 */
$model = $this->repository->create([
@ -92,9 +83,9 @@ class ScheduleController extends ClientApiController
/**
* 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) {
throw new NotFoundHttpException();
@ -110,13 +101,12 @@ class ScheduleController extends ClientApiController
/**
* Updates a given schedule with the new data provided.
*
* @return array
*
* @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @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');
@ -150,31 +140,27 @@ class ScheduleController extends ClientApiController
* Executes a given schedule immediately rather than waiting on it's normally scheduled time
* to pass. This does not care about the schedule state.
*
* @return \Illuminate\Http\JsonResponse
*
* @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) {
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);
return new JsonResponse([], JsonResponse::HTTP_ACCEPTED);
return $this->returnAccepted();
}
/**
* 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);
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 Pterodactyl\Models\Server;
use Pterodactyl\Models\Schedule;
use Illuminate\Http\JsonResponse;
use Pterodactyl\Models\Permission;
use Pterodactyl\Repositories\Eloquent\TaskRepository;
use Pterodactyl\Exceptions\Http\HttpForbiddenException;
@ -19,10 +18,7 @@ use Pterodactyl\Http\Requests\Api\Client\Servers\Schedules\StoreTaskRequest;
class ScheduleTaskController extends ClientApiController
{
/**
* @var \Pterodactyl\Repositories\Eloquent\TaskRepository
*/
private $repository;
private TaskRepository $repository;
/**
* ScheduleTaskController constructor.
@ -37,12 +33,11 @@ class ScheduleTaskController extends ClientApiController
/**
* Create a new task for a given schedule and store it in the database.
*
* @return array
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @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);
if ($schedule->tasks()->count() >= $limit) {
@ -69,12 +64,11 @@ class ScheduleTaskController extends ClientApiController
/**
* Updates a given task for a server.
*
* @return array
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @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) {
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
* for this schedule their sequence IDs are decremented properly.
*
* @return \Illuminate\Http\JsonResponse
*
* @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) {
throw new NotFoundHttpException();
@ -115,6 +107,6 @@ class ScheduleTaskController extends ClientApiController
$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
{
/**
* @var \Pterodactyl\Repositories\Eloquent\SubuserRepository
*/
private $repository;
/**
* @var \Pterodactyl\Services\Servers\GetUserPermissionsService
*/
private $permissionsService;
private SubuserRepository $repository;
private GetUserPermissionsService $permissionsService;
/**
* ServerController constructor.
@ -35,6 +28,8 @@ class ServerController extends ClientApiController
/**
* Transform an individual server into a response that can be consumed by a
* client using the API.
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
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 Pterodactyl\Models\Server;
use Illuminate\Http\JsonResponse;
use Pterodactyl\Repositories\Eloquent\ServerRepository;
use Pterodactyl\Services\Servers\ReinstallServerService;
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
@ -15,15 +14,8 @@ use Pterodactyl\Http\Requests\Api\Client\Servers\Settings\ReinstallServerRequest
class SettingsController extends ClientApiController
{
/**
* @var \Pterodactyl\Repositories\Eloquent\ServerRepository
*/
private $repository;
/**
* @var \Pterodactyl\Services\Servers\ReinstallServerService
*/
private $reinstallServerService;
private ServerRepository $repository;
private ReinstallServerService $reinstallServerService;
/**
* SettingsController constructor.
@ -41,42 +33,36 @@ class SettingsController extends ClientApiController
/**
* Renames a server.
*
* @return \Illuminate\Http\JsonResponse
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @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, [
'name' => $request->input('name'),
]);
return new JsonResponse([], Response::HTTP_NO_CONTENT);
return $this->returnNoContent();
}
/**
* Reinstalls the server on the daemon.
*
* @return \Illuminate\Http\JsonResponse
*
* @throws \Throwable
*/
public function reinstall(ReinstallServerRequest $request, Server $server)
public function reinstall(ReinstallServerRequest $request, Server $server): Response
{
$this->reinstallServerService->handle($server);
return new JsonResponse([], Response::HTTP_ACCEPTED);
return $this->returnAccepted();
}
/**
* Changes the Docker image in use by the server.
*
* @return \Illuminate\Http\JsonResponse
*
* @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)) {
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();
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
{
/**
* @var \Pterodactyl\Services\Servers\VariableValidatorService
*/
private $service;
/**
* @var \Pterodactyl\Repositories\Eloquent\ServerVariableRepository
*/
private $repository;
/**
* @var \Pterodactyl\Services\Servers\StartupCommandService
*/
private $startupCommandService;
private VariableValidatorService $service;
private ServerVariableRepository $repository;
private StartupCommandService $startupCommandService;
/**
* StartupController constructor.
@ -44,9 +33,9 @@ class StartupController extends ClientApiController
/**
* 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);
@ -65,13 +54,12 @@ class StartupController extends ClientApiController
/**
* Updates a single variable for a server.
*
* @return array
*
* @throws \Illuminate\Validation\ValidationException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @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 */
$variable = $server->variables()->where('env_variable', $request->input('key'))->first();

View File

@ -3,8 +3,8 @@
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Pterodactyl\Models\Server;
use Illuminate\Http\JsonResponse;
use Pterodactyl\Models\Permission;
use Illuminate\Support\Facades\Log;
use Pterodactyl\Repositories\Eloquent\SubuserRepository;
@ -20,20 +20,9 @@ use Pterodactyl\Http\Requests\Api\Client\Servers\Subusers\UpdateSubuserRequest;
class SubuserController extends ClientApiController
{
/**
* @var \Pterodactyl\Repositories\Eloquent\SubuserRepository
*/
private $repository;
/**
* @var \Pterodactyl\Services\Subusers\SubuserCreationService
*/
private $creationService;
/**
* @var \Pterodactyl\Repositories\Wings\DaemonServerRepository
*/
private $serverRepository;
private SubuserRepository $repository;
private SubuserCreationService $creationService;
private DaemonServerRepository $serverRepository;
/**
* SubuserController constructor.
@ -53,9 +42,9 @@ class SubuserController extends ClientApiController
/**
* 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)
->transformWith($this->getTransformer(SubuserTransformer::class))
@ -65,9 +54,9 @@ class SubuserController extends ClientApiController
/**
* 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');
@ -79,14 +68,12 @@ class SubuserController extends ClientApiController
/**
* Create a new subuser for the given server.
*
* @return array
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Service\Subuser\ServerSubuserExistsException
* @throws \Pterodactyl\Exceptions\Service\Subuser\UserIsServerOwnerException
* @throws \Throwable
*/
public function store(StoreSubuserRequest $request, Server $server)
public function store(StoreSubuserRequest $request, Server $server): array
{
$response = $this->creationService->handle(
$server,
@ -104,6 +91,7 @@ class SubuserController extends ClientApiController
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function update(UpdateSubuserRequest $request, Server $server): array
{
@ -139,10 +127,8 @@ class SubuserController extends ClientApiController
/**
* 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 */
$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]);
}
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
{
/**
* @var \Pterodactyl\Services\Nodes\NodeJWTService
*/
private $jwtService;
/**
* @var \Pterodactyl\Services\Servers\GetUserPermissionsService
*/
private $permissionsService;
private NodeJWTService $jwtService;
private GetUserPermissionsService $permissionsService;
/**
* 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.
* 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.
*
* @return \Illuminate\Http\JsonResponse
*/
public function __invoke(ClientApiRequest $request, Server $server)
public function __invoke(ClientApiRequest $request, Server $server): JsonResponse
{
$user = $request->user();
if ($user->cannot(Permission::ACTION_WEBSOCKET_CONNECT, $server)) {

View File

@ -14,20 +14,9 @@ use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
class TwoFactorController extends ClientApiController
{
/**
* @var \Pterodactyl\Services\Users\TwoFactorSetupService
*/
private $setupService;
/**
* @var \Illuminate\Contracts\Validation\Factory
*/
private $validation;
/**
* @var \Pterodactyl\Services\Users\ToggleTwoFactorService
*/
private $toggleTwoFactorService;
private ToggleTwoFactorService $toggleTwoFactorService;
private TwoFactorSetupService $setupService;
private Factory $validation;
/**
* TwoFactorController constructor.
@ -39,9 +28,9 @@ class TwoFactorController extends ClientApiController
) {
parent::__construct();
$this->toggleTwoFactorService = $toggleTwoFactorService;
$this->setupService = $setupService;
$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
* will return a 400 error.
*
* @return \Illuminate\Http\JsonResponse
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function index(Request $request)
public function index(Request $request): JsonResponse
{
if ($request->user()->use_totp) {
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.
*
* @return \Illuminate\Http\JsonResponse
*
* @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
* @throws \Throwable
*/
public function store(Request $request)
public function store(Request $request): JsonResponse
{
$validator = $this->validation->make($request->all(), [
'code' => 'required|string',
@ -103,10 +82,8 @@ class TwoFactorController extends ClientApiController
/**
* Disables two-factor authentication on an account if the password provided
* 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)) {
throw new BadRequestHttpException('The password provided was not valid.');
@ -120,6 +97,6 @@ class TwoFactorController extends ClientApiController
'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;
/**
* @var \Pterodactyl\Repositories\Eloquent\BackupRepository
*/
private $repository;
/**
* @var \Pterodactyl\Extensions\Backups\BackupManager
*/
private $backupManager;
private BackupRepository $repository;
private BackupManager $backupManager;
/**
* BackupRemoteUploadController constructor.
@ -37,15 +30,13 @@ class BackupRemoteUploadController extends Controller
}
/**
* Returns the required presigned urls to upload a backup to S3 cloud storage.
*
* @return \Illuminate\Http\JsonResponse
* Returns the required pre-signed urls to upload a backup to S3 cloud storage.
*
* @throws \Exception
* @throws \Throwable
* @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.
$size = (int) $request->query('size');

View File

@ -4,6 +4,7 @@ namespace Pterodactyl\Http\Controllers\Api\Remote\Backups;
use Carbon\CarbonImmutable;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Pterodactyl\Models\Backup;
use Pterodactyl\Models\Server;
use Pterodactyl\Models\AuditLog;
@ -18,15 +19,8 @@ use Pterodactyl\Http\Requests\Api\Remote\ReportBackupCompleteRequest;
class BackupStatusController extends Controller
{
/**
* @var \Pterodactyl\Repositories\Eloquent\BackupRepository
*/
private $repository;
/**
* @var \Pterodactyl\Extensions\Backups\BackupManager
*/
private $backupManager;
private BackupRepository $repository;
private BackupManager $backupManager;
/**
* BackupStatusController constructor.
@ -40,11 +34,9 @@ class BackupStatusController extends Controller
/**
* Handles updating the state of a backup.
*
* @return \Illuminate\Http\JsonResponse
*
* @throws \Throwable
*/
public function index(ReportBackupCompleteRequest $request, string $backup)
public function index(ReportBackupCompleteRequest $request, string $backup): Response
{
/** @var \Pterodactyl\Models\Backup $model */
$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
* table tracking for this restoration.
*
* @return \Illuminate\Http\JsonResponse
*
* @throws \Throwable
*/
public function restore(Request $request, string $backup)
public function restore(Request $request, string $backup): Response
{
/** @var \Pterodactyl\Models\Backup $model */
$model = Backup::query()->where('uuid', $backup)->firstOrFail();
@ -108,7 +98,7 @@ class BackupStatusController extends Controller
$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
{
/**
* @var \Pterodactyl\Services\Servers\EnvironmentService
*/
private $environment;
/**
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
*/
private $repository;
private EnvironmentService $environment;
private ServerRepositoryInterface $repository;
/**
* EggInstallController constructor.

View File

@ -3,13 +3,13 @@
namespace Pterodactyl\Http\Controllers\Api\Remote\Servers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Pterodactyl\Models\Server;
use Pterodactyl\Models\AuditLog;
use Illuminate\Http\JsonResponse;
use Illuminate\Database\Query\Builder;
use Illuminate\Database\Query\JoinClause;
use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Repositories\Eloquent\NodeRepository;
use Pterodactyl\Services\Eggs\EggConfigurationService;
use Pterodactyl\Repositories\Eloquent\ServerRepository;
use Pterodactyl\Http\Resources\Wings\ServerConfigurationCollection;
@ -17,46 +17,30 @@ use Pterodactyl\Services\Servers\ServerConfigurationStructureService;
class ServerDetailsController extends Controller
{
/**
* @var \Pterodactyl\Services\Eggs\EggConfigurationService
*/
private $eggConfigurationService;
private ServerRepository $repository;
private ServerConfigurationStructureService $configurationStructureService;
private EggConfigurationService $eggConfigurationService;
/**
* @var \Pterodactyl\Repositories\Eloquent\ServerRepository
*/
private $repository;
/**
* @var \Pterodactyl\Services\Servers\ServerConfigurationStructureService
*/
private $configurationStructureService;
/**
* ServerConfigurationController constructor.
* ServerDetailsController constructor.
*/
public function __construct(
ServerRepository $repository,
ServerConfigurationStructureService $configurationStructureService,
EggConfigurationService $eggConfigurationService,
NodeRepository $nodeRepository
EggConfigurationService $eggConfigurationService
) {
$this->eggConfigurationService = $eggConfigurationService;
$this->repository = $repository;
$this->configurationStructureService = $configurationStructureService;
$this->eggConfigurationService = $eggConfigurationService;
}
/**
* 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.
*
* @param string $uuid
*
* @return \Illuminate\Http\JsonResponse
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function __invoke(Request $request, $uuid)
public function __invoke(Request $request, string $uuid): JsonResponse
{
$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.
*
* @return \Pterodactyl\Http\Resources\Wings\ServerConfigurationCollection
*/
public function list(Request $request)
public function list(Request $request): ServerConfigurationCollection
{
/** @var \Pterodactyl\Models\Node $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
* a Wings reboot would completely stop those processes.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\JsonResponse
*
* @throws \Throwable
*/
public function resetState(Request $request)
public function resetState(Request $request): Response
{
$node = $request->attributes->get('node');
@ -147,6 +126,6 @@ class ServerDetailsController extends Controller
->whereIn('status', [Server::STATUS_INSTALLING, Server::STATUS_RESTORING_BACKUP])
->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
{
/**
* @var \Pterodactyl\Repositories\Eloquent\ServerRepository
*/
private $repository;
private ServerRepository $repository;
/**
* ServerInstallController constructor.
@ -28,16 +25,14 @@ class ServerInstallController extends Controller
/**
* Returns installation information for a server.
*
* @return \Illuminate\Http\JsonResponse
*
* @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);
$egg = $server->egg;
return JsonResponse::create([
return new JsonResponse([
'container_image' => $egg->copy_script_container,
'entrypoint' => $egg->copy_script_entry,
'script' => $egg->copy_script_install,
@ -47,12 +42,10 @@ class ServerInstallController extends Controller
/**
* Updates the installation state of a server.
*
* @return \Illuminate\Http\JsonResponse
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @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);
@ -63,6 +56,6 @@ class ServerInstallController extends Controller
$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\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Http\JsonResponse;
use Pterodactyl\Models\Allocation;
use Illuminate\Support\Facades\Log;
use Pterodactyl\Models\ServerTransfer;
@ -21,35 +20,12 @@ use Pterodactyl\Services\Servers\ServerConfigurationStructureService;
class ServerTransferController extends Controller
{
/**
* @var \Illuminate\Database\ConnectionInterface
*/
private $connection;
/**
* @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;
private ConnectionInterface $connection;
private ServerRepository $repository;
private DaemonServerRepository $daemonServerRepository;
private DaemonTransferRepository $daemonTransferRepository;
private ServerConfigurationStructureService $configurationStructureService;
private NodeJWTService $jwtService;
/**
* ServerTransferController constructor.
@ -73,12 +49,10 @@ class ServerTransferController extends Controller
/**
* The daemon notifies us about the archive status.
*
* @return \Illuminate\Http\JsonResponse
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Throwable
*/
public function archive(Request $request, string $uuid)
public function archive(Request $request, string $uuid): Response
{
$server = $this->repository->getByUuid($uuid);
@ -122,17 +96,15 @@ class ServerTransferController extends Controller
->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.
*
* @return \Illuminate\Http\JsonResponse
*
* @throws \Throwable
*/
public function failure(string $uuid)
public function failure(string $uuid): Response
{
$server = $this->repository->getByUuid($uuid);
@ -142,11 +114,9 @@ class ServerTransferController extends Controller
/**
* The daemon notifies us about a transfer success.
*
* @return \Illuminate\Http\JsonResponse
*
* @throws \Throwable
*/
public function success(string $uuid)
public function success(string $uuid): Response
{
$server = $this->repository->getByUuid($uuid);
$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
// 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 {
$this->daemonServerRepository
->setServer($server)
@ -183,18 +153,16 @@ class ServerTransferController extends Controller
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
* the database.
*
* @return \Illuminate\Http\JsonResponse
*
* @throws \Throwable
*/
protected function processFailedTransfer(ServerTransfer $transfer)
protected function processFailedTransfer(ServerTransfer $transfer): Response
{
$this->connection->transaction(function () use (&$transfer) {
$transfer->forceFill(['successful' => false])->saveOrFail();
@ -207,6 +175,6 @@ class ServerTransferController extends Controller
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;
/**
* @var \Pterodactyl\Repositories\Eloquent\UserRepository
*/
private $userRepository;
private UserRepository $userRepository;
private ServerRepository $serverRepository;
private GetUserPermissionsService $permissionsService;
/**
* @var \Pterodactyl\Repositories\Eloquent\ServerRepository
*/
private $serverRepository;
/**
* @var \Pterodactyl\Services\Servers\GetUserPermissionsService
*/
private $permissionsService;
/**
* SftpController constructor.
* SftpAuthenticationController constructor.
*/
public function __construct(
GetUserPermissionsService $permissionsService,
UserRepository $userRepository,
ServerRepository $serverRepository
ServerRepository $serverRepository,
GetUserPermissionsService $permissionsService
) {
$this->userRepository = $userRepository;
$this->serverRepository = $serverRepository;