Skip to content

Commit 48ad8f5

Browse files
committed
Always allow specifying a page size with the API; closes pterodactyl#3218
1 parent 9b46d59 commit 48ad8f5

File tree

8 files changed

+10
-9
lines changed

8 files changed

+10
-9
lines changed

app/Http/Controllers/Api/Application/Locations/LocationController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function index(GetLocationsRequest $request): array
6565
$locations = QueryBuilder::for(Location::query())
6666
->allowedFilters(['short', 'long'])
6767
->allowedSorts(['id'])
68-
->paginate(100);
68+
->paginate($request->query('per_page') ?? 50);
6969

7070
return $this->fractal->collection($locations)
7171
->transformWith($this->getTransformer(LocationTransformer::class))

app/Http/Controllers/Api/Application/Nests/NestController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct(NestRepositoryInterface $repository)
3030
*/
3131
public function index(GetNestsRequest $request): array
3232
{
33-
$nests = $this->repository->paginated(50);
33+
$nests = $this->repository->paginated($request->query('per_page') ?? 50);
3434

3535
return $this->fractal->collection($nests)
3636
->transformWith($this->getTransformer(NestTransformer::class))

app/Http/Controllers/Api/Application/Nodes/AllocationController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function __construct(
4343
*/
4444
public function index(GetAllocationsRequest $request, Node $node): array
4545
{
46-
$allocations = $node->allocations()->paginate(50);
46+
$allocations = $node->allocations()->paginate($request->query('per_page') ?? 50);
4747

4848
return $this->fractal->collection($allocations)
4949
->transformWith($this->getTransformer(AllocationTransformer::class))
@@ -53,6 +53,7 @@ public function index(GetAllocationsRequest $request, Node $node): array
5353
/**
5454
* Store new allocations for a given node.
5555
*
56+
* @throws \Pterodactyl\Exceptions\DisplayException
5657
* @throws \Pterodactyl\Exceptions\Service\Allocation\CidrOutOfRangeException
5758
* @throws \Pterodactyl\Exceptions\Service\Allocation\InvalidPortMappingException
5859
* @throws \Pterodactyl\Exceptions\Service\Allocation\PortOutOfRangeException

app/Http/Controllers/Api/Application/Nodes/NodeController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function index(GetNodesRequest $request): array
6464
$nodes = QueryBuilder::for(Node::query())
6565
->allowedFilters(['uuid', 'name', 'fqdn', 'daemon_token_id'])
6666
->allowedSorts(['id', 'uuid', 'memory', 'disk'])
67-
->paginate(100);
67+
->paginate($request->query('per_page') ?? 50);
6868

6969
return $this->fractal->collection($nodes)
7070
->transformWith($this->getTransformer(NodeTransformer::class))

app/Http/Controllers/Api/Application/Nodes/NodeDeploymentController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __invoke(GetDeployableNodesRequest $request): array
3737
$nodes = $this->viableNodesService->setLocations($data['location_ids'] ?? [])
3838
->setMemory($data['memory'])
3939
->setDisk($data['disk'])
40-
->handle($request->input('page') ?? 0);
40+
->handle($request->query('per_page'), $request->query('page'));
4141

4242
return $this->fractal->collection($nodes)
4343
->transformWith($this->getTransformer(NodeTransformer::class))

app/Http/Controllers/Api/Application/Servers/ServerController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function index(GetServersRequest $request): array
5656
$servers = QueryBuilder::for(Server::query())
5757
->allowedFilters(['uuid', 'name', 'image', 'external_id'])
5858
->allowedSorts(['id', 'uuid'])
59-
->paginate(100);
59+
->paginate($request->query('per_page') ?? 50);
6060

6161
return $this->fractal->collection($servers)
6262
->transformWith($this->getTransformer(ServerTransformer::class))

app/Http/Controllers/Api/Application/Users/UserController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function index(GetUsersRequest $request): array
6666
$users = QueryBuilder::for(User::query())
6767
->allowedFilters(['email', 'uuid', 'username', 'external_id'])
6868
->allowedSorts(['id', 'uuid'])
69-
->paginate(100);
69+
->paginate($request->query('per_page') ?? 50);
7070

7171
return $this->fractal->collection($users)
7272
->transformWith($this->getTransformer(UserTransformer::class))

app/Services/Deployment/FindViableNodesService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function setMemory(int $memory): self
8383
*
8484
* @throws \Pterodactyl\Exceptions\Service\Deployment\NoViableNodeException
8585
*/
86-
public function handle(int $page = null)
86+
public function handle(int $perPage = null, int $page = null)
8787
{
8888
Assert::integer($this->disk, 'Disk space must be an int, got %s');
8989
Assert::integer($this->memory, 'Memory usage must be an int, got %s');
@@ -103,7 +103,7 @@ public function handle(int $page = null)
103103
->havingRaw('(IFNULL(SUM(servers.disk), 0) + ?) <= (nodes.disk * (1 + (nodes.disk_overallocate / 100)))', [$this->disk]);
104104

105105
if (!is_null($page)) {
106-
$results = $results->paginate(50, ['*'], 'page', $page);
106+
$results = $results->paginate($perPage ?? 50, ['*'], 'page', $page);
107107
} else {
108108
$results = $results->get()->toBase();
109109
}

0 commit comments

Comments
 (0)