diff --git a/src/Controller/TorrentController.php b/src/Controller/TorrentController.php index db4f340..a1ea018 100644 --- a/src/Controller/TorrentController.php +++ b/src/Controller/TorrentController.php @@ -460,6 +460,87 @@ class TorrentController extends AbstractController ]); } + #[Route( + '/{_locale}/rss/torrents', + name: 'rss_torrents_recent', + defaults: [ + '_locale' => '%app.locale%' + ], + requirements: [ + '_locale' => '%app.locales%' + ], + methods: + [ + 'GET' + ] + )] + public function rssRecent( + Request $request, + UserService $userService, + TorrentService $torrentService, + ActivityService $activityService + ): Response + { + // Init user + $user = $this->initUser( + $request, + $userService, + $activityService + ); + + // Get total torrents + $total = $torrentService->findTorrentsTotal( + [], + $user->getLocales(), + !$user->isModerator() && $user->isSensitive() ? false : null, // hide on sensitive mode enabled or show all + !$user->isModerator() ? true : null // show approved content only for regular users + ); + + // Create torrents list + $torrents = []; + foreach ($torrentService->findTorrents( + [], + $user->getLocales(), + !$user->isModerator() && $user->isSensitive() ? false : null, // hide on sensitive mode enabled or show all + !$user->isModerator() ? true : null, // show approved content only for regular users + $this->getParameter('app.pagination'), + 0 + ) as $torrent) + { + // Read file + if (!$file = $torrentService->readTorrentFileByTorrentId($torrent->getId())) + { + throw $this->createNotFoundException(); // @TODO exception + } + + $torrents[] = + [ + 'id' => $torrent->getId(), + 'added' => $torrent->getAdded(), + 'file' => + [ + 'name' => $file->getName(), + ], + 'user' => + [ + 'id' => $torrent->getUserId(), + ], + ]; + } + + $response = new Response(); + $response->headers->set('Content-Type', 'text/xml'); + + return $this->render( + 'default/torrent/list.rss.twig', + [ + 'query' => $request->query->get('query'), + 'torrents' => $torrents + ], + $response + ); + } + // Forms #[Route( '/{_locale}/submit', diff --git a/templates/default/activity/event/undefined.rss.twig b/templates/default/activity/event/undefined.rss.twig index 09bcc56..34ab004 100644 --- a/templates/default/activity/event/undefined.rss.twig +++ b/templates/default/activity/event/undefined.rss.twig @@ -2,6 +2,6 @@