Added navbar and button to skip automatic search of book info online.

This commit is contained in:
krzysiej
2022-06-02 15:18:40 +02:00
parent e5562cddb1
commit b21d213b19
7 changed files with 82 additions and 35 deletions
+6 -16
View File
@@ -5,6 +5,7 @@ namespace App\Controller;
use App\Entity\Book;
use App\Entity\File;
use App\Repository\FileRepository;
use App\Service\FileService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
@@ -27,27 +28,16 @@ class FileController extends AbstractController
Request $request,
FileRepository $fileRepository,
File $file,
Filesystem $filesystem
FileService $fileService
): Response {
$filePath = $this->getParameter('book_files') . '/' . 'ebook_' . $file->getBook()->getId() . '_' .
md5($file->getFileName()) . '.' .
$file->getExtension();
$filesystem->remove($filePath);
if (!$filesystem->exists($filePath)) {
$fileRepository->remove($file, 'true');
}
$fileService->removeFiles($file);
$fileRepository->remove($file, 'true');
return $this->redirect($request->headers->get('referer'));
}
#[Route('/file/{id}', name: 'app_file_download', methods: ['GET'])]
public function get(File $file)
public function get(File $file, FileService $fileService)
{
return $this->file(
$this->getParameter('book_files') . '/' . 'ebook_' . $file->getBook()->getId() . '_' .
md5($file->getFileName()) . '.' .
$file->getExtension(),
$file->getFileName()
);
return $this->file($fileService->getFilePath($file), $file->getFileName());
}
}