- Gettings chapters from non En/Fr sources
- mercure fonctionne!
This commit is contained in:
Jérémy Guillot
2024-06-16 13:14:32 +02:00
parent bc85649789
commit 671551c7f8
11 changed files with 313 additions and 65 deletions

View File

@@ -29,7 +29,7 @@ class MangaController extends AbstractController
private readonly MangaExportService $mangaExportService,
private readonly LelScansProviderService $mangaProviderService,
private readonly MangaRepository $mangaRepository,
private ChapterRepository $chapterRepository,
private ChapterRepository $chapterRepository,
private MangaUpdatesMetadataProvider $mangaUpdatesDbProvider,
private MessageBusInterface $bus
)
@@ -63,12 +63,24 @@ class MangaController extends AbstractController
foreach ($manga->getChapters() as $chapter) {
$volume = $chapter->getVolume() ?? 'Not Found';
$chaptersByVolume[$volume][] = $chapter;
usort($chaptersByVolume[$volume], function ($a, $b) {
return $a->getNumber() <=> $b->getNumber();
});
}
$chaptersByVolume = array_map('array_reverse', array_reverse($chaptersByVolume, true));
foreach ($chaptersByVolume as $volume => &$chapters) {
usort($chapters, function ($a, $b) {
return $b->getNumber() <=> $a->getNumber();
});
}
unset($chapters);
uksort($chaptersByVolume, function ($a, $b) {
if ($a == 0) {
return -1;
}
if ($b == 0) {
return 1;
}
return $b <=> $a;
});
return $this->render('manga/show_chapters.html.twig', [
'chapters_by_volume' => $chaptersByVolume,
@@ -125,8 +137,8 @@ class MangaController extends AbstractController
$chapter = $this->chapterRepository->find($id);
if (!$chapter) {
return new JsonResponse(['error' => 'Chapter Not Found.'], 400);
}elseif ($chapter->getLocalPath() !== null){
return new JsonResponse(['error' => 'Chapter already scraped.'], 400);
} elseif ($chapter->getLocalPath() !== null) {
return new JsonResponse(['error' => 'Chapter already scraped.'], 400);
}
$this->bus->dispatch(new DownloadChapter($id));
@@ -134,10 +146,11 @@ class MangaController extends AbstractController
return new JsonResponse(['success' => 'Scrapping started...'], 200);
}
#[Route('/manga/{mangaSlug}/chapter/{chapterNumber}/download', name: 'download_chapter')]
public function downloadChapter(string $mangaSlug, float $chapterNumber): BinaryFileResponse
#[Route('/download-cbz/{chapterId}', name: 'download_cbz')]
public function downloadChapter(int $chapterId): BinaryFileResponse
{
$response = $this->mangaExportService->downloadCbz($this->slugToTitle($mangaSlug), $chapterNumber);
$chapter = $this->chapterRepository->find($chapterId);
$response = $this->mangaExportService->downloadCbz($chapter->getManga()->getTitle(), $chapter->getNumber());
if ($response === false) {
throw $this->createNotFoundException("Le chapitre demandé n'existe pas.");
@@ -147,7 +160,7 @@ class MangaController extends AbstractController
$response->headers->set('Content-Type', 'application/x-cbz');
$response->setContentDisposition(
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
"{$mangaSlug}_{$chapterNumber}.cbz"
"{$chapter->getManga()->getSlug()}_{$chapter->getNumber()}.cbz"
);
return $response;