Feat: Streamline and extend logging

This commit is contained in:
Björn Fromme
2023-10-21 10:01:25 +02:00
parent 124307616c
commit 5ac8ea7491
52 changed files with 261 additions and 74 deletions
+19 -3
View File
@@ -4,7 +4,9 @@ namespace App\Controller\Common;
use App\Entity\Upload;
use App\Service\Upload\UploadHandler;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
@@ -13,11 +15,14 @@ use Symfony\Component\Security\Http\Attribute\IsGranted;
class DownloadController extends AbstractController
{
public function __construct(private readonly UploadHandler $uploadHandler)
{
public function __construct(
private readonly UploadHandler $uploadHandler,
private readonly LoggerInterface $logger
) {
}
#[Route('/download/{uuid}', name: 'app_common_download')]
#[IsGranted('ROLE_USER')]
#[IsGranted('DOWNLOAD', subject: 'upload')]
public function index(Upload $upload, Request $request): Response
{
@@ -26,6 +31,17 @@ class DownloadController extends AbstractController
$inline = (bool) $request->get('inline');
$disposition = $inline ? ResponseHeaderBag::DISPOSITION_INLINE : ResponseHeaderBag::DISPOSITION_ATTACHMENT;
return $this->file($path, $originalFilename, $disposition);
$this->logger->info('Download file', [
'file_id' => $upload->getId(),
'file_filename' => $upload->getOriginalFilename(),
]);
try {
$response = $this->file($path, $originalFilename, $disposition);
} catch (FileNotFoundException $e) {
throw $this->createNotFoundException('Die Datei wurde nicht gefunden');
}
return $response;
}
}