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

View file

@ -47,14 +47,17 @@ class ServerController extends Controller
{ {
$this->authorize('server-list', $request->apiKey()); $this->authorize('server-list', $request->apiKey());
$servers = Server::paginate(20); $servers = Server::paginate(config('pterodactyl.paginate.api.servers'));
$fractal = Fractal::create()->collection($servers)
return Fractal::create()
->collection($servers)
->transformWith(new ServerTransformer($request)) ->transformWith(new ServerTransformer($request))
->paginateWith(new IlluminatePaginatorAdapter($servers)) ->withResourceName('user')
->withResourceName('server') ->paginateWith(new IlluminatePaginatorAdapter($servers));
->toArray();
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) public function index(Request $request)
{ {
$this->authorize('user-list', $request->apiKey()); $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)) ->transformWith(new UserTransformer($request))
->withResourceName('user') ->withResourceName('user')
->paginateWith(new IlluminatePaginatorAdapter($users)) ->paginateWith(new IlluminatePaginatorAdapter($users));
->toArray();
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' => [ 'paginate' => [
'frontend' => [ '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),
], ],
/* /*