Update the rest of the logic
This commit is contained in:
parent
2c72fdc716
commit
0b8b6a5272
3 changed files with 3 additions and 39 deletions
|
@ -8,7 +8,6 @@ use Pterodactyl\Facades\Activity;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use GuzzleHttp\Exception\BadResponseException;
|
use GuzzleHttp\Exception\BadResponseException;
|
||||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||||
use Pterodactyl\Repositories\Wings\DaemonCommandRepository;
|
|
||||||
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
|
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
|
||||||
use Pterodactyl\Http\Requests\Api\Client\Servers\SendCommandRequest;
|
use Pterodactyl\Http\Requests\Api\Client\Servers\SendCommandRequest;
|
||||||
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
|
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
|
||||||
|
@ -18,7 +17,7 @@ class CommandController extends ClientApiController
|
||||||
/**
|
/**
|
||||||
* CommandController constructor.
|
* CommandController constructor.
|
||||||
*/
|
*/
|
||||||
public function __construct(private DaemonCommandRepository $repository)
|
public function __construct()
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
@ -31,7 +30,7 @@ class CommandController extends ClientApiController
|
||||||
public function index(SendCommandRequest $request, Server $server): Response
|
public function index(SendCommandRequest $request, Server $server): Response
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$this->repository->setServer($server)->send($request->input('command'));
|
$server->send($request->input('command'));
|
||||||
} catch (DaemonConnectionException $exception) {
|
} catch (DaemonConnectionException $exception) {
|
||||||
$previous = $exception->getPrevious();
|
$previous = $exception->getPrevious();
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,6 @@ use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||||
use Pterodactyl\Services\Backups\InitiateBackupService;
|
use Pterodactyl\Services\Backups\InitiateBackupService;
|
||||||
use Pterodactyl\Repositories\Wings\DaemonPowerRepository;
|
use Pterodactyl\Repositories\Wings\DaemonPowerRepository;
|
||||||
use Pterodactyl\Repositories\Wings\DaemonCommandRepository;
|
|
||||||
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
|
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
|
||||||
|
|
||||||
class RunTaskJob extends Job implements ShouldQueue
|
class RunTaskJob extends Job implements ShouldQueue
|
||||||
|
@ -36,7 +35,6 @@ class RunTaskJob extends Job implements ShouldQueue
|
||||||
* @throws \Throwable
|
* @throws \Throwable
|
||||||
*/
|
*/
|
||||||
public function handle(
|
public function handle(
|
||||||
DaemonCommandRepository $commandRepository,
|
|
||||||
InitiateBackupService $backupService,
|
InitiateBackupService $backupService,
|
||||||
DaemonPowerRepository $powerRepository
|
DaemonPowerRepository $powerRepository
|
||||||
) {
|
) {
|
||||||
|
@ -66,7 +64,7 @@ class RunTaskJob extends Job implements ShouldQueue
|
||||||
$powerRepository->setServer($server)->send($this->task->payload);
|
$powerRepository->setServer($server)->send($this->task->payload);
|
||||||
break;
|
break;
|
||||||
case Task::ACTION_COMMAND:
|
case Task::ACTION_COMMAND:
|
||||||
$commandRepository->setServer($server)->send($this->task->payload);
|
$server->send($this->task->payload);
|
||||||
break;
|
break;
|
||||||
case Task::ACTION_BACKUP:
|
case Task::ACTION_BACKUP:
|
||||||
$backupService->setIgnoredFiles(explode(PHP_EOL, $this->task->payload))->handle($server, null, true);
|
$backupService->setIgnoredFiles(explode(PHP_EOL, $this->task->payload))->handle($server, null, true);
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue