Update support for moving/renaming files and folders

This commit is contained in:
Dane Everitt 2019-05-04 16:04:59 -07:00
parent eed4be49ab
commit 811026895b
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
9 changed files with 97 additions and 41 deletions

View file

@ -56,4 +56,13 @@ interface FileRepositoryInterface extends BaseRepositoryInterface
* @return \Psr\Http\Message\ResponseInterface
*/
public function createDirectory(string $name, string $path): ResponseInterface;
/**
* Renames or moves a file on the remote machine.
*
* @param string $from
* @param string $to
* @return \Psr\Http\Message\ResponseInterface
*/
public function renameFile(string $from, string $to): ResponseInterface;
}

View file

@ -11,6 +11,7 @@ use Illuminate\Contracts\Cache\Repository as CacheRepository;
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
use Pterodactyl\Contracts\Repository\Daemon\FileRepositoryInterface;
use Pterodactyl\Http\Requests\Api\Client\Servers\Files\ListFilesRequest;
use Pterodactyl\Http\Requests\Api\Client\Servers\Files\RenameFileRequest;
use Pterodactyl\Http\Requests\Api\Client\Servers\Files\CreateFolderRequest;
use Pterodactyl\Http\Requests\Api\Client\Servers\Files\DownloadFileRequest;
@ -67,7 +68,22 @@ class FileController extends ClientApiController
->setServer($request->getModel(Server::class))
->createDirectory($request->input('name'), $request->input('directory', '/'));
return Response::create('s');
return Response::create('', Response::HTTP_NO_CONTENT);
}
/**
* Renames a file on the remote machine.
*
* @param \Pterodactyl\Http\Requests\Api\Client\Servers\Files\RenameFileRequest $request
* @return \Illuminate\Http\Response
*/
public function renameFile(RenameFileRequest $request): Response
{
$this->fileRepository
->setServer($request->getModel(Server::class))
->renameFile($request->input('rename_from'), $request->input('rename_to'));
return Response::create('', Response::HTTP_NO_CONTENT);
}
/**

View file

@ -0,0 +1,31 @@
<?php
namespace Pterodactyl\Http\Requests\Api\Client\Servers\Files;
use Pterodactyl\Contracts\Http\ClientPermissionsRequest;
use Pterodactyl\Http\Requests\Api\Client\ClientApiRequest;
class RenameFileRequest extends ClientApiRequest implements ClientPermissionsRequest
{
/**
* The permission the user is required to have in order to perform this
* request action.
*
* @return string
*/
public function permission(): string
{
return 'move-files';
}
/**
* @return array
*/
public function rules(): array
{
return [
'rename_from' => 'string|required',
'rename_to' => 'string|required',
];
}
}

View file

@ -59,8 +59,8 @@ class FileRepository extends BaseWingsRepository implements FileRepositoryInterf
public function getDirectory(string $path): array
{
$response = $this->getHttpClient()->get(
// Reason for the path check is because it is unnecessary on the Daemon but we need
// to respect the interface.
// Reason for the path check is because it is unnecessary on the Daemon but we need
// to respect the interface.
sprintf('/api/servers/%s/files/list/%s', $this->getServer()->uuid, $path === '/' ? '' : $path)
);
@ -86,4 +86,24 @@ class FileRepository extends BaseWingsRepository implements FileRepositoryInterf
]
);
}
/**
* Renames or moves a file on the remote machine.
*
* @param string $from
* @param string $to
* @return \Psr\Http\Message\ResponseInterface
*/
public function renameFile(string $from, string $to): ResponseInterface
{
return $this->getHttpClient()->put(
sprintf('/api/servers/%s/files/rename', $this->getServer()->uuid),
[
'json' => [
'rename_from' => $from,
'rename_to' => $to,
],
]
);
}
}