Update client API endpoints to not use deprecated function
This commit is contained in:
parent
7543ef085d
commit
b99ea53ca1
8 changed files with 74 additions and 58 deletions
|
@ -3,23 +3,23 @@
|
|||
namespace Pterodactyl\Http\Controllers\Api\Client;
|
||||
|
||||
use Pterodactyl\Models\User;
|
||||
use Pterodactyl\Repositories\Eloquent\ServerRepository;
|
||||
use Pterodactyl\Transformers\Api\Client\ServerTransformer;
|
||||
use Pterodactyl\Http\Requests\Api\Client\GetServersRequest;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
|
||||
class ClientController extends ClientApiController
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
|
||||
* @var \Pterodactyl\Repositories\Eloquent\ServerRepository
|
||||
*/
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* ClientController constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
|
||||
* @param \Pterodactyl\Repositories\Eloquent\ServerRepository $repository
|
||||
*/
|
||||
public function __construct(ServerRepositoryInterface $repository)
|
||||
public function __construct(ServerRepository $repository)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
|
|
@ -8,11 +8,10 @@ use Illuminate\Http\Response;
|
|||
use Pterodactyl\Models\Server;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use GuzzleHttp\Exception\TransferException;
|
||||
use Pterodactyl\Repositories\Wings\DaemonFileRepository;
|
||||
use Pterodactyl\Transformers\Daemon\FileObjectTransformer;
|
||||
use Illuminate\Contracts\Cache\Repository as CacheRepository;
|
||||
use Illuminate\Contracts\Config\Repository as ConfigRepository;
|
||||
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
|
||||
use Pterodactyl\Contracts\Repository\Daemon\FileRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
|
||||
use Pterodactyl\Http\Requests\Api\Client\Servers\Files\CopyFileRequest;
|
||||
use Pterodactyl\Http\Requests\Api\Client\Servers\Files\ListFilesRequest;
|
||||
|
@ -31,28 +30,21 @@ class FileController extends ClientApiController
|
|||
private $cache;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Config\Repository
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\Daemon\FileRepositoryInterface
|
||||
* @var \Pterodactyl\Repositories\Wings\DaemonFileRepository
|
||||
*/
|
||||
private $fileRepository;
|
||||
|
||||
/**
|
||||
* FileController constructor.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Config\Repository $config
|
||||
* @param \Pterodactyl\Contracts\Repository\Daemon\FileRepositoryInterface $fileRepository
|
||||
* @param \Pterodactyl\Repositories\Wings\DaemonFileRepository $fileRepository
|
||||
* @param \Illuminate\Contracts\Cache\Repository $cache
|
||||
*/
|
||||
public function __construct(ConfigRepository $config, FileRepositoryInterface $fileRepository, CacheRepository $cache)
|
||||
public function __construct(DaemonFileRepository $fileRepository, CacheRepository $cache)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->cache = $cache;
|
||||
$this->config = $config;
|
||||
$this->fileRepository = $fileRepository;
|
||||
}
|
||||
|
||||
|
@ -60,15 +52,16 @@ class FileController extends ClientApiController
|
|||
* Returns a listing of files in a given directory.
|
||||
*
|
||||
* @param \Pterodactyl\Http\Requests\Api\Client\Servers\Files\ListFilesRequest $request
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @return array
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
||||
*/
|
||||
public function listDirectory(ListFilesRequest $request): array
|
||||
public function listDirectory(ListFilesRequest $request, Server $server): array
|
||||
{
|
||||
try {
|
||||
$contents = $this->fileRepository
|
||||
->setServer($request->getModel(Server::class))
|
||||
->setServer($server)
|
||||
->getDirectory($request->get('directory') ?? '/');
|
||||
} catch (TransferException $exception) {
|
||||
throw new DaemonConnectionException($exception, true);
|
||||
|
@ -83,13 +76,15 @@ class FileController extends ClientApiController
|
|||
* Return the contents of a specified file for the user.
|
||||
*
|
||||
* @param \Pterodactyl\Http\Requests\Api\Client\Servers\Files\GetFileContentsRequest $request
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @return \Illuminate\Http\Response
|
||||
* @throws \Pterodactyl\Exceptions\Http\Server\FileSizeTooLargeException
|
||||
*/
|
||||
public function getFileContents(GetFileContentsRequest $request): Response
|
||||
public function getFileContents(GetFileContentsRequest $request, Server $server): Response
|
||||
{
|
||||
return Response::create(
|
||||
$this->fileRepository->setServer($request->getModel(Server::class))->getContent(
|
||||
$request->get('file'), $this->config->get('pterodactyl.files.max_edit_size')
|
||||
$this->fileRepository->setServer($server)->getContent(
|
||||
$request->get('file'), config('pterodactyl.files.max_edit_size')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -98,11 +93,12 @@ class FileController extends ClientApiController
|
|||
* Writes the contents of the specified file to the server.
|
||||
*
|
||||
* @param \Pterodactyl\Http\Requests\Api\Client\Servers\Files\WriteFileContentRequest $request
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function writeFileContents(WriteFileContentRequest $request): Response
|
||||
public function writeFileContents(WriteFileContentRequest $request, Server $server): Response
|
||||
{
|
||||
$this->fileRepository->setServer($request->getModel(Server::class))->putContent(
|
||||
$this->fileRepository->setServer($server)->putContent(
|
||||
$request->get('file'),
|
||||
$request->getContent()
|
||||
);
|
||||
|
@ -114,12 +110,13 @@ class FileController extends ClientApiController
|
|||
* Creates a new folder on the server.
|
||||
*
|
||||
* @param \Pterodactyl\Http\Requests\Api\Client\Servers\Files\CreateFolderRequest $request
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function createFolder(CreateFolderRequest $request): Response
|
||||
public function createFolder(CreateFolderRequest $request, Server $server): Response
|
||||
{
|
||||
$this->fileRepository
|
||||
->setServer($request->getModel(Server::class))
|
||||
->setServer($server)
|
||||
->createDirectory($request->input('name'), $request->input('directory', '/'));
|
||||
|
||||
return Response::create('', Response::HTTP_NO_CONTENT);
|
||||
|
@ -129,12 +126,13 @@ class FileController extends ClientApiController
|
|||
* Renames a file on the remote machine.
|
||||
*
|
||||
* @param \Pterodactyl\Http\Requests\Api\Client\Servers\Files\RenameFileRequest $request
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function renameFile(RenameFileRequest $request): Response
|
||||
public function renameFile(RenameFileRequest $request, Server $server): Response
|
||||
{
|
||||
$this->fileRepository
|
||||
->setServer($request->getModel(Server::class))
|
||||
->setServer($server)
|
||||
->renameFile($request->input('rename_from'), $request->input('rename_to'));
|
||||
|
||||
return Response::create('', Response::HTTP_NO_CONTENT);
|
||||
|
@ -144,12 +142,13 @@ class FileController extends ClientApiController
|
|||
* Copies a file on the server.
|
||||
*
|
||||
* @param \Pterodactyl\Http\Requests\Api\Client\Servers\Files\CopyFileRequest $request
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function copyFile(CopyFileRequest $request): Response
|
||||
public function copyFile(CopyFileRequest $request, Server $server): Response
|
||||
{
|
||||
$this->fileRepository
|
||||
->setServer($request->getModel(Server::class))
|
||||
->setServer($server)
|
||||
->copyFile($request->input('location'));
|
||||
|
||||
return Response::create('', Response::HTTP_NO_CONTENT);
|
||||
|
@ -159,12 +158,13 @@ class FileController extends ClientApiController
|
|||
* Deletes a file or folder from the server.
|
||||
*
|
||||
* @param \Pterodactyl\Http\Requests\Api\Client\Servers\Files\DeleteFileRequest $request
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function delete(DeleteFileRequest $request): Response
|
||||
public function delete(DeleteFileRequest $request, Server $server): Response
|
||||
{
|
||||
$this->fileRepository
|
||||
->setServer($request->getModel(Server::class))
|
||||
->setServer($server)
|
||||
->deleteFile($request->input('location'));
|
||||
|
||||
return Response::create('', Response::HTTP_NO_CONTENT);
|
||||
|
@ -178,13 +178,12 @@ class FileController extends ClientApiController
|
|||
* Returns the token that needs to be used when downloading the file.
|
||||
*
|
||||
* @param \Pterodactyl\Http\Requests\Api\Client\Servers\Files\DownloadFileRequest $request
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function download(DownloadFileRequest $request): JsonResponse
|
||||
public function download(DownloadFileRequest $request, Server $server): JsonResponse
|
||||
{
|
||||
/** @var \Pterodactyl\Models\Server $server */
|
||||
$server = $request->getModel(Server::class);
|
||||
$token = Uuid::uuid4()->toString();
|
||||
|
||||
$this->cache->put(
|
||||
|
|
|
@ -3,24 +3,24 @@
|
|||
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
|
||||
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Repositories\Eloquent\AllocationRepository;
|
||||
use Pterodactyl\Transformers\Api\Client\AllocationTransformer;
|
||||
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
|
||||
use Pterodactyl\Contracts\Repository\AllocationRepositoryInterface;
|
||||
use Pterodactyl\Http\Requests\Api\Client\Servers\Network\GetNetworkRequest;
|
||||
|
||||
class NetworkController extends ClientApiController
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface
|
||||
* @var \Pterodactyl\Repositories\Eloquent\AllocationRepository
|
||||
*/
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* NetworkController constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface $repository
|
||||
* @param \Pterodactyl\Repositories\Eloquent\AllocationRepository $repository
|
||||
*/
|
||||
public function __construct(AllocationRepositoryInterface $repository)
|
||||
public function __construct(AllocationRepository $repository)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
@ -32,12 +32,11 @@ class NetworkController extends ClientApiController
|
|||
* not they are currently assigned as the primary for this server.
|
||||
*
|
||||
* @param \Pterodactyl\Http\Requests\Api\Client\Servers\Network\GetNetworkRequest $request
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @return array
|
||||
*/
|
||||
public function index(GetNetworkRequest $request): array
|
||||
public function index(GetNetworkRequest $request, Server $server): array
|
||||
{
|
||||
$server = $request->getModel(Server::class);
|
||||
|
||||
$allocations = $this->repository->findWhere([
|
||||
['server_id', '=', $server->id],
|
||||
]);
|
||||
|
|
|
@ -4,23 +4,23 @@ namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
|
|||
|
||||
use Illuminate\Http\Response;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Repositories\Wings\DaemonPowerRepository;
|
||||
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
|
||||
use Pterodactyl\Http\Requests\Api\Client\Servers\SendPowerRequest;
|
||||
use Pterodactyl\Contracts\Repository\Daemon\PowerRepositoryInterface;
|
||||
|
||||
class PowerController extends ClientApiController
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\Daemon\PowerRepositoryInterface
|
||||
* @var \Pterodactyl\Repositories\Wings\DaemonPowerRepository
|
||||
*/
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* PowerController constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Contracts\Repository\Daemon\PowerRepositoryInterface $repository
|
||||
* @param \Pterodactyl\Repositories\Wings\DaemonPowerRepository $repository
|
||||
*/
|
||||
public function __construct(PowerRepositoryInterface $repository)
|
||||
public function __construct(DaemonPowerRepository $repository)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
@ -31,16 +31,14 @@ class PowerController extends ClientApiController
|
|||
* Send a power action to a server.
|
||||
*
|
||||
* @param \Pterodactyl\Http\Requests\Api\Client\Servers\SendPowerRequest $request
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @return \Illuminate\Http\Response
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\Daemon\InvalidPowerSignalException
|
||||
*/
|
||||
public function index(SendPowerRequest $request): Response
|
||||
public function index(SendPowerRequest $request, Server $server): Response
|
||||
{
|
||||
$server = $request->getModel(Server::class);
|
||||
$token = $request->attributes->get('server_token');
|
||||
|
||||
$this->repository->setServer($server)->setToken($token)->sendSignal($request->input('signal'));
|
||||
$this->repository->setServer($server)->send(
|
||||
$request->input('signal')
|
||||
);
|
||||
|
||||
return $this->returnNoContent();
|
||||
}
|
||||
|
|
|
@ -31,15 +31,14 @@ class ResourceUtilizationController extends ClientApiController
|
|||
* Return the current resource utilization for a server.
|
||||
*
|
||||
* @param \Pterodactyl\Http\Requests\Api\Client\Servers\GetServerRequest $request
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @return array
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
||||
*/
|
||||
public function __invoke(GetServerRequest $request): array
|
||||
public function __invoke(GetServerRequest $request, Server $server): array
|
||||
{
|
||||
$stats = $this->repository
|
||||
->setServer($request->getModel(Server::class))
|
||||
->getDetails();
|
||||
$stats = $this->repository->setServer($server)->getDetails();
|
||||
|
||||
return $this->fractal->item($stats)
|
||||
->transformWith($this->getTransformer(StatsTransformer::class))
|
||||
|
|
|
@ -14,11 +14,12 @@ class ServerController extends ClientApiController
|
|||
* client using the API.
|
||||
*
|
||||
* @param \Pterodactyl\Http\Requests\Api\Client\Servers\GetServerRequest $request
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @return array
|
||||
*/
|
||||
public function index(GetServerRequest $request): array
|
||||
public function index(GetServerRequest $request, Server $server): array
|
||||
{
|
||||
return $this->fractal->item($request->getModel(Server::class))
|
||||
return $this->fractal->item($server)
|
||||
->transformWith($this->getTransformer(ServerTransformer::class))
|
||||
->toArray();
|
||||
}
|
||||
|
|
|
@ -89,6 +89,7 @@ abstract class ApplicationApiRequest extends FormRequest
|
|||
*
|
||||
* @param string $model
|
||||
* @return mixed
|
||||
* @deprecated
|
||||
*
|
||||
* @throws \Symfony\Component\Routing\Exception\InvalidParameterException
|
||||
*/
|
||||
|
|
|
@ -2,6 +2,25 @@
|
|||
|
||||
namespace Pterodactyl\Repositories\Wings;
|
||||
|
||||
use Webmozart\Assert\Assert;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
class DaemonPowerRepository extends DaemonRepository
|
||||
{
|
||||
/**
|
||||
* Sends a power action to the server instance.
|
||||
*
|
||||
* @param string $action
|
||||
* @return \Psr\Http\Message\ResponseInterface
|
||||
*/
|
||||
public function send(string $action): ResponseInterface
|
||||
{
|
||||
Assert::isInstanceOf($this->server, Server::class);
|
||||
|
||||
return $this->getHttpClient()->post(
|
||||
sprintf('/api/servers/%s/power', $this->server->id),
|
||||
['json' => ['action' => $action]]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue