Added:
- hamburger menu - download cbz
This commit is contained in:
10
assets/controllers/menu_controller.js
Normal file
10
assets/controllers/menu_controller.js
Normal 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')
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Chapter;
|
||||
use App\Entity\Manga;
|
||||
use App\Message\DownloadChapter;
|
||||
use App\Repository\ChapterRepository;
|
||||
@@ -170,22 +171,51 @@ class MangaController extends AbstractController
|
||||
public function downloadChapter(int $chapterId): BinaryFileResponse
|
||||
{
|
||||
$chapter = $this->chapterRepository->find($chapterId);
|
||||
$response = $this->mangaExportService->downloadCbz($chapter->getManga()->getTitle(), $chapter->getNumber());
|
||||
|
||||
if ($response === false) {
|
||||
if (!$chapter) {
|
||||
throw $this->createNotFoundException("Le chapitre demandé n'existe pas.");
|
||||
}
|
||||
|
||||
// Définir les en-têtes pour le téléchargement
|
||||
$response->headers->set('Content-Type', 'application/x-cbz');
|
||||
$cbzPath = $chapter->getCbzPath();
|
||||
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(
|
||||
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
|
||||
"{$chapter->getManga()->getSlug()}_{$chapter->getNumber()}.cbz"
|
||||
$fileName
|
||||
);
|
||||
|
||||
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')]
|
||||
public function scrapeByMangaAndChapter(Request $request): Response
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user