misc_pterodactyl-panel/app/Http/Controllers/Api/Client/Servers/SettingsController.php

76 lines
2.3 KiB
PHP
Raw Normal View History

<?php
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
use Illuminate\Http\Response;
use Pterodactyl\Models\Server;
use Pterodactyl\Repositories\Eloquent\ServerRepository;
use Pterodactyl\Services\Servers\ReinstallServerService;
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Pterodactyl\Http\Requests\Api\Client\Servers\Settings\RenameServerRequest;
use Pterodactyl\Http\Requests\Api\Client\Servers\Settings\SetDockerImageRequest;
use Pterodactyl\Http\Requests\Api\Client\Servers\Settings\ReinstallServerRequest;
class SettingsController extends ClientApiController
{
2021-03-05 17:03:12 +00:00
private ServerRepository $repository;
private ReinstallServerService $reinstallServerService;
/**
* SettingsController constructor.
*/
public function __construct(
ServerRepository $repository,
ReinstallServerService $reinstallServerService
) {
parent::__construct();
$this->repository = $repository;
$this->reinstallServerService = $reinstallServerService;
}
/**
* Renames a server.
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
2021-03-05 17:03:12 +00:00
public function rename(RenameServerRequest $request, Server $server): Response
{
$this->repository->update($server->id, [
'name' => $request->input('name'),
]);
2021-03-05 17:03:12 +00:00
return $this->returnNoContent();
}
/**
* Reinstalls the server on the daemon.
*
* @throws \Throwable
*/
2021-03-05 17:03:12 +00:00
public function reinstall(ReinstallServerRequest $request, Server $server): Response
{
2020-10-06 04:54:29 +00:00
$this->reinstallServerService->handle($server);
2021-03-05 17:03:12 +00:00
return $this->returnAccepted();
}
/**
* Changes the Docker image in use by the server.
*
* @throws \Throwable
*/
2021-03-05 17:03:12 +00:00
public function dockerImage(SetDockerImageRequest $request, Server $server): Response
{
2021-01-23 20:33:34 +00:00
if (!in_array($server->image, $server->egg->docker_images)) {
throw new BadRequestHttpException('This server\'s Docker image has been manually set by an administrator and cannot be updated.');
}
$server->forceFill(['image' => $request->input('docker_image')])->saveOrFail();
2021-03-05 17:03:12 +00:00
return $this->returnNoContent();
}
}