Pass along new fields to Wings instance when endpoint is used; closes #4048

This commit is contained in:
DaneEveritt 2022-05-28 13:45:23 -04:00
parent 3fceb588fb
commit c14c7b436e
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
3 changed files with 57 additions and 33 deletions

View file

@ -97,7 +97,9 @@ class FileController extends ClientApiController
*/
public function download(GetFileContentsRequest $request, Server $server)
{
$token = $server->audit(AuditLog::SERVER__FILESYSTEM_DOWNLOAD, function (AuditLog $audit, Server $server) use ($request) {
$token = $server->audit(
AuditLog::SERVER__FILESYSTEM_DOWNLOAD,
function (AuditLog $audit, Server $server) use ($request) {
$audit->metadata = ['file' => $request->get('file')];
return $this->jwtService
@ -107,7 +109,8 @@ class FileController extends ClientApiController
'server_uuid' => $server->uuid,
])
->handle($server->node, $request->user()->id . $server->uuid);
});
}
);
return [
'object' => 'signed_url',
@ -201,7 +204,9 @@ class FileController extends ClientApiController
*/
public function compress(CompressFilesRequest $request, Server $server): array
{
$file = $server->audit(AuditLog::SERVER__FILESYSTEM_COMPRESS, function (AuditLog $audit, Server $server) use ($request) {
$file = $server->audit(
AuditLog::SERVER__FILESYSTEM_COMPRESS,
function (AuditLog $audit, Server $server) use ($request) {
// Allow up to five minutes for this request to process before timing out.
set_time_limit(300);
@ -212,7 +217,8 @@ class FileController extends ClientApiController
$request->input('root'),
$request->input('files')
);
});
}
);
return $this->fractal->item($file)
->transformWith($this->getTransformer(FileObjectTransformer::class))
@ -224,7 +230,9 @@ class FileController extends ClientApiController
*/
public function decompress(DecompressFilesRequest $request, Server $server): JsonResponse
{
$file = $server->audit(AuditLog::SERVER__FILESYSTEM_DECOMPRESS, function (AuditLog $audit, Server $server) use ($request) {
$file = $server->audit(
AuditLog::SERVER__FILESYSTEM_DECOMPRESS,
function (AuditLog $audit, Server $server) use ($request) {
// Allow up to five minutes for this request to process before timing out.
set_time_limit(300);
@ -232,7 +240,8 @@ class FileController extends ClientApiController
$this->fileRepository->setServer($server)
->decompressFile($request->input('root'), $request->input('file'));
});
}
);
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
}
@ -276,8 +285,6 @@ class FileController extends ClientApiController
/**
* Requests that a file be downloaded from a remote location by Wings.
*
* @param $request
*
* @throws \Throwable
*/
public function pull(PullFileRequest $request, Server $server): JsonResponse
@ -285,7 +292,13 @@ class FileController extends ClientApiController
$server->audit(AuditLog::SERVER__FILESYSTEM_PULL, function (AuditLog $audit, Server $server) use ($request) {
$audit->metadata = ['directory' => $request->input('directory'), 'url' => $request->input('url')];
$this->fileRepository->setServer($server)->pull($request->input('url'), $request->input('directory'));
$this->fileRepository
->setServer($server)
->pull(
$request->input('url'),
$request->input('directory'),
$request->safe(['filename', 'use_header', 'foreground'])
);
});
return new JsonResponse([], Response::HTTP_NO_CONTENT);

View file

@ -20,7 +20,10 @@ class PullFileRequest extends ClientApiRequest implements ClientPermissionsReque
{
return [
'url' => 'required|string|url',
'directory' => 'sometimes|nullable|string',
'directory' => 'nullable|string',
'filename' => 'nullable|string',
'use_header' => 'boolean',
'foreground' => 'boolean',
];
}
}

View file

@ -267,15 +267,23 @@ class DaemonFileRepository extends DaemonRepository
*
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
*/
public function pull(string $url, ?string $directory): ResponseInterface
public function pull(string $url, ?string $directory, array $params = []): ResponseInterface
{
Assert::isInstanceOf($this->server, Server::class);
$attributes = [
'url' => $url,
'root' => $directory ?? '/',
'file_name' => $params['filename'] ?? null,
'use_header' => $params['use_header'] ?? null,
'foreground' => $params['foreground'] ?? null,
];
try {
return $this->getHttpClient()->post(
sprintf('/api/servers/%s/files/pull', $this->server->uuid),
[
'json' => ['url' => $url, 'directory' => $directory ?? '/'],
'json' => array_filter($attributes, fn ($value) => !is_null($value)),
]
);
} catch (TransferException $exception) {