Added:
- settings form - manga upload directory - ContentSource export/import
This commit is contained in:
@@ -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']);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user