Added:
- Updated Reader - fix image download for JavascriptScraper.php
This commit is contained in:
@@ -213,38 +213,38 @@ class MangaController extends AbstractController
|
||||
return new JsonResponse(['success' => 'Chapter hidden.'], 200);
|
||||
}
|
||||
|
||||
#[Route('/manga/read/{mangaSlug}/{chapterNumber}/{pageNumber}', name: 'app_manga_read')]
|
||||
public function readChapterPage(string $mangaSlug, float $chapterNumber, int $pageNumber = 1): Response
|
||||
{
|
||||
$manga = $this->mangaRepository->findOneBy(['slug' => $mangaSlug]);
|
||||
if (!$manga) {
|
||||
throw $this->createNotFoundException("Le manga demandé n'existe pas.");
|
||||
}
|
||||
|
||||
$chapter = $manga->getChapterByNumber($chapterNumber);
|
||||
if (!$chapter) {
|
||||
throw $this->createNotFoundException("Le chapitre demandé n'existe pas.");
|
||||
}
|
||||
|
||||
if (is_null($chapter->getCbzPath())) {
|
||||
throw $this->createNotFoundException("Le chapitre demandé n'a pas été scrapé.");
|
||||
}
|
||||
|
||||
$pageContent = $this->cbzService->getPageContent($chapter->getCbzPath(), $pageNumber);
|
||||
if (!$pageContent) {
|
||||
throw $this->createNotFoundException("La page demandée n'existe pas.");
|
||||
}
|
||||
|
||||
$totalPages = $this->cbzService->getPageCount($chapter->getCbzPath());
|
||||
|
||||
return $this->render('manga/manga_reader.html.twig', [
|
||||
'manga' => $manga,
|
||||
'chapter' => $chapter,
|
||||
'currentPage' => $pageNumber,
|
||||
'totalPages' => $totalPages,
|
||||
'pageContent' => base64_encode($pageContent),
|
||||
]);
|
||||
}
|
||||
// #[Route('/manga/read/{mangaSlug}/{chapterNumber}/{pageNumber}', name: 'app_manga_read')]
|
||||
// public function readChapterPage(string $mangaSlug, float $chapterNumber, int $pageNumber = 1): Response
|
||||
// {
|
||||
// $manga = $this->mangaRepository->findOneBy(['slug' => $mangaSlug]);
|
||||
// if (!$manga) {
|
||||
// throw $this->createNotFoundException("Le manga demandé n'existe pas.");
|
||||
// }
|
||||
//
|
||||
// $chapter = $manga->getChapterByNumber($chapterNumber);
|
||||
// if (!$chapter) {
|
||||
// throw $this->createNotFoundException("Le chapitre demandé n'existe pas.");
|
||||
// }
|
||||
//
|
||||
// if (is_null($chapter->getCbzPath())) {
|
||||
// throw $this->createNotFoundException("Le chapitre demandé n'a pas été scrapé.");
|
||||
// }
|
||||
//
|
||||
// $pageContent = $this->cbzService->getPageContent($chapter->getCbzPath(), $pageNumber);
|
||||
// if (!$pageContent) {
|
||||
// throw $this->createNotFoundException("La page demandée n'existe pas.");
|
||||
// }
|
||||
//
|
||||
// $totalPages = $this->cbzService->getPageCount($chapter->getCbzPath());
|
||||
//
|
||||
// return $this->render('manga/manga_reader.html.twig', [
|
||||
// 'manga' => $manga,
|
||||
// 'chapter' => $chapter,
|
||||
// 'currentPage' => $pageNumber,
|
||||
// 'totalPages' => $totalPages,
|
||||
// 'pageContent' => base64_encode($pageContent),
|
||||
// ]);
|
||||
// }
|
||||
|
||||
#[Route('/manga/search/{query}', name: 'app_manga_search')]
|
||||
public function search(string $query = ''): Response
|
||||
|
||||
130
src/Controller/ReaderController.php
Normal file
130
src/Controller/ReaderController.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Repository\MangaRepository;
|
||||
use App\Service\CbzService;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
class ReaderController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly MangaRepository $mangaRepository,
|
||||
private readonly CbzService $cbzService
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
#[Route('/read/{mangaSlug}/{chapterNumber}', name: 'app_reader')]
|
||||
public function read(string $mangaSlug, float $chapterNumber): Response
|
||||
{
|
||||
$manga = $this->mangaRepository->findOneBy(['slug' => $mangaSlug]);
|
||||
if (!$manga) {
|
||||
throw $this->createNotFoundException("Le manga demandé n'existe pas.");
|
||||
}
|
||||
|
||||
$chapter = $manga->getChapterByNumber($chapterNumber);
|
||||
if (!$chapter) {
|
||||
throw $this->createNotFoundException("Le chapitre demandé n'existe pas.");
|
||||
}
|
||||
|
||||
if (is_null($chapter->getCbzPath())) {
|
||||
throw $this->createNotFoundException("Le chapitre demandé n'a pas été scrapé.");
|
||||
}
|
||||
|
||||
$totalPages = $this->cbzService->getPageCount($chapter->getCbzPath());
|
||||
|
||||
return $this->render('reader/index.html.twig', [
|
||||
'manga' => $manga,
|
||||
'chapter' => $chapter,
|
||||
'totalPages' => $totalPages,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/api/read/{mangaSlug}/{chapterNumber}/{pageNumber}', name: 'app_reader_page')]
|
||||
public function getPage(string $mangaSlug, float $chapterNumber, int $pageNumber): Response
|
||||
{
|
||||
$manga = $this->mangaRepository->findOneBy(['slug' => $mangaSlug]);
|
||||
if (!$manga) {
|
||||
throw $this->createNotFoundException("Le manga demandé n'existe pas.");
|
||||
}
|
||||
|
||||
$chapter = $manga->getChapterByNumber($chapterNumber);
|
||||
if (!$chapter) {
|
||||
throw $this->createNotFoundException("Le chapitre demandé n'existe pas.");
|
||||
}
|
||||
|
||||
$pageContent = $this->cbzService->getPageContent($chapter->getCbzPath(), $pageNumber);
|
||||
if (!$pageContent) {
|
||||
throw $this->createNotFoundException("La page demandée n'existe pas.");
|
||||
}
|
||||
|
||||
return new Response(base64_encode($pageContent), 200, ['Content-Type' => 'text/plain']);
|
||||
}
|
||||
|
||||
#[Route('/api/chapters/{mangaSlug}', name: 'app_reader_chapters')]
|
||||
public function getChapters(string $mangaSlug): JsonResponse
|
||||
{
|
||||
$manga = $this->mangaRepository->findOneBy(['slug' => $mangaSlug]);
|
||||
if (!$manga) {
|
||||
throw $this->createNotFoundException("Le manga demandé n'existe pas.");
|
||||
}
|
||||
|
||||
$chapters = $manga->getChapters()
|
||||
->filter(fn($chapter) => $chapter->isVisible() && !is_null($chapter->getCbzPath()))
|
||||
->toArray();
|
||||
|
||||
usort($chapters, fn($a, $b) => $b->getNumber() <=> $a->getNumber());
|
||||
|
||||
$chapters = array_values(array_map(fn($chapter) => [
|
||||
'number' => $chapter->getNumber(),
|
||||
'title' => $chapter->getTitle()
|
||||
], $chapters));
|
||||
|
||||
|
||||
return $this->json($chapters);
|
||||
}
|
||||
|
||||
#[Route('/api/previous-chapter/{mangaSlug}/{currentChapterNumber}', name: 'app_reader_previous_chapter')]
|
||||
public function getPreviousChapter(string $mangaSlug, float $currentChapterNumber): JsonResponse
|
||||
{
|
||||
$manga = $this->mangaRepository->findOneBy(['slug' => $mangaSlug]);
|
||||
if (!$manga) {
|
||||
throw $this->createNotFoundException("Le manga demandé n'existe pas.");
|
||||
}
|
||||
|
||||
$previousChapter = $manga->getChapters()
|
||||
->filter(fn($chapter) => $chapter->isVisible() && $chapter->getNumber() < $currentChapterNumber)
|
||||
->last();
|
||||
|
||||
return $this->json($previousChapter ? [
|
||||
'number' => $previousChapter->getNumber(),
|
||||
'title' => $previousChapter->getTitle()
|
||||
] : null);
|
||||
}
|
||||
|
||||
#[Route('/api/next-chapter/{mangaSlug}/{currentChapterNumber}', name: 'app_reader_next_chapter')]
|
||||
public function getNextChapter(string $mangaSlug, float $currentChapterNumber): JsonResponse
|
||||
{
|
||||
$manga = $this->mangaRepository->findOneBy(['slug' => $mangaSlug]);
|
||||
if (!$manga) {
|
||||
throw $this->createNotFoundException("Le manga demandé n'existe pas.");
|
||||
}
|
||||
|
||||
$nextChapter = $manga->getChapters()
|
||||
->filter(fn($chapter) => $chapter->isVisible() && $chapter->getNumber() > $currentChapterNumber)
|
||||
->toArray();
|
||||
|
||||
usort($nextChapter, fn($a, $b) => $a->getNumber() <=> $b->getNumber());
|
||||
|
||||
$nextChapter = reset($nextChapter) ?: null;
|
||||
|
||||
return $this->json($nextChapter ? [
|
||||
'number' => $nextChapter->getNumber(),
|
||||
'title' => $nextChapter->getTitle()
|
||||
] : null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user