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,17 +97,20 @@ 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) {
|
||||
$audit->metadata = ['file' => $request->get('file')];
|
||||
$token = $server->audit(
|
||||
AuditLog::SERVER__FILESYSTEM_DOWNLOAD,
|
||||
function (AuditLog $audit, Server $server) use ($request) {
|
||||
$audit->metadata = ['file' => $request->get('file')];
|
||||
|
||||
return $this->jwtService
|
||||
->setExpiresAt(CarbonImmutable::now()->addMinutes(15))
|
||||
->setClaims([
|
||||
'file_path' => rawurldecode($request->get('file')),
|
||||
'server_uuid' => $server->uuid,
|
||||
])
|
||||
->handle($server->node, $request->user()->id . $server->uuid);
|
||||
});
|
||||
return $this->jwtService
|
||||
->setExpiresAt(CarbonImmutable::now()->addMinutes(15))
|
||||
->setClaims([
|
||||
'file_path' => rawurldecode($request->get('file')),
|
||||
'server_uuid' => $server->uuid,
|
||||
])
|
||||
->handle($server->node, $request->user()->id . $server->uuid);
|
||||
}
|
||||
);
|
||||
|
||||
return [
|
||||
'object' => 'signed_url',
|
||||
|
@ -201,18 +204,21 @@ 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) {
|
||||
// Allow up to five minutes for this request to process before timing out.
|
||||
set_time_limit(300);
|
||||
$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);
|
||||
|
||||
$audit->metadata = ['root' => $request->input('root'), 'files' => $request->input('files')];
|
||||
$audit->metadata = ['root' => $request->input('root'), 'files' => $request->input('files')];
|
||||
|
||||
return $this->fileRepository->setServer($server)
|
||||
->compressFiles(
|
||||
$request->input('root'),
|
||||
$request->input('files')
|
||||
);
|
||||
});
|
||||
return $this->fileRepository->setServer($server)
|
||||
->compressFiles(
|
||||
$request->input('root'),
|
||||
$request->input('files')
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
return $this->fractal->item($file)
|
||||
->transformWith($this->getTransformer(FileObjectTransformer::class))
|
||||
|
@ -224,15 +230,18 @@ 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) {
|
||||
// Allow up to five minutes for this request to process before timing out.
|
||||
set_time_limit(300);
|
||||
$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);
|
||||
|
||||
$audit->metadata = ['root' => $request->input('root'), 'files' => $request->input('file')];
|
||||
$audit->metadata = ['root' => $request->input('root'), 'files' => $request->input('file')];
|
||||
|
||||
$this->fileRepository->setServer($server)
|
||||
->decompressFile($request->input('root'), $request->input('file'));
|
||||
});
|
||||
$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);
|
||||
|
|
|
@ -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',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue