Route and handle install state updates

This commit is contained in:
Dane Everitt 2020-01-19 13:50:38 -08:00
parent bb9a3714cb
commit dbc7c597d0
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
3 changed files with 52 additions and 2 deletions

View file

@ -3,9 +3,11 @@
namespace Pterodactyl\Http\Controllers\Api\Remote\Servers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Http\JsonResponse;
use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Repositories\Eloquent\ServerRepository;
use Pterodactyl\Http\Requests\Api\Remote\InstallationDataRequest;
class ServerInstallController extends Controller
{
@ -33,7 +35,7 @@ class ServerInstallController extends Controller
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function __invoke(Request $request, string $uuid)
public function index(Request $request, string $uuid)
{
$server = $this->repository->getByUuid($uuid);
$egg = $server->egg;
@ -44,4 +46,25 @@ class ServerInstallController extends Controller
'script' => $egg->copy_script_install,
]);
}
/**
* Updates the installation state of a server.
*
* @param \Pterodactyl\Http\Requests\Api\Remote\InstallationDataRequest $request
* @param string $uuid
* @return \Illuminate\Http\JsonResponse
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
*/
public function store(InstallationDataRequest $request, string $uuid)
{
$server = $this->repository->getByUuid($uuid);
$this->repository->update($server->id, [
'installed' => ((bool) $request->input('successful', false)) ? 1 : 2,
]);
return JsonResponse::create([], Response::HTTP_NO_CONTENT);
}
}

View file

@ -0,0 +1,26 @@
<?php
namespace Pterodactyl\Http\Requests\Api\Remote;
use Illuminate\Foundation\Http\FormRequest;
class InstallationDataRequest extends FormRequest
{
/**
* @return bool
*/
public function authorize()
{
return true;
}
/**
* @return array
*/
public function rules()
{
return [
'successful' => 'present|boolean',
];
}
}

View file

@ -9,5 +9,6 @@ Route::post('/download-file', 'FileDownloadController@index');
Route::post('/sftp/auth', 'SftpAuthenticationController');
Route::group(['prefix' => '/servers/{uuid}'], function () {
Route::get('/', 'Servers\ServerDetailsController');
Route::get('/install', 'Servers\ServerInstallController');
Route::get('/install', 'Servers\ServerInstallController@index');
Route::post('/install', 'Servers\ServerInstallController@store');
});