Skip to content

Commit 9777330

Browse files
committed
Better middleware for routes, cleaned up API, removed old API calls
New API routes for Server allow specifying which fractal objects to load into the request, thus making it possible to fine-tune what data is returned.
1 parent ddb82ac commit 9777330

File tree

15 files changed

+304
-747
lines changed

15 files changed

+304
-747
lines changed

app/Exceptions/Handler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function report(Exception $exception)
4646
*/
4747
public function render($request, Exception $exception)
4848
{
49-
if ($request->expectsJson() || $request->isJson() || $request->is('api/*', 'remote/*', 'daemon/*')) {
49+
if ($request->expectsJson() || $request->isJson() || $request->is(...config('pterodactyl.json_routes'))) {
5050

5151
if (config('app.debug')) {
5252
$report = [
@@ -56,7 +56,7 @@ public function render($request, Exception $exception)
5656
}
5757

5858
$response = response()->json([
59-
'error' => $exception->getMessage(),
59+
'error' => (config('app.debug')) ? $exception->getMessage() : 'An unhandled exception was encountered with this request.',
6060
'exception' => ! isset($report) ?: $report,
6161
], ($this->isHttpException($exception)) ? $exception->getStatusCode() : 500, [], JSON_UNESCAPED_SLASHES);
6262

app/Http/Controllers/API_old/User/InfoController.php renamed to app/Http/Controllers/API/User/ServerController.php

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,35 @@
2424

2525
namespace Pterodactyl\Http\Controllers\API\User;
2626

27+
use Fractal;
2728
use Illuminate\Http\Request;
28-
use Pterodactyl\Http\Controllers\API\BaseController;
29+
use Pterodactyl\Models\Server;
30+
use Pterodactyl\Http\Controllers\Controller;
31+
use Pterodactyl\Transformers\User\ServerTransformer;
2932

30-
class InfoController extends BaseController
33+
class ServerController extends Controller
3134
{
32-
public function me(Request $request)
35+
public function index(Request $request, $uuid)
3336
{
34-
return $request->user()->access('service', 'node', 'allocation', 'option')->get()->map(function ($server) {
35-
return [
36-
'id' => $server->uuidShort,
37-
'uuid' => $server->uuid,
38-
'name' => $server->name,
39-
'node' => $server->node->name,
40-
'ip' => $server->allocation->alias,
41-
'port' => $server->allocation->port,
42-
'service' => $server->service->name,
43-
'option' => $server->option->name,
44-
];
45-
})->all();
37+
$server = Server::byUuid($uuid);
38+
$fractal = Fractal::create()->item($server);
39+
40+
if ($request->input('with')) {
41+
$fractal->parseIncludes(collect(explode(',', $request->input('with')))->intersect([
42+
'allocations', 'subusers', 'stats',
43+
])->toArray());
44+
}
45+
46+
return $fractal->transformWith(new ServerTransformer)->toArray();
47+
}
48+
49+
public function power(Request $request, $uuid)
50+
{
51+
52+
}
53+
54+
public function command(Request $request, $uuid)
55+
{
56+
4657
}
4758
}

app/Http/Controllers/API_old/NodeController.php

Lines changed: 0 additions & 172 deletions
This file was deleted.

0 commit comments

Comments
 (0)