Configuration for API pagination and includes on listing

This commit is contained in:
Dane Everitt 2017-04-09 16:04:08 -04:00
parent 69dfd380ad
commit de8bbcd098
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
4 changed files with 45 additions and 17 deletions

View file

@ -32,6 +32,7 @@ use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Repositories\NodeRepository;
use Pterodactyl\Transformers\Admin\NodeTransformer;
use Pterodactyl\Exceptions\DisplayValidationException;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
class NodeController extends Controller
{
@ -45,14 +46,17 @@ class NodeController extends Controller
{
$this->authorize('node-list', $request->apiKey());
$fractal = Fractal::create()->collection(Node::all());
if ($request->input('include')) {
$nodes = Node::paginate(config('pterodactyl.paginate.api.nodes'));
$fractal = Fractal::create()->collection($nodes)
->transformWith(new NodeTransformer($request))
->withResourceName('user')
->paginateWith(new IlluminatePaginatorAdapter($nodes));
if (config('pterodactyl.api.allow_includes_on_list') && $request->input('include')) {
$fractal->parseIncludes(explode(',', $request->input('include')));
}
return $fractal->transformWith(new NodeTransformer($request))
->withResourceName('node')
->toArray();
return $fractal->toArray();
}
/**

View file

@ -47,14 +47,17 @@ class ServerController extends Controller
{
$this->authorize('server-list', $request->apiKey());
$servers = Server::paginate(20);
return Fractal::create()
->collection($servers)
$servers = Server::paginate(config('pterodactyl.paginate.api.servers'));
$fractal = Fractal::create()->collection($servers)
->transformWith(new ServerTransformer($request))
->paginateWith(new IlluminatePaginatorAdapter($servers))
->withResourceName('server')
->toArray();
->withResourceName('user')
->paginateWith(new IlluminatePaginatorAdapter($servers));
if (config('pterodactyl.api.allow_includes_on_list') && $request->input('include')) {
$fractal->parseIncludes(explode(',', $request->input('include')));
}
return $fractal->toArray();
}
/**

View file

@ -45,13 +45,18 @@ class UserController extends Controller
public function index(Request $request)
{
$this->authorize('user-list', $request->apiKey());
$users = User::paginate(50);
return Fractal::create()->collection($users)
$users = User::paginate(config('pterodactyl.paginate.api.users'));
$fractal = Fractal::create()->collection($users)
->transformWith(new UserTransformer($request))
->withResourceName('user')
->paginateWith(new IlluminatePaginatorAdapter($users))
->toArray();
->paginateWith(new IlluminatePaginatorAdapter($users));
if (config('pterodactyl.api.allow_includes_on_list') && $request->input('include')) {
$fractal->parseIncludes(explode(',', $request->input('include')));
}
return $fractal->toArray();
}
/**

View file

@ -26,8 +26,24 @@ return [
*/
'paginate' => [
'frontend' => [
'servers' => 15,
'servers' => env('APP_PAGINATE_FRONT_SERVERS', 15),
],
'api' => [
'nodes' => env('APP_PAGINATE_API_NODES', 25),
'servers' => env('APP_PAGINATE_API_SERVERS', 25),
'users' => env('APP_PAGINATE_API_USERS', 25),
]
],
/*
|--------------------------------------------------------------------------
| API Options
|--------------------------------------------------------------------------
|
| Configuration options for the API.
*/
'api' => [
'allow_includes_on_list' => env('API_ALLOW_INCLUDE_ON_LIST', false),
],
/*