Update the rest of the logic

This commit is contained in:
Lance Pioch 2022-10-22 03:05:45 -04:00
parent 2c72fdc716
commit 0b8b6a5272
3 changed files with 3 additions and 39 deletions

View file

@ -8,7 +8,6 @@ use Pterodactyl\Facades\Activity;
use Psr\Http\Message\ResponseInterface;
use GuzzleHttp\Exception\BadResponseException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Pterodactyl\Repositories\Wings\DaemonCommandRepository;
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
use Pterodactyl\Http\Requests\Api\Client\Servers\SendCommandRequest;
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
@ -18,7 +17,7 @@ class CommandController extends ClientApiController
/**
* CommandController constructor.
*/
public function __construct(private DaemonCommandRepository $repository)
public function __construct()
{
parent::__construct();
}
@ -31,7 +30,7 @@ class CommandController extends ClientApiController
public function index(SendCommandRequest $request, Server $server): Response
{
try {
$this->repository->setServer($server)->send($request->input('command'));
$server->send($request->input('command'));
} catch (DaemonConnectionException $exception) {
$previous = $exception->getPrevious();

View file

@ -13,7 +13,6 @@ use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Pterodactyl\Services\Backups\InitiateBackupService;
use Pterodactyl\Repositories\Wings\DaemonPowerRepository;
use Pterodactyl\Repositories\Wings\DaemonCommandRepository;
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
class RunTaskJob extends Job implements ShouldQueue
@ -36,7 +35,6 @@ class RunTaskJob extends Job implements ShouldQueue
* @throws \Throwable
*/
public function handle(
DaemonCommandRepository $commandRepository,
InitiateBackupService $backupService,
DaemonPowerRepository $powerRepository
) {
@ -66,7 +64,7 @@ class RunTaskJob extends Job implements ShouldQueue
$powerRepository->setServer($server)->send($this->task->payload);
break;
case Task::ACTION_COMMAND:
$commandRepository->setServer($server)->send($this->task->payload);
$server->send($this->task->payload);
break;
case Task::ACTION_BACKUP:
$backupService->setIgnoredFiles(explode(PHP_EOL, $this->task->payload))->handle($server, null, true);

View file

@ -1,33 +0,0 @@
<?php
namespace Pterodactyl\Repositories\Wings;
use Webmozart\Assert\Assert;
use Pterodactyl\Models\Server;
use Psr\Http\Message\ResponseInterface;
use GuzzleHttp\Exception\TransferException;
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
class DaemonCommandRepository extends DaemonRepository
{
/**
* Sends a command or multiple commands to a running server instance.
*
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
*/
public function send(array|string $command): ResponseInterface
{
Assert::isInstanceOf($this->server, Server::class);
try {
return $this->getHttpClient()->post(
sprintf('/api/servers/%s/commands', $this->server->uuid),
[
'json' => ['commands' => is_array($command) ? $command : [$command]],
]
);
} catch (TransferException $exception) {
throw new DaemonConnectionException($exception);
}
}
}