fix(import): extraire les images CBZ vers le stockage individuel

Corrige l'import de chapitres/volumes CBZ qui stockait le chemin du fichier
CBZ comme pagesDirectory. Le reader ne trouvait aucune image car
LegacyChapterRepository attend un dossier d'images individuelles.

- Déplace ImageStorageInterface dans Shared (storeChapterImages + extractFromCbz + countCbzImages)
- Crée ImageStorageManager dans Shared/Infrastructure (extraction ZIP + copie)
- Supprime LocalImageStorage et l'ancienne interface dans Scraping
- Refactore ImportChapterHandler et ImportVolumeHandler pour utiliser ImageStorageInterface
- Corrige LegacyChapterRepository : construit l'URL depuis basename(pagesDirectory)
  au lieu de chapterId (fix pour les volumes partagés)
This commit is contained in:
ext.jeremy.guillot@maxicoffee.domains
2026-03-15 18:26:28 +01:00
parent be8a3c6de8
commit 2e3abb76c3
13 changed files with 173 additions and 108 deletions

View File

@@ -5,13 +5,13 @@ namespace App\Domain\Manga\Application\CommandHandler;
use App\Domain\Manga\Application\Command\ImportVolume;
use App\Domain\Manga\Domain\Contract\Repository\MangaRepositoryInterface;
use App\Domain\Manga\Domain\Exception\MangaNotFoundException;
use App\Domain\Shared\Domain\Contract\MangaPathManagerInterface;
use App\Domain\Shared\Domain\Contract\ImageStorageInterface;
readonly class ImportVolumeHandler
{
public function __construct(
private MangaRepositoryInterface $mangaRepository,
private MangaPathManagerInterface $pathManager
private ImageStorageInterface $imageStorage
) {
}
@@ -40,12 +40,14 @@ readonly class ImportVolumeHandler
);
}
// 4. Save the CBZ file to storage using the path manager
$cbzPath = $this->saveCbzFile($command, $manga);
// 4. Extract CBZ into individual images storage (shared directory for all volume chapters)
$volumeDirectoryId = sprintf('volume_%s_%d', $command->mangaId, $command->volumeNumber);
$pagesDirectory = $this->imageStorage->extractFromCbz($volumeDirectoryId, $command->fileBinary);
$pageCount = $this->imageStorage->countCbzImages($command->fileBinary);
// 5. Update all chapters with the volume path through the aggregate
foreach ($chapters as $chapter) {
$manga->updateChapterPages($chapter, $cbzPath, $chapter->getPageCount());
$manga->updateChapterPages($chapter, $pagesDirectory, $pageCount);
}
$this->mangaRepository->save($manga);
}
@@ -56,19 +58,4 @@ readonly class ImportVolumeHandler
return strpos($fileBinary, $zipMagicNumber) === 0;
}
private function saveCbzFile(ImportVolume $command, \App\Domain\Manga\Domain\Model\Manga $manga): string
{
$cbzPath = $this->pathManager->buildVolumeCbzPath(
$manga->getTitle()->getValue(),
(string)$manga->getPublicationYear(),
$command->volumeNumber
);
if (!file_put_contents($cbzPath, $command->fileBinary)) {
throw new \RuntimeException('Failed to save CBZ file');
}
return $cbzPath;
}
}