feat(dump): add download functionality for dumps and improve UI interactions
This commit is contained in:
@@ -9,8 +9,11 @@ use AeonDumpManager\Service\DumpService;
|
||||
use AeonDumpManager\Service\Exception\DumpNotFoundException;
|
||||
use Shopware\Core\Framework\Routing\ApiRouteScope;
|
||||
use Shopware\Core\PlatformRequest;
|
||||
use Symfony\Component\HttpFoundation\HeaderUtils;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\Messenger\MessageBusInterface;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
@@ -77,6 +80,32 @@ class DumpController
|
||||
return new JsonResponse(null, Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
|
||||
#[Route(
|
||||
path: '/api/_action/aeon-dump-manager/dumps/{filename}/download',
|
||||
name: 'api.action.aeon_dump_manager.dumps.download',
|
||||
defaults: [PlatformRequest::ATTRIBUTE_ACL => ['aeon_dump_manager.viewer']],
|
||||
methods: ['GET']
|
||||
)]
|
||||
public function download(string $filename): StreamedResponse
|
||||
{
|
||||
try {
|
||||
$stream = $this->dumpService->readStream($filename);
|
||||
} catch (DumpNotFoundException $exception) {
|
||||
throw new NotFoundHttpException($exception->getMessage());
|
||||
}
|
||||
|
||||
$response = new StreamedResponse(static function () use ($stream): void {
|
||||
fpassthru($stream);
|
||||
});
|
||||
$response->headers->set('Content-Type', 'application/gzip');
|
||||
$response->headers->set(
|
||||
'Content-Disposition',
|
||||
HeaderUtils::makeDisposition(HeaderUtils::DISPOSITION_ATTACHMENT, $filename)
|
||||
);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
#[Route(
|
||||
path: '/api/_action/aeon-dump-manager/dumps/jobs/{jobId}',
|
||||
name: 'api.action.aeon_dump_manager.dumps.jobs.status',
|
||||
|
||||
Reference in New Issue
Block a user