refactor: 🚚 move routes to PHP anotations
All checks were successful
repod / xml (push) Successful in 16s
repod / php (push) Successful in 1m7s
repod / nodejs (push) Successful in 1m29s
repod / release (push) Has been skipped

This commit is contained in:
Michel Roux 2024-10-18 15:19:45 +02:00
parent 3232723602
commit 0024507ed5
8 changed files with 55 additions and 72 deletions

View File

@ -29,12 +29,15 @@ You need to have [GPodderSync](https://apps.nextcloud.com/apps/gpoddersync) inst
<screenshot>https://git.crystalyx.net/Xefir/repod/raw/branch/main/screens/modal.png</screenshot> <screenshot>https://git.crystalyx.net/Xefir/repod/raw/branch/main/screens/modal.png</screenshot>
<dependencies> <dependencies>
<php min-version="8.1"/> <php min-version="8.1"/>
<nextcloud min-version="27" max-version="30"/> <nextcloud min-version="29" max-version="30"/>
</dependencies> </dependencies>
<navigations> <navigations>
<navigation> <navigation>
<id>repod</id>
<name>Podcast</name> <name>Podcast</name>
<route>repod.page.index</route> <route>repod.page.index</route>
<icon>app.svg</icon>
<type>link</type>
</navigation> </navigation>
</navigations> </navigations>
</info> </info>

View File

@ -1,27 +0,0 @@
<?php
declare(strict_types=1);
/**
* Create your routes in here. The name is the lowercase name of the controller
* without the controller part, the stuff after the hash is the method.
* e.g. page#index -> OCA\RePod\Controller\PageController->index().
*
* The controller class has to be registered in the application.php file since
* it's instantiated in there
*/
return [
'routes' => [
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
['name' => 'page#feed', 'url' => '/feed/{path}', 'verb' => 'GET', 'requirements' => ['path' => '.+']],
['name' => 'page#discover', 'url' => '/discover', 'verb' => 'GET'],
['name' => 'episodes#action', 'url' => '/episodes/action', 'verb' => 'GET'],
['name' => 'episodes#list', 'url' => '/episodes/list', 'verb' => 'GET'],
['name' => 'opml#export', 'url' => '/opml/export', 'verb' => 'GET'],
['name' => 'opml#import', 'url' => '/opml/import', 'verb' => 'POST'],
['name' => 'podcast#index', 'url' => '/podcast', 'verb' => 'GET'],
['name' => 'search#index', 'url' => '/search', 'verb' => 'GET'],
['name' => 'toplist#hot', 'url' => '/toplist/hot', 'verb' => 'GET'],
['name' => 'toplist#new', 'url' => '/toplist/new', 'verb' => 'GET'],
],
];

View File

@ -11,6 +11,9 @@ use OCA\RePod\Core\EpisodeAction\EpisodeActionReader;
use OCA\RePod\Service\UserService; use OCA\RePod\Service\UserService;
use OCP\AppFramework\Controller; use OCP\AppFramework\Controller;
use OCP\AppFramework\Http; use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\FrontpageRoute;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Http\JSONResponse;
use OCP\Http\Client\IClientService; use OCP\Http\Client\IClientService;
use OCP\IRequest; use OCP\IRequest;
@ -27,10 +30,9 @@ class EpisodesController extends Controller
parent::__construct(Application::APP_ID, $request); parent::__construct(Application::APP_ID, $request);
} }
/** #[NoAdminRequired]
* @NoAdminRequired #[NoCSRFRequired]
* @NoCSRFRequired #[FrontpageRoute(verb: 'GET', url: '/episodes/list')]
*/
public function list(string $url): JSONResponse { public function list(string $url): JSONResponse {
$client = $this->clientService->newClient(); $client = $this->clientService->newClient();
$feed = $client->get($url); $feed = $client->get($url);
@ -41,10 +43,9 @@ class EpisodesController extends Controller
return new JSONResponse($episodes, $feed->getStatusCode()); return new JSONResponse($episodes, $feed->getStatusCode());
} }
/** #[NoAdminRequired]
* @NoAdminRequired #[NoCSRFRequired]
* @NoCSRFRequired #[FrontpageRoute(verb: 'GET', url: '/episodes/action')]
*/
public function action(string $url): JSONResponse { public function action(string $url): JSONResponse {
$action = $this->episodeActionRepository->findByEpisodeUrl($url, $this->userService->getUserUID()); $action = $this->episodeActionRepository->findByEpisodeUrl($url, $this->userService->getUserUID());

View File

@ -10,6 +10,9 @@ use OCA\GPodderSync\Core\SubscriptionChange\SubscriptionChangeSaver;
use OCA\RePod\AppInfo\Application; use OCA\RePod\AppInfo\Application;
use OCA\RePod\Service\UserService; use OCA\RePod\Service\UserService;
use OCP\AppFramework\Controller; use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Attribute\FrontpageRoute;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\DataDownloadResponse; use OCP\AppFramework\Http\DataDownloadResponse;
use OCP\AppFramework\Http\Response; use OCP\AppFramework\Http\Response;
use OCP\IL10N; use OCP\IL10N;
@ -28,10 +31,9 @@ class OpmlController extends Controller
parent::__construct(Application::APP_ID, $request); parent::__construct(Application::APP_ID, $request);
} }
/** #[NoAdminRequired]
* @NoAdminRequired #[NoCSRFRequired]
* @NoCSRFRequired #[FrontpageRoute(verb: 'GET', url: '/opml/export')]
*/
public function export(): DataDownloadResponse { public function export(): DataDownloadResponse {
// https://github.com/AntennaPod/AntennaPod/blob/master/core/src/main/java/de/danoeh/antennapod/core/export/opml/OpmlWriter.java // https://github.com/AntennaPod/AntennaPod/blob/master/core/src/main/java/de/danoeh/antennapod/core/export/opml/OpmlWriter.java
$xml = new \SimpleXMLElement('<opml/>', namespaceOrPrefix: 'http://xmlpull.org/v1/doc/features.html#indent-output'); $xml = new \SimpleXMLElement('<opml/>', namespaceOrPrefix: 'http://xmlpull.org/v1/doc/features.html#indent-output');
@ -82,10 +84,9 @@ class OpmlController extends Controller
return new DataDownloadResponse((string) $xml->asXML(), 'repod-'.$dateCreated->getTimestamp().'.opml', ' application/xml'); return new DataDownloadResponse((string) $xml->asXML(), 'repod-'.$dateCreated->getTimestamp().'.opml', ' application/xml');
} }
/** #[NoAdminRequired]
* @NoAdminRequired #[NoCSRFRequired]
* @NoCSRFRequired #[FrontpageRoute(verb: 'POST', url: '/opml/import')]
*/
public function import(): Response { public function import(): Response {
$file = $this->request->getUploadedFile('import'); $file = $this->request->getUploadedFile('import');

View File

@ -6,6 +6,9 @@ namespace OCA\RePod\Controller;
use OCA\RePod\AppInfo\Application; use OCA\RePod\AppInfo\Application;
use OCP\AppFramework\Controller; use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Attribute\FrontpageRoute;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\ContentSecurityPolicy; use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig; use OCP\IConfig;
@ -21,10 +24,9 @@ class PageController extends Controller
parent::__construct(Application::APP_ID, $request); parent::__construct(Application::APP_ID, $request);
} }
/** #[NoAdminRequired]
* @NoAdminRequired #[NoCSRFRequired]
* @NoCSRFRequired #[FrontpageRoute(verb: 'GET', url: '/')]
*/
public function index(): TemplateResponse { public function index(): TemplateResponse {
Util::addScript(Application::APP_ID, Application::APP_ID.'-main'); Util::addScript(Application::APP_ID, Application::APP_ID.'-main');
Util::addStyle(Application::APP_ID, Application::APP_ID.'-main'); Util::addStyle(Application::APP_ID, Application::APP_ID.'-main');
@ -46,18 +48,16 @@ class PageController extends Controller
return $response; return $response;
} }
/** #[NoAdminRequired]
* @NoAdminRequired #[NoCSRFRequired]
* @NoCSRFRequired #[FrontpageRoute(verb: 'GET', url: '/discover')]
*/
public function discover(): TemplateResponse { public function discover(): TemplateResponse {
return $this->index(); return $this->index();
} }
/** #[NoAdminRequired]
* @NoAdminRequired #[NoCSRFRequired]
* @NoCSRFRequired #[FrontpageRoute(verb: 'GET', url: '/feed/{path}', requirements: ['path' => '.+'])]
*/
public function feed(): TemplateResponse { public function feed(): TemplateResponse {
return $this->index(); return $this->index();
} }

