Added:
- settings form - manga upload directory - ContentSource export/import
This commit is contained in:
@@ -222,6 +222,9 @@ class MangaController extends AbstractController
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
#[Route('/addManga', name: 'app_manga_add')]
|
||||
public function addManga(Request $request): Response
|
||||
{
|
||||
@@ -248,8 +251,8 @@ class MangaController extends AbstractController
|
||||
$imageUrls = $this->processAndSaveImage($imageUrl);
|
||||
$manga->setImageUrl($imageUrls['full']);
|
||||
$manga->setThumbnailUrl($imageUrls['thumbnail']);
|
||||
} catch (\Exception $e) {
|
||||
// Gérer l'exception (par exemple, logger l'erreur)
|
||||
} catch (\Exception|GuzzleException $e) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$mergedChapters = $this->mangadexProvider->addAllChaptersToManga($manga);
|
||||
|
||||
@@ -3,7 +3,10 @@
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\ContentSource;
|
||||
use App\Form\AppSettingsType;
|
||||
use App\Form\ContentSourceType;
|
||||
use App\Manager\AppSettingsManager;
|
||||
use App\Manager\Toolbar\Factory\ToolbarFactory;
|
||||
use App\Repository\ContentSourceRepository;
|
||||
|
||||
use App\Service\NotificationService;
|
||||
@@ -21,7 +24,8 @@ class SettingsController extends AbstractController
|
||||
public function __construct(
|
||||
private MangaScraperService $mangaScraperService,
|
||||
private EntityManagerInterface $entityManager,
|
||||
private NotificationService $notificationService
|
||||
private NotificationService $notificationService,
|
||||
private ContentSourceRepository $contentSourceRepository
|
||||
)
|
||||
{
|
||||
|
||||
@@ -44,20 +48,34 @@ class SettingsController extends AbstractController
|
||||
}
|
||||
|
||||
#[Route('/settings/folders', name: 'app_settings_folders')]
|
||||
public function folders(): Response
|
||||
public function folders(Request $request, AppSettingsManager $settingsManager): Response
|
||||
{
|
||||
return $this->render('settings/index.html.twig', [
|
||||
'controller_name' => 'SettingsController',
|
||||
$currentSettings = $settingsManager->getSettings();
|
||||
|
||||
$form = $this->createForm(AppSettingsType::class, $currentSettings);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$newSettings = $form->getData();
|
||||
$settingsManager->updateSettings($newSettings);
|
||||
|
||||
$this->notificationService->sendUpdate(['status' => 'success', 'message' => 'Settings updated successfully.']);
|
||||
return $this->json(['success' => true]);
|
||||
}
|
||||
|
||||
return $this->render('settings/folders.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/settings/scrappers/list', name: 'app_settings_scrappers_list')]
|
||||
public function list(ContentSourceRepository $repository): Response
|
||||
public function list(ContentSourceRepository $repository, ToolbarFactory $toolbarFactory): Response
|
||||
{
|
||||
$contentSources = $repository->findAll();
|
||||
|
||||
return $this->render('settings/scrapper_list.html.twig', [
|
||||
'contentSources' => $contentSources,
|
||||
'toolbar' => $toolbarFactory->createToolbar('scraper_list')->getGroups(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -137,4 +155,51 @@ class SettingsController extends AbstractController
|
||||
'controller_name' => 'SettingsController',
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/settings/export_scrappers', name: 'app_settings_scrappers_export', methods: ['GET'])]
|
||||
public function exportScrappers(): JsonResponse
|
||||
{
|
||||
$contentSources = $this->contentSourceRepository->findAll();
|
||||
$data = [];
|
||||
|
||||
foreach ($contentSources as $source) {
|
||||
$data[] = [
|
||||
'baseUrl' => $source->getBaseUrl(),
|
||||
'imageSelector' => $source->getImageSelector(),
|
||||
'nextPageSelector' => $source->getNextPageSelector(),
|
||||
'chapterUrlFormat' => $source->getChapterUrlFormat(),
|
||||
'scrapingType' => $source->getScrapingType(),
|
||||
'chapterSelector' => $source->getChapterSelector(), //TODO à renommer en chapterListSelector
|
||||
];
|
||||
}
|
||||
|
||||
return new JsonResponse($data);
|
||||
}
|
||||
|
||||
#[Route('/settings/import_scrappers', name: 'app_settings_scrappers_import', methods: ['POST'])]
|
||||
public function importScrappers(Request $request): JsonResponse
|
||||
{
|
||||
$content = $request->getContent();
|
||||
$data = json_decode($content, true);
|
||||
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
$this->notificationService->sendUpdate(['status' => 'error', 'message' => 'Invalid JSON data']);
|
||||
return new JsonResponse(['error' => 'Invalid JSON data'], 400);
|
||||
}
|
||||
|
||||
foreach ($data as $sourceData) {
|
||||
$contentSource = new ContentSource();
|
||||
$contentSource->setBaseUrl($sourceData['baseUrl']);
|
||||
$contentSource->setImageSelector($sourceData['imageSelector']);
|
||||
$contentSource->setNextPageSelector($sourceData['nextPageSelector']);
|
||||
$contentSource->setChapterUrlFormat($sourceData['chapterUrlFormat']);
|
||||
$contentSource->setScrapingType($sourceData['scrapingType']);
|
||||
|
||||
$this->entityManager->persist($contentSource);
|
||||
}
|
||||
|
||||
$this->entityManager->flush();
|
||||
|
||||
return new JsonResponse(['message' => 'Content sources imported successfully']);
|
||||
}
|
||||
}
|
||||
|
||||
50
src/Entity/AppSettings.php
Normal file
50
src/Entity/AppSettings.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\AppSettingsRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: AppSettingsRepository::class)]
|
||||
class AppSettings
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $MangaDirectory = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $ImageDirectory = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getMangaDirectory(): ?string
|
||||
{
|
||||
return $this->MangaDirectory;
|
||||
}
|
||||
|
||||
public function setMangaDirectory(?string $MangaDirectory): static
|
||||
{
|
||||
$this->MangaDirectory = $MangaDirectory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getImageDirectory(): ?string
|
||||
{
|
||||
return $this->ImageDirectory;
|
||||
}
|
||||
|
||||
public function setImageDirectory(?string $ImageDirectory): static
|
||||
{
|
||||
$this->ImageDirectory = $ImageDirectory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -20,16 +20,10 @@ class Chapter
|
||||
#[ORM\Column]
|
||||
private ?float $number = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private array $pages = [];
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'chapters')]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
private ?Manga $manga = null;
|
||||
|
||||
#[ORM\OneToMany(mappedBy: 'chapter', targetEntity: Page::class, orphanRemoval: true)]
|
||||
private Collection $pagesLink;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?int $volume = null;
|
||||
|
||||
@@ -45,12 +39,11 @@ class Chapter
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $cbzPath = null;
|
||||
|
||||
#[ORM\Column]
|
||||
#[ORM\Column(type: 'boolean', options: ['default' => true])]
|
||||
private ?bool $visible = true;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->pagesLink = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
@@ -70,18 +63,6 @@ class Chapter
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPages(): array
|
||||
{
|
||||
return $this->pages;
|
||||
}
|
||||
|
||||
public function setPages(array $pages): self
|
||||
{
|
||||
$this->pages = $pages;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getManga(): ?Manga
|
||||
{
|
||||
return $this->manga;
|
||||
@@ -94,50 +75,6 @@ class Chapter
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Page>
|
||||
*/
|
||||
public function getPagesLink(): Collection
|
||||
{
|
||||
return $this->pagesLink;
|
||||
}
|
||||
|
||||
public function addPagesLink(Page $pagesLink): self
|
||||
{
|
||||
if (!$this->pagesLink->contains($pagesLink)) {
|
||||
$this->pagesLink->add($pagesLink);
|
||||
$pagesLink->setChapter($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removePagesLink(Page $pagesLink): self
|
||||
{
|
||||
if ($this->pagesLink->removeElement($pagesLink)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($pagesLink->getChapter() === $this) {
|
||||
$pagesLink->setChapter(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPageByNumber(int $number): ?Page
|
||||
{
|
||||
/**
|
||||
* @var Page $page
|
||||
*/
|
||||
foreach ($this->pagesLink as $page) {
|
||||
if ($page->getNumber() === $number) {
|
||||
return $page;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getVolume(): ?int
|
||||
{
|
||||
return $this->volume;
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\PageRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: PageRepository::class)]
|
||||
class Page
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?int $number = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $imageUrl = null;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'pagesLink')]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
private ?Chapter $chapter = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $imageLocalUrl = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getNumber(): ?int
|
||||
{
|
||||
return $this->number;
|
||||
}
|
||||
|
||||
public function setNumber(int $number): self
|
||||
{
|
||||
$this->number = $number;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getImageUrl(): ?string
|
||||
{
|
||||
return $this->imageUrl;
|
||||
}
|
||||
|
||||
public function setImageUrl(string $imageUrl): self
|
||||
{
|
||||
$this->imageUrl = $imageUrl;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getChapter(): ?Chapter
|
||||
{
|
||||
return $this->chapter;
|
||||
}
|
||||
|
||||
public function setChapter(?Chapter $chapter): self
|
||||
{
|
||||
$this->chapter = $chapter;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getImageLocalUrl(): ?string
|
||||
{
|
||||
return $this->imageLocalUrl;
|
||||
}
|
||||
|
||||
public function setImageLocalUrl(string $imageLocalUrl): self
|
||||
{
|
||||
$this->imageLocalUrl = $imageLocalUrl;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
30
src/Form/AppSettingsType.php
Normal file
30
src/Form/AppSettingsType.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\AppSettings;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class AppSettingsType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('mangaDirectory', TextType::class, [
|
||||
'label' => 'Manga Directory',
|
||||
])
|
||||
->add('imageDirectory', TextType::class, [
|
||||
'label' => 'Image Directory',
|
||||
]);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => AppSettings::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ class ContentSourceType extends AbstractType
|
||||
'label' => 'Image Selector',
|
||||
])
|
||||
->add('chapterUrlFormat', TextType::class, [
|
||||
'label' => 'Chapter URL Format',
|
||||
'label' => 'Chapter URL Format ({slug}, {chapterNumber})',
|
||||
])
|
||||
->add('nextPageSelector', TextType::class, [
|
||||
'label' => 'Next Page Selector (let empty if vertical reader)',
|
||||
|
||||
52
src/Manager/AppSettingsManager.php
Normal file
52
src/Manager/AppSettingsManager.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Manager;
|
||||
|
||||
use App\Entity\AppSettings;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
class AppSettingsManager
|
||||
{
|
||||
private const string DEFAULT_MANGA_DIRECTORY = '/manga_data';
|
||||
private const string DEFAULT_IMAGE_DIRECTORY = '/image_data';
|
||||
|
||||
public function __construct(private readonly EntityManagerInterface $entityManager)
|
||||
{
|
||||
}
|
||||
|
||||
public function getSettings(): AppSettings
|
||||
{
|
||||
$settings = $this->entityManager->getRepository(AppSettings::class)->findOneBy([]);
|
||||
if (!$settings) {
|
||||
$settings = $this->createDefaultSettings();
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
public function updateSettings(AppSettings $newSettings): void
|
||||
{
|
||||
$settings = $this->entityManager->getRepository(AppSettings::class)->findOneBy([]);
|
||||
if (!$settings) {
|
||||
$settings = new AppSettings();
|
||||
}
|
||||
|
||||
$settings->setMangaDirectory($newSettings->getMangaDirectory());
|
||||
$settings->setImageDirectory($newSettings->getImageDirectory());
|
||||
|
||||
$this->entityManager->persist($settings);
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
|
||||
private function createDefaultSettings(): AppSettings
|
||||
{
|
||||
$settings = new AppSettings();
|
||||
$settings->setMangaDirectory(self::DEFAULT_MANGA_DIRECTORY);
|
||||
$settings->setImageDirectory(self::DEFAULT_IMAGE_DIRECTORY);
|
||||
|
||||
$this->entityManager->persist($settings);
|
||||
$this->entityManager->flush();
|
||||
|
||||
return $settings;
|
||||
}
|
||||
}
|
||||
@@ -11,17 +11,48 @@ class FileSystemManager
|
||||
private const string UPLOADS_DIRECTORY = 'public/tmp';
|
||||
private const string IMAGES_DIRECTORY = 'public/images';
|
||||
|
||||
private string $mangaDirectory;
|
||||
private string $imageDirectory;
|
||||
|
||||
public function __construct(
|
||||
private readonly string $projectDir,
|
||||
private readonly Filesystem $filesystem,
|
||||
private readonly SluggerInterface $slugger
|
||||
) {
|
||||
private readonly string $projectDir,
|
||||
private readonly Filesystem $filesystem,
|
||||
private readonly SluggerInterface $slugger,
|
||||
private readonly AppSettingsManager $appSettingsManager
|
||||
)
|
||||
{
|
||||
$this->loadSettings();
|
||||
}
|
||||
|
||||
private function loadSettings(): void
|
||||
{
|
||||
$settings = $this->appSettingsManager->getSettings();
|
||||
$this->mangaDirectory = $settings->getMangaDirectory();
|
||||
$this->imageDirectory = $settings->getImageDirectory();
|
||||
}
|
||||
|
||||
public function getMangaDirectory(): string
|
||||
{
|
||||
return $this->mangaDirectory;
|
||||
}
|
||||
|
||||
public function getImageDirectory(): string
|
||||
{
|
||||
return $this->imageDirectory;
|
||||
}
|
||||
|
||||
public function getImagePath(string $subDir = ''): string
|
||||
{
|
||||
if(!$this->filesystem->exists($this->projectDir. '/' . self::IMAGES_DIRECTORY . ($subDir ? "/$subDir" : ''))) {
|
||||
$this->filesystem->mkdir($this->projectDir. '/' . self::IMAGES_DIRECTORY . ($subDir ? "/$subDir" : ''), 0755);
|
||||
}
|
||||
return $this->projectDir. '/' . self::IMAGES_DIRECTORY . ($subDir ? "/$subDir" : '');
|
||||
}
|
||||
|
||||
public function createMangaDirectory(string $mangaSlug, ?int $year): string
|
||||
{
|
||||
$year = $year ?? 'unknown';
|
||||
$directoryPath = $this->projectDir . '/' . self::CBZ_DIRECTORY . '/' . ucfirst($mangaSlug) . " ($year)";
|
||||
$directoryPath = $this->mangaDirectory . '/' . ucfirst($mangaSlug) . " ($year)";
|
||||
$this->filesystem->mkdir($directoryPath, 0755);
|
||||
return $directoryPath;
|
||||
}
|
||||
@@ -76,11 +107,6 @@ class FileSystemManager
|
||||
return $safeFilename . '-' . uniqid() . '.' . pathinfo($originalFilename, PATHINFO_EXTENSION);
|
||||
}
|
||||
|
||||
public function getImagePath(string $subDir = ''): string
|
||||
{
|
||||
return $this->projectDir . '/' . self::IMAGES_DIRECTORY . ($subDir ? "/$subDir" : '');
|
||||
}
|
||||
|
||||
public function generateUniqueImageFilename(string $originalFilename): string
|
||||
{
|
||||
$safeFilename = $this->slugger->slug(pathinfo($originalFilename, PATHINFO_FILENAME));
|
||||
|
||||
16
src/Manager/Toolbar/Definition/ScraperListToolbar.php
Normal file
16
src/Manager/Toolbar/Definition/ScraperListToolbar.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Manager\Toolbar\Definition;
|
||||
|
||||
use App\Manager\Toolbar\Element\ToolbarButton;
|
||||
use App\Manager\Toolbar\Element\ToolbarDivider;
|
||||
|
||||
class ScraperListToolbar extends Toolbar
|
||||
{
|
||||
public function __construct(array $contextData = [])
|
||||
{
|
||||
$this->addToRightGroup(new ToolbarButton('file-import', 'Import Json', 'toolbar#openImportModal'))
|
||||
->addToRightGroup(new ToolbarDivider())
|
||||
->addToRightGroup(new ToolbarButton('file-export', 'Export Json', 'toolbar#openExportModal'));
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ namespace App\Manager\Toolbar\Factory;
|
||||
use App\Manager\Toolbar\Definition\ActivityToolbar;
|
||||
use App\Manager\Toolbar\Definition\ChapterListToolbar;
|
||||
use App\Manager\Toolbar\Definition\MangaListToolbar;
|
||||
use App\Manager\Toolbar\Definition\ScraperListToolbar;
|
||||
use App\Manager\Toolbar\Definition\Toolbar;
|
||||
|
||||
class ToolbarFactory
|
||||
@@ -15,6 +16,7 @@ class ToolbarFactory
|
||||
'manga_list' => new MangaListToolbar(),
|
||||
'chapter_list' => new ChapterListToolbar($context),
|
||||
'activity' => new ActivityToolbar($context),
|
||||
'scraper_list' => new ScraperListToolbar($context),
|
||||
default => throw new \InvalidArgumentException("Unknown toolbar type: $type"),
|
||||
};
|
||||
}
|
||||
|
||||
48
src/Repository/AppSettingsRepository.php
Normal file
48
src/Repository/AppSettingsRepository.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\AppSettings;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<AppSettings>
|
||||
*
|
||||
* @method AppSettings|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method AppSettings|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method AppSettings[] findAll()
|
||||
* @method AppSettings[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class AppSettingsRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, AppSettings::class);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return AppSettings[] Returns an array of AppSettings objects
|
||||
// */
|
||||
// public function findByExampleField($value): array
|
||||
// {
|
||||
// return $this->createQueryBuilder('a')
|
||||
// ->andWhere('a.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->orderBy('a.id', 'ASC')
|
||||
// ->setMaxResults(10)
|
||||
// ->getQuery()
|
||||
// ->getResult()
|
||||
// ;
|
||||
// }
|
||||
|
||||
// public function findOneBySomeField($value): ?AppSettings
|
||||
// {
|
||||
// return $this->createQueryBuilder('a')
|
||||
// ->andWhere('a.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user