|
5 | 5 | use Illuminate\Http\Request; |
6 | 6 | use Illuminate\Support\Facades\DB; |
7 | 7 | use JavaScript; |
| 8 | +use Pterodactyl\Contracts\Repository\AllocationRepositoryInterface; |
| 9 | +use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface; |
| 10 | +use Pterodactyl\Contracts\Repository\EggRepositoryInterface; |
| 11 | +use Pterodactyl\Contracts\Repository\NodeRepositoryInterface; |
| 12 | +use Pterodactyl\Contracts\Repository\ServerRepositoryInterface; |
| 13 | +use Pterodactyl\Contracts\Repository\UserRepositoryInterface; |
8 | 14 | use Pterodactyl\Http\Controllers\Controller; |
9 | | -use Pterodactyl\Models\Allocation; |
10 | | -use Pterodactyl\Models\Database; |
11 | | -use Pterodactyl\Models\Egg; |
12 | | -use Pterodactyl\Models\Node; |
13 | | -use Pterodactyl\Models\Server; |
14 | | -use Pterodactyl\Models\User; |
15 | 15 | use Pterodactyl\Services\DaemonKeys\DaemonKeyProviderService; |
| 16 | +use Pterodactyl\Traits\Controllers\JavascriptInjection; |
16 | 17 |
|
17 | 18 | class StatisticsController extends Controller |
18 | 19 | { |
| 20 | + use JavascriptInjection; |
| 21 | + |
| 22 | + private $allocationRepository; |
| 23 | + |
| 24 | + private $databaseRepository; |
19 | 25 |
|
20 | 26 | private $keyProviderService; |
21 | 27 |
|
22 | | - function __construct(DaemonKeyProviderService $keyProviderService) |
| 28 | + private $eggRepository; |
| 29 | + |
| 30 | + private $nodeRepository; |
| 31 | + |
| 32 | + private $serverRepository; |
| 33 | + |
| 34 | + private $userRepository; |
| 35 | + |
| 36 | + function __construct( |
| 37 | + AllocationRepositoryInterface $allocationRepository, |
| 38 | + DatabaseRepositoryInterface $databaseRepository, |
| 39 | + DaemonKeyProviderService $keyProviderService, |
| 40 | + EggRepositoryInterface $eggRepository, |
| 41 | + NodeRepositoryInterface $nodeRepository, |
| 42 | + ServerRepositoryInterface $serverRepository, |
| 43 | + UserRepositoryInterface $userRepository |
| 44 | + ) |
23 | 45 | { |
| 46 | + $this->allocationRepository = $allocationRepository; |
| 47 | + $this->databaseRepository = $databaseRepository; |
24 | 48 | $this->keyProviderService = $keyProviderService; |
| 49 | + $this->eggRepository = $eggRepository; |
| 50 | + $this->nodeRepository = $nodeRepository; |
| 51 | + $this->serverRepository = $serverRepository; |
| 52 | + $this->userRepository = $userRepository; |
25 | 53 | } |
26 | 54 |
|
27 | 55 | public function index(Request $request) |
28 | 56 | { |
29 | | - $servers = Server::all(); |
30 | | - $nodes = Node::all(); |
| 57 | + $servers = $this->serverRepository->all(); |
31 | 58 | $serversCount = count($servers); |
| 59 | + $nodes = $this->nodeRepository->all(); |
32 | 60 | $nodesCount = count($nodes); |
33 | | - $usersCount = User::count(); |
34 | | - $eggsCount = Egg::count(); |
35 | | - $databasesCount = Database::count(); |
| 61 | + $usersCount = $this->userRepository->count(); |
| 62 | + $eggsCount = $this->eggRepository->count(); |
| 63 | + $databasesCount = $this->databaseRepository->count(); |
36 | 64 | $totalServerRam = DB::table('servers')->sum('memory'); |
37 | 65 | $totalNodeRam = DB::table('nodes')->sum('memory'); |
38 | 66 | $totalServerDisk = DB::table('servers')->sum('disk'); |
39 | 67 | $totalNodeDisk = DB::table('nodes')->sum('disk'); |
40 | | - $totalAllocations = Allocation::count(); |
41 | | - |
42 | | - $suspendedServersCount = Server::where('suspended', true)->count(); |
| 68 | + $totalAllocations = $this->allocationRepository->count(); |
| 69 | + $suspendedServersCount = $this->serverRepository->getBuilder()->where('suspended', true)->count(); |
43 | 70 |
|
44 | 71 | $tokens = []; |
45 | 72 | foreach ($nodes as $node) { |
46 | | - $server = Server::where('node_id', $node->id)->first(); |
47 | | - if ($server == null) |
48 | | - continue; |
49 | | - |
50 | | - $tokens[$node->id] = $this->keyProviderService->handle($server, $request->user()); |
| 73 | + $tokens[$node->id] = $node->daemonSecret; |
51 | 74 | } |
52 | 75 |
|
53 | | - Javascript::put([ |
| 76 | + $this->injectJavascript([ |
54 | 77 | 'servers' => $servers, |
55 | 78 | 'serverCount' => $serversCount, |
56 | 79 | 'suspendedServers' => $suspendedServersCount, |
|
0 commit comments