View File

@ -8,6 +8,9 @@ use OCA\GPodderSync\Core\PodcastData\PodcastData;
use OCA\GPodderSync\Core\PodcastData\PodcastDataReader; use OCA\GPodderSync\Core\PodcastData\PodcastDataReader;
use OCA\RePod\AppInfo\Application; use OCA\RePod\AppInfo\Application;
use OCP\AppFramework\Controller; use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Attribute\FrontpageRoute;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Http\JSONResponse;
use OCP\Http\Client\IClientService; use OCP\Http\Client\IClientService;
use OCP\ICacheFactory; use OCP\ICacheFactory;
@ -24,10 +27,9 @@ class PodcastController extends Controller
parent::__construct(Application::APP_ID, $request); parent::__construct(Application::APP_ID, $request);
} }
/** #[NoAdminRequired]
* @NoAdminRequired #[NoCSRFRequired]
* @NoCSRFRequired #[FrontpageRoute(verb: 'GET', url: '/podcast')]
*/
public function index(string $url): JSONResponse { public function index(string $url): JSONResponse {
$podcast = null; $podcast = null;

View File

@ -7,6 +7,9 @@ namespace OCA\RePod\Controller;
use OCA\RePod\AppInfo\Application; use OCA\RePod\AppInfo\Application;
use OCA\RePod\Service\MultiPodService; use OCA\RePod\Service\MultiPodService;
use OCP\AppFramework\Controller; use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Attribute\FrontpageRoute;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest; use OCP\IRequest;
@ -19,10 +22,9 @@ class SearchController extends Controller
parent::__construct(Application::APP_ID, $request); parent::__construct(Application::APP_ID, $request);
} }
/** #[NoAdminRequired]
* @NoAdminRequired #[NoCSRFRequired]
* @NoCSRFRequired #[FrontpageRoute(verb: 'GET', url: '/search')]
*/
public function index(string $q): JSONResponse { public function index(string $q): JSONResponse {
return new JSONResponse($this->multiPodService->search($q)); return new JSONResponse($this->multiPodService->search($q));
} }

