Skip to content

Commit

Permalink
feat: add get rss torrents api.
Browse files Browse the repository at this point in the history
  • Loading branch information
EstrellaXD committed Aug 12, 2023
1 parent 560a0fa commit c40723d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
11 changes: 9 additions & 2 deletions backend/src/module/api/rss.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Optional

from fastapi import APIRouter, Depends, status
from fastapi.responses import JSONResponse
from fastapi import APIRouter, Depends

from .response import u_response

Expand Down Expand Up @@ -65,3 +64,11 @@ async def refresh_rss(rss_id: int, current_user=Depends(get_current_user)):
raise UNAUTHORIZED
with RSSEngine() as engine, DownloadClient() as client:
response = engine.refresh_rss(client, rss_id)


@router.get("/torrent/{rss_id}")
async def get_torrent(rss_id: int, current_user=Depends(get_current_user)):
if not current_user:
raise UNAUTHORIZED
with RSSEngine() as engine:
return engine.get_rss_torrents(rss_id)
3 changes: 3 additions & 0 deletions backend/src/module/database/torrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def search(self, _id: int) -> Torrent:
def search_all(self) -> list[Torrent]:
return self.session.exec(select(Torrent)).all()

def search_rss(self, rss_id: int) -> list[Torrent]:
return self.session.exec(select(Torrent).where(Torrent.rss_id == rss_id)).all()

def check_new(self, torrents_list: list[Torrent]) -> list[Torrent]:
new_torrents = []
old_torrents = self.search_all()
Expand Down
7 changes: 7 additions & 0 deletions backend/src/module/rss/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ def _get_torrents(rss: RSSItem) -> list[Torrent]:
def get_combine_rss(self) -> list[RSSItem]:
return self.rss.get_combine()

def get_rss_torrents(self, rss_id: int) -> list[Torrent]:
rss = self.rss.search_id(rss_id)
if rss:
return self.torrent.search_rss(rss_id)
else:
return []

def add_rss(self, rss_link: str, name: str | None = None, combine: bool = True):
if not name:
with RequestContent() as req:
Expand Down

0 comments on commit c40723d

Please sign in to comment.