- hamburger menu
- download cbz
This commit is contained in:
Jérémy Guillot
2024-06-27 11:49:32 +02:00
parent 115e4336ab
commit b04055ec22
2 changed files with 46 additions and 6 deletions

View File

@@ -0,0 +1,10 @@
// assets/controllers/menu_controller.js
import { Controller } from '@hotwired/stimulus';
export default class extends Controller {
static targets = ["sidebar"]
toggleMenu() {
this.sidebarTarget.classList.toggle('-translate-x-full')
}
}

View File

@@ -2,6 +2,7 @@
namespace App\Controller; namespace App\Controller;
use App\Entity\Chapter;
use App\Entity\Manga; use App\Entity\Manga;
use App\Message\DownloadChapter; use App\Message\DownloadChapter;
use App\Repository\ChapterRepository; use App\Repository\ChapterRepository;
@@ -170,22 +171,51 @@ class MangaController extends AbstractController
public function downloadChapter(int $chapterId): BinaryFileResponse public function downloadChapter(int $chapterId): BinaryFileResponse
{ {
$chapter = $this->chapterRepository->find($chapterId); $chapter = $this->chapterRepository->find($chapterId);
$response = $this->mangaExportService->downloadCbz($chapter->getManga()->getTitle(), $chapter->getNumber()); if (!$chapter) {
if ($response === false) {
throw $this->createNotFoundException("Le chapitre demandé n'existe pas."); throw $this->createNotFoundException("Le chapitre demandé n'existe pas.");
} }
// Définir les en-têtes pour le téléchargement $cbzPath = $chapter->getCbzPath();
$response->headers->set('Content-Type', 'application/x-cbz'); if (!$cbzPath || !file_exists($cbzPath)) {
throw $this->createNotFoundException("Le fichier CBZ n'existe pas.");
}
$response = new BinaryFileResponse($cbzPath);
// Vérifier si c'est un volume complet ou un chapitre individuel
$isFullVolume = $this->isFullVolume($chapter);
if ($isFullVolume) {
$fileName = sprintf("%s_volume_%02d.cbz", $chapter->getManga()->getSlug(), $chapter->getVolume());
} else {
$fileName = sprintf("%s_chapter_%s.cbz", $chapter->getManga()->getSlug(), number_format($chapter->getNumber(), 2));
}
$response->setContentDisposition( $response->setContentDisposition(
ResponseHeaderBag::DISPOSITION_ATTACHMENT, ResponseHeaderBag::DISPOSITION_ATTACHMENT,
"{$chapter->getManga()->getSlug()}_{$chapter->getNumber()}.cbz" $fileName
); );
return $response; return $response;
} }
private function isFullVolume(Chapter $chapter): bool
{
$volumeChapters = $this->chapterRepository->findBy([
'manga' => $chapter->getManga(),
'volume' => $chapter->getVolume()
]);
$firstChapterPath = $volumeChapters[0]->getCbzPath();
foreach ($volumeChapters as $volumeChapter) {
if ($volumeChapter->getCbzPath() !== $firstChapterPath) {
return false;
}
}
return true;
}
#[Route('/scrape', name: 'manga_scrape', methods: 'POST')] #[Route('/scrape', name: 'manga_scrape', methods: 'POST')]
public function scrapeByMangaAndChapter(Request $request): Response public function scrapeByMangaAndChapter(Request $request): Response
{ {