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:
parent
17f9feea7b
commit
d23c82631e
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user