feat: ajout de la fonctionnalité de téléchargement des volumes de manga, avec mise à jour de l'API et des composants pour gérer l'indicateur de chargement et le téléchargement des fichiers.

This commit is contained in:
ext.jeremy.guillot@maxicoffee.domains
2025-06-29 23:35:22 +02:00
parent 17f9feea7b
commit d23c82631e
4 changed files with 119 additions and 7 deletions

View File

@@ -39,11 +39,47 @@ readonly class FileService implements FileServiceInterface
throw new \RuntimeException('Cannot create CBZ file');
}
$imageCounter = 1;
foreach ($cbzPaths as $cbzPath) {
if ($this->cbzExists($cbzPath)) {
$filename = basename($cbzPath);
$cbz->addFile($cbzPath, $filename);
if (!$this->cbzExists($cbzPath)) {
continue;
}
$sourceCbz = new \ZipArchive();
if ($sourceCbz->open($cbzPath) !== true) {
continue; // Skip if we can't open the CBZ
}
// Extract all images from the current CBZ
for ($i = 0; $i < $sourceCbz->numFiles; $i++) {
$fileName = $sourceCbz->getNameIndex($i);
$fileInfo = $sourceCbz->statIndex($i);
// Skip directories and non-image files
if ($fileInfo['size'] === 0 || !$this->isImageFile($fileName)) {
continue;
}
// Get the file content
$imageContent = $sourceCbz->getFromIndex($i);
if ($imageContent === false) {
continue;
}
// Get file extension
$extension = pathinfo($fileName, PATHINFO_EXTENSION);
// Create a new filename with proper ordering
$newFileName = sprintf('%04d.%s', $imageCounter, $extension);
// Add the image to the volume CBZ
$cbz->addFromString($newFileName, $imageContent);
$imageCounter++;
}
$sourceCbz->close();
}
$cbz->close();
@@ -61,6 +97,14 @@ readonly class FileService implements FileServiceInterface
return $response;
}
private function isImageFile(string $fileName): bool
{
$imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp'];
$extension = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
return in_array($extension, $imageExtensions);
}
public function deleteCbzFile(string $filePath): bool
{
if (!$this->cbzExists($filePath)) {