Add http macro

This commit is contained in:
Lance Pioch 2022-10-21 16:34:26 -04:00
parent 5331fd2cdb
commit 264df1876b
2 changed files with 34 additions and 0 deletions

View file

@ -2,15 +2,20 @@
namespace Pterodactyl\Models;
use Illuminate\Support\Facades\Http;
use Psr\Http\Message\ResponseInterface;
use Illuminate\Notifications\Notifiable;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Database\Query\JoinClause;
use Znck\Eloquent\Traits\BelongsToThrough;
use GuzzleHttp\Exception\TransferException;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Pterodactyl\Exceptions\Http\Server\ServerStateConflictException;
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
/**
* \Pterodactyl\Models\Server.
@ -378,4 +383,20 @@ class Server extends Model
throw new ServerStateConflictException($this);
}
}
/**
* Sends a command or multiple commands to a running server instance.
*
* @throws DaemonConnectionException|GuzzleException
*/
public function send(array|string $command): ResponseInterface
{
try {
return Http::daemon($this->node)->post("/api/servers/{$this->uuid}/commands", [
'json' => ['commands' => is_array($command) ? $command : [$command]],
])->toPsrResponse();
} catch (TransferException $exception) {
throw new DaemonConnectionException($exception);
}
}
}