Merge pull request #1903 from matthewpi/enhancement/wings-improved-server-loading

[Wings] Improved Server Loading
This commit is contained in:
Dane Everitt 2020-04-10 17:37:04 -07:00 committed by GitHub
commit 25f18dccdc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 70 additions and 2 deletions

View file

@ -171,4 +171,16 @@ interface ServerRepositoryInterface extends RepositoryInterface, SearchableInter
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
*/ */
public function loadAllServersForNode(int $node, int $limit): LengthAwarePaginator; public function loadAllServersForNode(int $node, int $limit): LengthAwarePaginator;
/**
* Returns every server that exists for a given node.
*
* This is different from {@see loadAllServersForNode} because
* it does not paginate the response.
*
* @param int $node
*
* @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection
*/
public function loadEveryServerForNode(int $node);
} }

View file

@ -5,6 +5,7 @@ namespace Pterodactyl\Http\Controllers\Api\Remote\Servers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Repositories\Eloquent\NodeRepository;
use Pterodactyl\Services\Eggs\EggConfigurationService; use Pterodactyl\Services\Eggs\EggConfigurationService;
use Pterodactyl\Repositories\Eloquent\ServerRepository; use Pterodactyl\Repositories\Eloquent\ServerRepository;
use Pterodactyl\Services\Servers\ServerConfigurationStructureService; use Pterodactyl\Services\Servers\ServerConfigurationStructureService;
@ -26,21 +27,29 @@ class ServerDetailsController extends Controller
*/ */
private $configurationStructureService; private $configurationStructureService;
/**
* @var \Pterodactyl\Repositories\Eloquent\NodeRepository
*/
private $nodeRepository;
/** /**
* ServerConfigurationController constructor. * ServerConfigurationController constructor.
* *
* @param \Pterodactyl\Repositories\Eloquent\ServerRepository $repository * @param \Pterodactyl\Repositories\Eloquent\ServerRepository $repository
* @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $configurationStructureService * @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $configurationStructureService
* @param \Pterodactyl\Services\Eggs\EggConfigurationService $eggConfigurationService * @param \Pterodactyl\Services\Eggs\EggConfigurationService $eggConfigurationService
* @param \Pterodactyl\Repositories\Eloquent\NodeRepository $nodeRepository
*/ */
public function __construct( public function __construct(
ServerRepository $repository, ServerRepository $repository,
ServerConfigurationStructureService $configurationStructureService, ServerConfigurationStructureService $configurationStructureService,
EggConfigurationService $eggConfigurationService EggConfigurationService $eggConfigurationService,
NodeRepository $nodeRepository
) { ) {
$this->eggConfigurationService = $eggConfigurationService; $this->eggConfigurationService = $eggConfigurationService;
$this->repository = $repository; $this->repository = $repository;
$this->configurationStructureService = $configurationStructureService; $this->configurationStructureService = $configurationStructureService;
$this->nodeRepository = $nodeRepository;
} }
/** /**
@ -62,4 +71,30 @@ class ServerDetailsController extends Controller
'process_configuration' => $this->eggConfigurationService->handle($server), 'process_configuration' => $this->eggConfigurationService->handle($server),
]); ]);
} }
/**
* Lists all servers with their configurations that are assigned to the requesting node.
*
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\Http\JsonResponse
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function list(Request $request)
{
$node = $request->attributes->get('node');
$servers = $this->repository->loadEveryServerForNode($node->id);
$configurations = [];
foreach ($servers as $server) {
$configurations[$server->uuid] = [
'settings' => $this->configurationStructureService->handle($server),
'process_configuration' => $this->eggConfigurationService->handle($server),
];
}
return JsonResponse::create($configurations);
}
} }

View file

@ -69,7 +69,7 @@ class DaemonAuthenticate
// Ensure that all of the correct parts are provided in the header. // Ensure that all of the correct parts are provided in the header.
if (count($parts) !== 2 || empty($parts[0]) || empty($parts[1])) { if (count($parts) !== 2 || empty($parts[0]) || empty($parts[1])) {
throw new BadRequestHttpException( throw new BadRequestHttpException(
'The Authorization headed provided was not in a valid format.', 'The Authorization headed provided was not in a valid format.'
); );
} }

View file

@ -378,4 +378,22 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt
->where('node_id', '=', $node) ->where('node_id', '=', $node)
->paginate($limit); ->paginate($limit);
} }
/**
* Returns every server that exists for a given node.
*
* This is different from {@see loadAllServersForNode} because
* it does not paginate the response.
*
* @param int $node
*
* @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection
*/
public function loadEveryServerForNode(int $node)
{
return $this->getBuilder()
->with('nest')
->where('node_id', '=', $node)
->get();
}
} }

View file

@ -7,6 +7,9 @@ Route::post('/download-file', 'FileDownloadController@index');
// Routes for the Wings daemon. // Routes for the Wings daemon.
Route::post('/sftp/auth', 'SftpAuthenticationController'); Route::post('/sftp/auth', 'SftpAuthenticationController');
Route::get('/servers', 'Servers\ServerDetailsController@list');
Route::group(['prefix' => '/servers/{uuid}'], function () { Route::group(['prefix' => '/servers/{uuid}'], function () {
Route::get('/', 'Servers\ServerDetailsController'); Route::get('/', 'Servers\ServerDetailsController');
Route::get('/install', 'Servers\ServerInstallController@index'); Route::get('/install', 'Servers\ServerInstallController@index');