Skip to content

Commit dbc7c59

Browse files
committed
Route and handle install state updates
1 parent bb9a371 commit dbc7c59

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

app/Http/Controllers/Api/Remote/Servers/ServerInstallController.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
namespace Pterodactyl\Http\Controllers\Api\Remote\Servers;
44

55
use Illuminate\Http\Request;
6+
use Illuminate\Http\Response;
67
use Illuminate\Http\JsonResponse;
78
use Pterodactyl\Http\Controllers\Controller;
89
use Pterodactyl\Repositories\Eloquent\ServerRepository;
10+
use Pterodactyl\Http\Requests\Api\Remote\InstallationDataRequest;
911

1012
class ServerInstallController extends Controller
1113
{
@@ -33,7 +35,7 @@ public function __construct(ServerRepository $repository)
3335
*
3436
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
3537
*/
36-
public function __invoke(Request $request, string $uuid)
38+
public function index(Request $request, string $uuid)
3739
{
3840
$server = $this->repository->getByUuid($uuid);
3941
$egg = $server->egg;
@@ -44,4 +46,25 @@ public function __invoke(Request $request, string $uuid)
4446
'script' => $egg->copy_script_install,
4547
]);
4648
}
49+
50+
/**
51+
* Updates the installation state of a server.
52+
*
53+
* @param \Pterodactyl\Http\Requests\Api\Remote\InstallationDataRequest $request
54+
* @param string $uuid
55+
* @return \Illuminate\Http\JsonResponse
56+
*
57+
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
58+
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
59+
*/
60+
public function store(InstallationDataRequest $request, string $uuid)
61+
{
62+
$server = $this->repository->getByUuid($uuid);
63+
64+
$this->repository->update($server->id, [
65+
'installed' => ((bool) $request->input('successful', false)) ? 1 : 2,
66+
]);
67+
68+
return JsonResponse::create([], Response::HTTP_NO_CONTENT);
69+
}
4770
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Pterodactyl\Http\Requests\Api\Remote;
4+
5+
use Illuminate\Foundation\Http\FormRequest;
6+
7+
class InstallationDataRequest extends FormRequest
8+
{
9+
/**
10+
* @return bool
11+
*/
12+
public function authorize()
13+
{
14+
return true;
15+
}
16+
17+
/**
18+
* @return array
19+
*/
20+
public function rules()
21+
{
22+
return [
23+
'successful' => 'present|boolean',
24+
];
25+
}
26+
}

routes/api-remote.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
Route::post('/sftp/auth', 'SftpAuthenticationController');
1010
Route::group(['prefix' => '/servers/{uuid}'], function () {
1111
Route::get('/', 'Servers\ServerDetailsController');
12-
Route::get('/install', 'Servers\ServerInstallController');
12+
Route::get('/install', 'Servers\ServerInstallController@index');
13+
Route::post('/install', 'Servers\ServerInstallController@store');
1314
});

0 commit comments

Comments
 (0)