feat: refonte du gestionnaire de chapitres pour intégrer la génération de fichiers CBZ, le téléchargement d'images en lot et la gestion des requêtes de scraping, avec mise à jour des interfaces et des modèles associés

This commit is contained in:
ext.jeremy.guillot@maxicoffee.domains
2025-03-28 20:42:21 +01:00
parent cdee6f77fc
commit d7088b14c2
22 changed files with 620 additions and 195 deletions

View File

@@ -0,0 +1,48 @@
<?php
namespace App\Tests\Domain\Scraping\Adapter;
use App\Domain\Scraping\Domain\Contract\Service\ImageDownloaderInterface;
use App\Domain\Scraping\Domain\Model\ValueObject\DownloadResult;
use App\Domain\Scraping\Domain\Model\ValueObject\TempDirectory;
class InMemoryImageDownloader implements ImageDownloaderInterface
{
private array $downloadedFiles = [];
private ?\Exception $shouldThrowException = null;
public function download(string $url, string $destination): void
{
if ($this->shouldThrowException) {
throw $this->shouldThrowException;
}
$this->downloadedFiles[$url] = $destination;
}
public function downloadBatch(array $urls, TempDirectory $tempDir, string $jobId): array
{
if ($this->shouldThrowException) {
throw $this->shouldThrowException;
}
$results = [];
foreach ($urls as $index => $url) {
$destination = sprintf('%s/%03d.jpg', $tempDir->getPath(), $index + 1);
$this->download($url, $destination);
$results[] = new DownloadResult($destination, $url);
}
return $results;
}
public function simulateError(\Exception $exception): void
{
$this->shouldThrowException = $exception;
}
public function getDownloadedFiles(): array
{
return $this->downloadedFiles;
}
}