fix: add missing Admin controllers, fix __DIR__ paths (3 levels), defensive ServiceProvider
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Addons\AdvancedAdmin\Http\Controllers\Admin;
|
||||
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Pterodactyl\Models\Node;
|
||||
use Pterodactyl\Addons\AdvancedAdmin\Models\NetworkMetric;
|
||||
|
||||
class NodeNetworkController extends Controller
|
||||
{
|
||||
/** GET api/application/addons/network/nodes */
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
$nodes = Node::all()->map(function (Node $node) {
|
||||
$latest = NetworkMetric::where('node_id', $node->id)
|
||||
->orderByDesc('recorded_at')
|
||||
->first();
|
||||
|
||||
return [
|
||||
'id' => $node->id,
|
||||
'name' => $node->name,
|
||||
'fqdn' => $node->fqdn,
|
||||
'rx_bytes' => $latest?->rx_bytes ?? 0,
|
||||
'tx_bytes' => $latest?->tx_bytes ?? 0,
|
||||
'recorded_at'=> $latest?->recorded_at,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json(['data' => $nodes]);
|
||||
}
|
||||
|
||||
/** GET api/application/addons/network/nodes/{node} */
|
||||
public function show(Node $node): JsonResponse
|
||||
{
|
||||
$metrics = NetworkMetric::where('node_id', $node->id)
|
||||
->orderByDesc('recorded_at')
|
||||
->limit(60)
|
||||
->get(['recorded_at', 'rx_bytes', 'tx_bytes', 'server_id']);
|
||||
|
||||
return response()->json([
|
||||
'node' => ['id' => $node->id, 'name' => $node->name, 'fqdn' => $node->fqdn],
|
||||
'metrics' => $metrics,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user