Added:
- AdditionnalData for buttons - refresh manga metadata and chapters
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Entity\Chapter;
|
||||
use App\Entity\Manga;
|
||||
use App\Manager\Toolbar\Factory\ToolbarFactory;
|
||||
use App\Message\DownloadChapter;
|
||||
use App\Message\RefreshMetadata;
|
||||
use App\Repository\ChapterRepository;
|
||||
use App\Repository\MangaRepository;
|
||||
use App\Service\CbzService;
|
||||
@@ -33,8 +34,7 @@ class MangaController extends AbstractController
|
||||
private readonly CbzService $cbzService,
|
||||
private readonly ToolbarFactory $toolbarFactory,
|
||||
private readonly MangadexProvider $mangadexProvider,
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly NotificationService $notificationService
|
||||
private readonly EntityManagerInterface $entityManager
|
||||
)
|
||||
{
|
||||
}
|
||||
@@ -92,11 +92,10 @@ class MangaController extends AbstractController
|
||||
}
|
||||
return $b <=> $a;
|
||||
});
|
||||
|
||||
return $this->render('manga/show_chapters.html.twig', [
|
||||
'chapters_by_volume' => $chaptersByVolume,
|
||||
'manga' => $manga,
|
||||
'toolbar' => $this->toolbarFactory->createToolbar('chapter_list')->getGroups(),
|
||||
'toolbar' => $this->toolbarFactory->createToolbar('chapter_list', ['mangaId' => $manga->getId()])->getGroups(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -167,39 +166,12 @@ class MangaController extends AbstractController
|
||||
->setRating($request->request->get('rating'))
|
||||
->setExternalId($request->request->get('externalId'));
|
||||
|
||||
$mangaFeed = $this->mangadexProvider->getFeed($manga);
|
||||
$mangaAggregate = $this->mangadexProvider->getMangaAggregate($manga);
|
||||
$mergedChapters = $this->mangadexProvider->addAllChaptersToManga($manga);
|
||||
|
||||
$allChapters = array_merge($mangaFeed, $mangaAggregate);
|
||||
|
||||
if (empty($allChapters)) {
|
||||
$this->notificationService->sendUpdate([
|
||||
'status' => 'error',
|
||||
'message' => 'No chapters found for this manga.'
|
||||
]);
|
||||
if (empty($mergedChapters)) {
|
||||
return $this->redirectToRoute('app_manga_search', ['query' => $manga->getTitle()]);
|
||||
}
|
||||
|
||||
$mergedChapters = [];
|
||||
foreach ($allChapters as $chapter) {
|
||||
$number = $chapter->getNumber();
|
||||
|
||||
if (isset($mergedChapters[$number])) {
|
||||
$existingChapter = $mergedChapters[$number];
|
||||
|
||||
if (!empty($chapter->getExternalId()) ||
|
||||
(empty($existingChapter->getExternalId()) && !strpos($chapter->getTitle(), 'Chapter ') == 0)) {
|
||||
$mergedChapters[$number] = $chapter;
|
||||
}
|
||||
} else {
|
||||
$mergedChapters[$number] = $chapter;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($mergedChapters as $chapter) {
|
||||
$manga->addChapter($chapter);
|
||||
}
|
||||
|
||||
try {
|
||||
foreach ($manga->getChapters() as $chapter) {
|
||||
$this->entityManager->persist($chapter);
|
||||
@@ -264,6 +236,19 @@ class MangaController extends AbstractController
|
||||
return $response;
|
||||
}
|
||||
|
||||
#[Route('/refresh_metadata', name: 'refresh_metadata')]
|
||||
public function refreshMetadata(Request $request): JsonResponse
|
||||
{
|
||||
$mangaId = json_decode($request->getContent(), true)['mangaId'];
|
||||
$manga = $this->mangaRepository->find($mangaId);
|
||||
if (!$manga) {
|
||||
return new JsonResponse(['error' => 'Manga Not Found.'], 400);
|
||||
}
|
||||
$this->bus->dispatch(new RefreshMetadata($mangaId));
|
||||
|
||||
return new JsonResponse(['success' => 'Metadata refresh started...'], 200);
|
||||
}
|
||||
|
||||
private function isFullVolume(Chapter $chapter): bool
|
||||
{
|
||||
$volumeChapters = $this->chapterRepository->findBy([
|
||||
|
||||
Reference in New Issue
Block a user