misc_pterodactyl-panel/app/Http/Controllers/Api/Remote/Servers/ServerInstallController.php
2021-03-05 10:03:12 -07:00

61 lines
1.8 KiB
PHP

<?php
namespace Pterodactyl\Http\Controllers\Api\Remote\Servers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Pterodactyl\Models\Server;
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
{
private ServerRepository $repository;
/**
* ServerInstallController constructor.
*/
public function __construct(ServerRepository $repository)
{
$this->repository = $repository;
}
/**
* Returns installation information for a server.
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function index(Request $request, string $uuid): JsonResponse
{
$server = $this->repository->getByUuid($uuid);
$egg = $server->egg;
return new JsonResponse([
'container_image' => $egg->copy_script_container,
'entrypoint' => $egg->copy_script_entry,
'script' => $egg->copy_script_install,
]);
}
/**
* Updates the installation state of a server.
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
*/
public function store(InstallationDataRequest $request, string $uuid): Response
{
$server = $this->repository->getByUuid($uuid);
$status = $request->boolean('successful') ? null : Server::STATUS_INSTALL_FAILED;
if ($server->status === Server::STATUS_SUSPENDED) {
$status = Server::STATUS_SUSPENDED;
}
$this->repository->update($server->id, ['status' => $status], true, true);
return new Response('', Response::HTTP_NO_CONTENT);
}
}