- activity on menu
- starting activity page
This commit is contained in:
2024-06-17 22:36:37 +02:00
parent 671551c7f8
commit f7bb7b9148
14 changed files with 524 additions and 33 deletions

View File

@@ -0,0 +1,20 @@
<?php
namespace App\Service;
use Symfony\Component\Mercure\HubInterface;
use Symfony\Component\Mercure\Update;
class ActivityService
{
public function __construct(private HubInterface $hub)
{
}
public function sendUpdate(mixed $data): void
{
$update = new Update('activity', json_encode($data));
$this->hub->publish($update);
}
}

View File

@@ -5,6 +5,7 @@ namespace App\Service;
use App\Entity\Chapter;
use App\Entity\Manga;
use App\Entity\ContentSource;
use App\Event\PageScrappingProgressEvent;
use App\EventSubscriber\MangaScrapedEvent;
use Exception;
use GuzzleHttp\Client;
@@ -143,6 +144,9 @@ class MangaScraperService
$this->downloadAndSaveImage($pageUrl, $imagePath);
$event = new PageScrappingProgressEvent($chapter->getId(), count($pageData) + 1, count($results['chapter']['dataSaver']));
$this->eventDispatcher->dispatch($event, PageScrappingProgressEvent::NAME);
$pageData[] = [
'image_url' => $pageUrl,
'local_image_url' => sprintf('/manga-images/%s/%s/%s', $mangaTitle, $chapterNumber, $imageName),
@@ -215,6 +219,9 @@ class MangaScraperService
$this->downloadAndSaveImage($page['image_url'], $imagePath);
$event = new PageScrappingProgressEvent($chapter->getId(), count($pageData) + 1, 0);
$this->eventDispatcher->dispatch($event, PageScrappingProgressEvent::NAME);
$pageData[] = [
'image_url' => $page['image_url'],
'local_image_url' => sprintf('/manga-images/%s/%s/%s', $mangaTitle, $chapterNumber, $imageName),

View File

@@ -12,7 +12,7 @@ use Symfony\Component\String\Slugger\SluggerInterface;
readonly class MangadexProvider implements MetadataProviderInterface
{
public function __construct(private ClientInterface $client, private SluggerInterface $slugger)
public function __construct(private ClientInterface $client, private SluggerInterface $slugger, private NotificationService $notificationService)
{
}
@@ -22,12 +22,17 @@ readonly class MangadexProvider implements MetadataProviderInterface
return new ArrayCollection();
}
$results = $this->client->get('/manga', [
'title' => $title,
'contentRating' => ['safe', 'suggestive'],
'includes' => ['cover_art', 'author'],
'limit' => 25
]);
try{
$results = $this->client->get('/manga', [
'title' => $title,
'contentRating' => ['safe', 'suggestive'],
'includes' => ['cover_art', 'author'],
'limit' => 25
]);
}catch(\Exception $e){
$this->notificationService->sendUpdate('notification', ['status' => 'error', 'message' => 'An error occurred while fetching data from Mangadex.']);
return new ArrayCollection();
}
$mangas = [];
foreach ($results['data'] as $result) {

View File

@@ -12,9 +12,9 @@ class NotificationService
}
public function sendUpdate(string $topic, mixed $data): void
public function sendUpdate(mixed $data): void
{
$update = new Update($topic, json_encode($data));
$update = new Update('notification', json_encode($data));
$this->hub->publish($update);
}
}