Add endpoint to return startup variables; send back modified startup when a variable is edited

This commit is contained in:
Dane Everitt 2020-08-25 19:22:17 -07:00
parent d58fd72bf5
commit 179885b546
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
3 changed files with 54 additions and 1 deletions

View file

@ -5,12 +5,14 @@ namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
use Carbon\CarbonImmutable;
use Pterodactyl\Models\Server;
use Illuminate\Http\JsonResponse;
use Pterodactyl\Services\Servers\StartupCommandService;
use Pterodactyl\Services\Servers\VariableValidatorService;
use Pterodactyl\Repositories\Eloquent\ServerVariableRepository;
use Pterodactyl\Transformers\Api\Client\EggVariableTransformer;
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Pterodactyl\Http\Requests\Api\Client\Servers\Startup\GetStartupRequest;
use Pterodactyl\Http\Requests\Api\Client\Servers\Startup\UpdateStartupVariableRequest;
class StartupController extends ClientApiController
@ -25,18 +27,45 @@ class StartupController extends ClientApiController
*/
private $repository;
/**
* @var \Pterodactyl\Services\Servers\StartupCommandService
*/
private $startupCommandService;
/**
* StartupController constructor.
*
* @param \Pterodactyl\Services\Servers\VariableValidatorService $service
* @param \Pterodactyl\Services\Servers\StartupCommandService $startupCommandService
* @param \Pterodactyl\Repositories\Eloquent\ServerVariableRepository $repository
*/
public function __construct(VariableValidatorService $service, ServerVariableRepository $repository)
public function __construct(VariableValidatorService $service, StartupCommandService $startupCommandService, ServerVariableRepository $repository)
{
parent::__construct();
$this->service = $service;
$this->repository = $repository;
$this->startupCommandService = $startupCommandService;
}
/**
* Returns the startup information for the server including all of the variables.
*
* @param \Pterodactyl\Http\Requests\Api\Client\Servers\Startup\GetStartupRequest $request
* @param \Pterodactyl\Models\Server $server
* @return array
*/
public function index(GetStartupRequest $request, Server $server)
{
$startup = $this->startupCommandService->handle($server, false);
return $this->fractal->collection($server->variables)
->transformWith($this->getTransformer(EggVariableTransformer::class))
->addMeta([
'startup_command' => $startup,
'raw_startup_command' => $server->startup,
])
->toArray();
}
/**
@ -78,8 +107,14 @@ class StartupController extends ClientApiController
$variable = $variable->refresh();
$variable->server_value = $request->input('value');
$startup = $this->startupCommandService->handle($server, false);
return $this->fractal->item($variable)
->transformWith($this->getTransformer(EggVariableTransformer::class))
->addMeta([
'startup_command' => $startup,
'raw_startup_command' => $server->startup,
])
->toArray();
}
}

View file

@ -0,0 +1,17 @@
<?php
namespace Pterodactyl\Http\Requests\Api\Client\Servers\Startup;
use Pterodactyl\Models\Permission;
use Pterodactyl\Http\Requests\Api\Client\ClientApiRequest;
class GetStartupRequest extends ClientApiRequest
{
/**
* @return string
*/
public function permission()
{
return Permission::ACTION_STARTUP_READ;
}
}

View file

@ -103,6 +103,7 @@ Route::group(['prefix' => '/servers/{server}', 'middleware' => [AuthenticateServ
});
Route::group(['prefix' => '/startup'], function () {
Route::get('/', 'Servers\StartupController@index');
Route::put('/variable', 'Servers\StartupController@update');
});