From b1a68dfbbbe71405711f403500c0bf2bfb767df1 Mon Sep 17 00:00:00 2001 From: JVT038 <47184046+JVT038@users.noreply.github.com> Date: Fri, 23 Feb 2024 21:47:07 +0100 Subject: [PATCH 1/3] Moved JobController to API endpoints and changed the URLs in the frontend --- bootstrap.php | 2 +- public/js/component/modal-job.js | 2 +- public/js/settings-integration-jellyfin.js | 4 +-- public/js/settings-integration-plex.js | 2 +- settings/routes.php | 31 +++++++++---------- src/Factory.php | 3 +- .../{Web => Api}/JobController.php | 5 +-- .../Middleware/UserHasJellyfinToken.php | 3 +- .../settings-integration-letterboxd.html.twig | 4 +-- .../page/settings-integration-trakt.html.twig | 4 +-- 10 files changed, 27 insertions(+), 33 deletions(-) rename src/HttpController/{Web => Api}/JobController.php (97%) rename src/HttpController/{Web => Api}/Middleware/UserHasJellyfinToken.php (87%) diff --git a/bootstrap.php b/bootstrap.php index 6fb46d622..3f59182ba 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -16,7 +16,7 @@ \Movary\Service\Export\ExportService::class => DI\factory([Factory::class, 'createExportService']), \Movary\HttpController\Api\OpenApiController::class => DI\factory([Factory::class, 'createOpenApiController']), \Movary\HttpController\Web\CreateUserController::class => DI\factory([Factory::class, 'createCreateUserController']), - \Movary\HttpController\Web\JobController::class => DI\factory([Factory::class, 'createJobController']), + \Movary\HttpController\Api\JobController::class => DI\factory([Factory::class, 'createJobController']), \Movary\HttpController\Web\LandingPageController::class => DI\factory([Factory::class, 'createLandingPageController']), \Movary\HttpController\Web\Middleware\ServerHasRegistrationEnabled::class => DI\factory([Factory::class, 'createMiddlewareServerHasRegistrationEnabled']), \Movary\ValueObject\Http\Request::class => DI\factory([Factory::class, 'createCurrentHttpRequest']), diff --git a/public/js/component/modal-job.js b/public/js/component/modal-job.js index 7ff077f4e..d3e48f687 100644 --- a/public/js/component/modal-job.js +++ b/public/js/component/modal-job.js @@ -67,7 +67,7 @@ function setJobModalTitle(jobType) { async function fetchJobs(jobType) { - const response = await fetch('/jobs?type=' + jobType) + const response = await fetch('/api/jobs?type=' + jobType) if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`) diff --git a/public/js/settings-integration-jellyfin.js b/public/js/settings-integration-jellyfin.js index 3acc213b5..f7df541aa 100644 --- a/public/js/settings-integration-jellyfin.js +++ b/public/js/settings-integration-jellyfin.js @@ -266,7 +266,7 @@ async function updateSyncOptions() { async function exportJellyfin() { const response = await fetch( - '/jobs/schedule/jellyfin-export-history', + '/api/jobs/schedule/jellyfin-export-history', {'method': 'get'} ).catch(function (error) { addAlert('alertJellyfinExportHistoryDiv', 'History export could not be scheduled', 'danger') @@ -296,7 +296,7 @@ async function exportJellyfin() { async function importJellyfin() { const response = await fetch( - '/jobs/schedule/jellyfin-import-history', + '/api/jobs/schedule/jellyfin-import-history', {'method': 'get'} ).catch(function (error) { addAlert('alertJellyfinImportHistoryDiv', 'History import could not be scheduled', 'danger') diff --git a/public/js/settings-integration-plex.js b/public/js/settings-integration-plex.js index edc34cc4f..4993b447f 100644 --- a/public/js/settings-integration-plex.js +++ b/public/js/settings-integration-plex.js @@ -226,7 +226,7 @@ document.getElementById('plexServerUrlInput').addEventListener('input', function async function importPlexWatchlist() { const response = await fetch( - '/jobs/schedule/plex-watchlist-sync', + '/api/jobs/schedule/plex-watchlist-sync', {'method': 'get'} ).catch(function (error) { addAlert('alertPlexWatchlistImportDiv', 'Watchlist import could not be scheduled', 'danger') diff --git a/settings/routes.php b/settings/routes.php index 7c49d23d3..9f65c325b 100644 --- a/settings/routes.php +++ b/settings/routes.php @@ -41,23 +41,6 @@ function addWebRoutes(RouterService $routerService, FastRoute\RouteCollector $ro $routes->add('POST', '/jellyfin/{id:.+}', [Web\JellyfinController::class, 'handleJellyfinWebhook']); $routes->add('POST', '/emby/{id:.+}', [Web\EmbyController::class, 'handleEmbyWebhook']); - ############# - # Job Queue # - ############# - $routes->add('GET', '/jobs', [Web\JobController::class, 'getJobs'], [Web\Middleware\UserIsAuthenticated::class]); - $routes->add('GET', '/job-queue/purge-processed', [Web\JobController::class, 'purgeProcessedJobs'], [Web\Middleware\UserIsAuthenticated::class]); - $routes->add('GET', '/job-queue/purge-all', [Web\JobController::class, 'purgeAllJobs'], [Web\Middleware\UserIsAuthenticated::class]); - $routes->add('GET', '/jobs/schedule/trakt-history-sync', [Web\JobController::class, 'scheduleTraktHistorySync'], [Web\Middleware\UserIsAuthenticated::class]); - $routes->add('GET', '/jobs/schedule/trakt-ratings-sync', [Web\JobController::class, 'scheduleTraktRatingsSync'], [Web\Middleware\UserIsAuthenticated::class]); - $routes->add('POST', '/jobs/schedule/letterboxd-diary-sync', [Web\JobController::class, 'scheduleLetterboxdDiaryImport'], [Web\Middleware\UserIsAuthenticated::class]); - $routes->add('POST', '/jobs/schedule/letterboxd-ratings-sync', [Web\JobController::class, 'scheduleLetterboxdRatingsImport'], [Web\Middleware\UserIsAuthenticated::class]); - $routes->add('GET', '/jobs/schedule/plex-watchlist-sync', [Web\JobController::class, 'schedulePlexWatchlistImport'], [Web\Middleware\UserIsAuthenticated::class]); - $routes->add('GET', '/jobs/schedule/jellyfin-import-history', [Web\JobController::class, 'scheduleJellyfinImportHistory'], [Web\Middleware\UserIsAuthenticated::class]); - $routes->add('GET', '/jobs/schedule/jellyfin-export-history', [Web\JobController::class, 'scheduleJellyfinExportHistory'], [ - Web\Middleware\UserIsAuthenticated::class, - Web\Middleware\UserHasJellyfinToken::class - ]); - ############ # Settings # ############ @@ -229,5 +212,19 @@ function addApiRoutes(RouterService $routerService, FastRoute\RouteCollector $ro $routes->add('GET', '/feed/radarr/{id:.+}', [Api\RadarrController::class, 'renderRadarrFeed']); + ############# + # Job Queue # + ############# + $routes->add('GET', '/jobs', [Api\JobController::class, 'getJobs'], [Api\Middleware\IsAuthenticated::class]); + $routes->add('GET', '/job-queue/purge-processed', [Api\JobController::class, 'purgeProcessedJobs'], [Api\Middleware\IsAuthenticated::class]); + $routes->add('GET', '/job-queue/purge-all', [Api\JobController::class, 'purgeAllJobs'], [Api\Middleware\IsAuthenticated::class]); + $routes->add('GET', '/jobs/schedule/trakt-history-sync', [Api\JobController::class, 'scheduleTraktHistorySync'], [Api\Middleware\IsAuthenticated::class]); + $routes->add('GET', '/jobs/schedule/trakt-ratings-sync', [Api\JobController::class, 'scheduleTraktRatingsSync'], [Api\Middleware\IsAuthenticated::class]); + $routes->add('POST', '/jobs/schedule/letterboxd-diary-sync', [Api\JobController::class, 'scheduleLetterboxdDiaryImport'], [Api\Middleware\IsAuthenticated::class]); + $routes->add('POST', '/jobs/schedule/letterboxd-ratings-sync', [Api\JobController::class, 'scheduleLetterboxdRatingsImport'], [Api\Middleware\IsAuthenticated::class]); + $routes->add('GET', '/jobs/schedule/plex-watchlist-sync', [Api\JobController::class, 'schedulePlexWatchlistImport'], [Api\Middleware\IsAuthenticated::class]); + $routes->add('GET', '/jobs/schedule/jellyfin-import-history', [Api\JobController::class, 'scheduleJellyfinImportHistory'], [Api\Middleware\IsAuthenticated::class]); + $routes->add('GET', '/jobs/schedule/jellyfin-export-history', [Api\JobController::class, 'scheduleJellyfinExportHistory'], [Api\Middleware\IsAuthenticated::class, Api\Middleware\UserHasJellyfinToken::class]); + $routerService->addRoutesToRouteCollector($routeCollector, $routes); } diff --git a/src/Factory.php b/src/Factory.php index b59fce2ad..6befef78c 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -13,16 +13,15 @@ use Movary\Api\Trakt\Cache\User\Movie\Watched; use Movary\Api\Trakt\TraktApi; use Movary\Api\Trakt\TraktClient; -use Movary\Command; use Movary\Command\CreatePublicStorageLink; use Movary\Domain\Movie\MovieApi; use Movary\Domain\Movie\Watchlist\MovieWatchlistApi; use Movary\Domain\User; use Movary\Domain\User\Service\Authentication; use Movary\Domain\User\UserApi; +use Movary\HttpController\Api\JobController; use Movary\HttpController\Api\OpenApiController; use Movary\HttpController\Web\CreateUserController; -use Movary\HttpController\Web\JobController; use Movary\HttpController\Web\LandingPageController; use Movary\JobQueue\JobQueueApi; use Movary\JobQueue\JobQueueScheduler; diff --git a/src/HttpController/Web/JobController.php b/src/HttpController/Api/JobController.php similarity index 97% rename from src/HttpController/Web/JobController.php rename to src/HttpController/Api/JobController.php index 9b53d6995..f4f190de0 100644 --- a/src/HttpController/Web/JobController.php +++ b/src/HttpController/Api/JobController.php @@ -1,11 +1,8 @@ -
Upload the diary.csv file
Upload the ratings.csv file
No jobs in queue
{% endif %}