Added:
- FileSystemManager.php refactoring of all write/read actions on filesystem Deleted: - old ToolbarManager.php
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Entity\Chapter;
|
||||
use App\Entity\ContentSource;
|
||||
use App\Entity\Manga;
|
||||
use App\Event\PageScrappingProgressEvent;
|
||||
use App\Manager\FileSystemManager;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Exception;
|
||||
use GuzzleHttp\Client;
|
||||
@@ -15,11 +16,10 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
abstract class AbstractScraper implements ScraperInterface
|
||||
{
|
||||
const string PUBLIC_CBZ = '/public/cbz';
|
||||
protected Client $httpClient;
|
||||
|
||||
public function __construct(
|
||||
protected string $projectDir,
|
||||
protected FileSystemManager $fileSystemManager,
|
||||
protected EventDispatcherInterface $eventDispatcher,
|
||||
protected EntityManagerInterface $entityManager
|
||||
)
|
||||
@@ -53,7 +53,8 @@ abstract class AbstractScraper implements ScraperInterface
|
||||
|
||||
protected function generateCbzPath(Manga $manga, Chapter $chapter): string
|
||||
{
|
||||
$volumeDir = $this->createDirectories($manga, $chapter->getVolume());
|
||||
$mangaDir = $this->fileSystemManager->createMangaDirectory($manga->getSlug(), $manga->getPublicationYear());
|
||||
$volumeDir = $this->fileSystemManager->createVolumeDirectory($mangaDir, $chapter->getVolume());
|
||||
$fileName = sprintf('%s_vol%d_ch%s.cbz',
|
||||
$manga->getSlug(),
|
||||
$chapter->getVolume(),
|
||||
@@ -62,7 +63,7 @@ abstract class AbstractScraper implements ScraperInterface
|
||||
return $volumeDir . '/' . $fileName;
|
||||
}
|
||||
|
||||
protected function createCbzFile(string $tempDir, array $pageData, string $cbzFilePath): void
|
||||
protected function createCbzFile(array $pageData, string $cbzFilePath): void
|
||||
{
|
||||
$zip = new \ZipArchive();
|
||||
|
||||
@@ -76,26 +77,7 @@ abstract class AbstractScraper implements ScraperInterface
|
||||
|
||||
protected function cleanupTempFiles(string $directory): void
|
||||
{
|
||||
$files = glob($directory . '/*');
|
||||
foreach ($files as $file) {
|
||||
if (is_file($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
rmdir($directory);
|
||||
}
|
||||
|
||||
protected function createDirectories(Manga $manga, int $volume): string
|
||||
{
|
||||
$mangaYear = $manga->getPublicationYear() ?? 'unknown';
|
||||
$mangaDir = sprintf('%s/%s (%s)', $this->projectDir . self::PUBLIC_CBZ, ucfirst($manga->getSlug()), $mangaYear);
|
||||
$volumeDir = sprintf('%s/volume_%d', $mangaDir, sprintf('%02d', $volume));
|
||||
|
||||
if (!is_dir($volumeDir)) {
|
||||
mkdir($volumeDir, 0755, true);
|
||||
}
|
||||
|
||||
return $volumeDir;
|
||||
$this->fileSystemManager->deleteDirectory($directory);
|
||||
}
|
||||
|
||||
protected function cleanImageUrl(string $url): string
|
||||
|
||||
Reference in New Issue
Block a user