api(application): v2 backport
This commit is contained in:
parent
4cd0bee231
commit
67bf3e342e
172 changed files with 2922 additions and 1579 deletions
|
@ -3,13 +3,14 @@
|
|||
namespace Pterodactyl\Http\Controllers\Api\Application\Nodes;
|
||||
|
||||
use Pterodactyl\Models\Node;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Response;
|
||||
use Pterodactyl\Models\Allocation;
|
||||
use Spatie\QueryBuilder\QueryBuilder;
|
||||
use Spatie\QueryBuilder\AllowedFilter;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Pterodactyl\Services\Allocations\AssignmentService;
|
||||
use Pterodactyl\Services\Allocations\AllocationDeletionService;
|
||||
use Pterodactyl\Exceptions\Http\QueryValueOutOfRangeHttpException;
|
||||
use Pterodactyl\Transformers\Api\Application\AllocationTransformer;
|
||||
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
|
||||
use Pterodactyl\Http\Requests\Api\Application\Allocations\GetAllocationsRequest;
|
||||
|
@ -33,23 +34,27 @@ class AllocationController extends ApplicationApiController
|
|||
*/
|
||||
public function index(GetAllocationsRequest $request, Node $node): array
|
||||
{
|
||||
$allocations = QueryBuilder::for($node->allocations())
|
||||
->allowedFilters([
|
||||
AllowedFilter::exact('ip'),
|
||||
AllowedFilter::exact('port'),
|
||||
'ip_alias',
|
||||
AllowedFilter::callback('server_id', function (Builder $builder, $value) {
|
||||
if (empty($value) || is_bool($value) || !ctype_digit((string) $value)) {
|
||||
return $builder->whereNull('server_id');
|
||||
}
|
||||
$perPage = (int) $request->query('per_page', '10');
|
||||
if ($perPage < 1 || $perPage > 100) {
|
||||
throw new QueryValueOutOfRangeHttpException('per_page', 1, 100);
|
||||
}
|
||||
|
||||
return $builder->where('server_id', $value);
|
||||
$allocations = QueryBuilder::for(Allocation::query()->where('node_id', '=', $node->id))
|
||||
->allowedFilters([
|
||||
'id', 'ip', 'port', 'alias',
|
||||
AllowedFilter::callback('server_id', function (Builder $query, $value) {
|
||||
if ($value === '0') {
|
||||
$query->whereNull('server_id');
|
||||
} else {
|
||||
$query->where('server_id', '=', $value);
|
||||
}
|
||||
}),
|
||||
])
|
||||
->paginate($request->query('per_page') ?? 50);
|
||||
->allowedSorts(['id', 'ip', 'port', 'server_id'])
|
||||
->paginate($perPage);
|
||||
|
||||
return $this->fractal->collection($allocations)
|
||||
->transformWith($this->getTransformer(AllocationTransformer::class))
|
||||
->transformWith(AllocationTransformer::class)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
@ -62,11 +67,11 @@ class AllocationController extends ApplicationApiController
|
|||
* @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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -74,10 +79,10 @@ class AllocationController extends ApplicationApiController
|
|||
*
|
||||
* @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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue