Pass along new fields to Wings instance when endpoint is used; closes #4048
This commit is contained in:
parent
3fceb588fb
commit
c14c7b436e
3 changed files with 57 additions and 33 deletions
|
@ -97,7 +97,9 @@ class FileController extends ClientApiController
|
||||||
*/
|
*/
|
||||||
public function download(GetFileContentsRequest $request, Server $server)
|
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')];
|
$audit->metadata = ['file' => $request->get('file')];
|
||||||
|
|
||||||
return $this->jwtService
|
return $this->jwtService
|
||||||
|
@ -107,7 +109,8 @@ class FileController extends ClientApiController
|
||||||
'server_uuid' => $server->uuid,
|
'server_uuid' => $server->uuid,
|
||||||
])
|
])
|
||||||
->handle($server->node, $request->user()->id . $server->uuid);
|
->handle($server->node, $request->user()->id . $server->uuid);
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'object' => 'signed_url',
|
'object' => 'signed_url',
|
||||||
|
@ -201,7 +204,9 @@ class FileController extends ClientApiController
|
||||||
*/
|
*/
|
||||||
public function compress(CompressFilesRequest $request, Server $server): array
|
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.
|
// Allow up to five minutes for this request to process before timing out.
|
||||||
set_time_limit(300);
|
set_time_limit(300);
|
||||||
|
|
||||||
|
@ -212,7 +217,8 @@ class FileController extends ClientApiController
|
||||||
$request->input('root'),
|
$request->input('root'),
|
||||||
$request->input('files')
|
$request->input('files')
|
||||||
);
|
);
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
return $this->fractal->item($file)
|
return $this->fractal->item($file)
|
||||||
->transformWith($this->getTransformer(FileObjectTransformer::class))
|
->transformWith($this->getTransformer(FileObjectTransformer::class))
|
||||||
|
@ -224,7 +230,9 @@ class FileController extends ClientApiController
|
||||||
*/
|
*/
|
||||||
public function decompress(DecompressFilesRequest $request, Server $server): JsonResponse
|
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.
|
// Allow up to five minutes for this request to process before timing out.
|
||||||
set_time_limit(300);
|
set_time_limit(300);
|
||||||
|
|
||||||
|
@ -232,7 +240,8 @@ class FileController extends ClientApiController
|
||||||
|
|
||||||
$this->fileRepository->setServer($server)
|
$this->fileRepository->setServer($server)
|
||||||
->decompressFile($request->input('root'), $request->input('file'));
|
->decompressFile($request->input('root'), $request->input('file'));
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
|
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.
|
* Requests that a file be downloaded from a remote location by Wings.
|
||||||
*
|
*
|
||||||
* @param $request
|
|
||||||
*
|
|
||||||
* @throws \Throwable
|
* @throws \Throwable
|
||||||
*/
|
*/
|
||||||
public function pull(PullFileRequest $request, Server $server): JsonResponse
|
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) {
|
$server->audit(AuditLog::SERVER__FILESYSTEM_PULL, function (AuditLog $audit, Server $server) use ($request) {
|
||||||
$audit->metadata = ['directory' => $request->input('directory'), 'url' => $request->input('url')];
|
$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);
|
return new JsonResponse([], Response::HTTP_NO_CONTENT);
|
||||||
|
|
|
@ -20,7 +20,10 @@ class PullFileRequest extends ClientApiRequest implements ClientPermissionsReque
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'url' => 'required|string|url',
|
'url' => 'required|string|url',
|
||||||
'directory' => 'sometimes|nullable|string',
|
'directory' => 'nullable|string',
|
||||||
|
'filename' => 'nullable|string',
|
||||||
|
'use_header' => 'boolean',
|
||||||
|
'foreground' => 'boolean',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -267,15 +267,23 @@ class DaemonFileRepository extends DaemonRepository
|
||||||
*
|
*
|
||||||
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
* @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);
|
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 {
|
try {
|
||||||
return $this->getHttpClient()->post(
|
return $this->getHttpClient()->post(
|
||||||
sprintf('/api/servers/%s/files/pull', $this->server->uuid),
|
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) {
|
} catch (TransferException $exception) {
|
||||||
|
|
Loading…
Reference in a new issue