- Updated Reader
- fix image download for JavascriptScraper.php
This commit is contained in:
Jérémy Guillot
2024-07-23 15:30:05 +02:00
parent c56f72b813
commit 4484be4d4e
11 changed files with 356 additions and 62 deletions

View File

@@ -7,6 +7,7 @@ use App\Entity\ContentSource;
use App\Entity\Manga;
use App\Event\PageScrappingProgressEvent;
use Doctrine\ORM\EntityManagerInterface;
use Exception;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Exception\RequestException;
@@ -107,4 +108,24 @@ abstract class AbstractScraper implements ScraperInterface
$event = new PageScrappingProgressEvent($chapter->getId(), $currentPage, $totalPages);
$this->eventDispatcher->dispatch($event, PageScrappingProgressEvent::NAME);
}
/**
* @throws GuzzleException
* @throws Exception
*/
protected function downloadAndSaveImage(string $imageUrl, string $destinationPath): void
{
try {
$response = $this->httpClient->get($imageUrl);
$contentType = $response->getHeaderLine('Content-Type');
if (str_starts_with($contentType, 'image/')) {
file_put_contents($destinationPath, $response->getBody()->getContents());
} else {
throw new Exception('Le contenu récupéré n\'est pas une image. Type de contenu : ' . $contentType);
}
} catch (Exception $e) {
throw new Exception('Erreur lors de la récupération de l\'image : ' . $e->getMessage());
}
}
}