From 54bcfd3775b0b0097667310ecd0fc0deffcfc86c Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Sat, 21 Dec 2024 14:57:16 +0100 Subject: [PATCH] build(composer): add ext-fileinfo to composer dependencies --- composer.json | 3 ++- src/Controller/ServeFileController.php | 1 - src/Objects/DirContent.php | 9 ++++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index b80b360..e26274b 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,8 @@ "symfony/yaml": "7.1.*", "symfonycasts/tailwind-bundle": "^0.6.1", "twig/extra-bundle": "^2.12|^3.0", - "twig/twig": "^2.12|^3.0" + "twig/twig": "^2.12|^3.0", + "ext-fileinfo": "*" }, "config": { "allow-plugins": { diff --git a/src/Controller/ServeFileController.php b/src/Controller/ServeFileController.php index a5e1fcb..22e535c 100644 --- a/src/Controller/ServeFileController.php +++ b/src/Controller/ServeFileController.php @@ -5,7 +5,6 @@ namespace App\Controller; use App\Service\FileSystemService; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\BinaryFileResponse; -use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\ResponseHeaderBag; use Symfony\Component\Routing\Attribute\Route; diff --git a/src/Objects/DirContent.php b/src/Objects/DirContent.php index 91d8d01..3079713 100644 --- a/src/Objects/DirContent.php +++ b/src/Objects/DirContent.php @@ -14,6 +14,7 @@ readonly class DirContent private string $type, private string $path, private string $content, + private string $mimeType, ) { } @@ -24,7 +25,8 @@ readonly class DirContent $fileInfo->getSize() ?? 0, $fileInfo->getType() ?? 'N/A', $fileInfo->getPath(), - $content + $content, + mime_content_type($fileInfo->getFilename()), ); } @@ -57,6 +59,11 @@ readonly class DirContent return $this->content; } + public function getMimeType(): string + { + return $this->mimeType; + } + private function getHumanReadableSize(): string { $bytes = $this->size;