View File

@ -7,6 +7,9 @@ namespace OCA\RePod\Controller;
use OCA\RePod\AppInfo\Application; use OCA\RePod\AppInfo\Application;
use OCA\RePod\Service\FyydService; use OCA\RePod\Service\FyydService;
use OCP\AppFramework\Controller; use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Attribute\FrontpageRoute;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest; use OCP\IRequest;
@ -19,18 +22,16 @@ class ToplistController extends Controller
parent::__construct(Application::APP_ID, $request); parent::__construct(Application::APP_ID, $request);
} }
/** #[NoAdminRequired]
* @NoAdminRequired #[NoCSRFRequired]
* @NoCSRFRequired #[FrontpageRoute(verb: 'GET', url: '/toplist/hot')]
*/
public function hot(): JSONResponse { public function hot(): JSONResponse {
return new JSONResponse($this->fyydService->hot()); return new JSONResponse($this->fyydService->hot());
} }
/** #[NoAdminRequired]
* @NoAdminRequired #[NoCSRFRequired]
* @NoCSRFRequired #[FrontpageRoute(verb: 'GET', url: '/toplist/new')]
*/
public function new(): JSONResponse { public function new(): JSONResponse {
return new JSONResponse($this->fyydService->latest()); return new JSONResponse($this->fyydService->latest());
} }