fix: fix bugs, add more api.

This commit is contained in:
EstrellaXD
2023-08-12 17:41:23 +08:00
parent c40723d53c
commit ec97edfe8d
7 changed files with 9 additions and 35 deletions

View File

@@ -2,9 +2,10 @@ import logging
import os
import signal
from fastapi import APIRouter, Depends, HTTPException, status
from fastapi import APIRouter, Depends, HTTPException
from module.core import Program
from module.conf import VERSION
from module.security.api import get_current_user, UNAUTHORIZED
logger = logging.getLogger(__name__)
@@ -82,8 +83,8 @@ async def check_downloader_status(current_user=Depends(get_current_user)):
return program.check_downloader()
@router.get("/check/rss", tags=["check"])
async def check_rss_status(current_user=Depends(get_current_user)):
@router.get("/check/version", tags=["check"])
async def check_version(current_user=Depends(get_current_user)):
if not current_user:
raise UNAUTHORIZED
return program.check_analyser()
return VERSION

View File

@@ -22,13 +22,11 @@ async def get_rss(current_user=Depends(get_current_user)):
@router.post("/add")
async def add_rss(
url: str, name: Optional[str], combine: bool, current_user=Depends(get_current_user)
):
async def add_rss(rss: RSSItem, current_user=Depends(get_current_user)):
if not current_user:
raise UNAUTHORIZED
with RSSEngine() as engine:
result = engine.add_rss(url, name, combine)
result = engine.add_rss(rss.url, rss.item_path, rss.combine)
return u_response(result)

View File

@@ -32,19 +32,6 @@ class Checker:
else:
return False
@staticmethod
def check_torrents() -> bool:
with RequestContent() as req:
try:
torrents = req.get_torrents(settings.rss_link, retry=2)
if torrents:
return True
except AttributeError:
link = f"https://mikanani.me/RSS/MyBangumi?token={settings.rss_parser.token}"
if req.get_torrents(link):
return True
return False
@staticmethod
def check_first_run() -> bool:
if settings.dict() == Config().dict():

View File

@@ -31,12 +31,6 @@ class ProgramStatus(Checker):
self._downloader_status = self.check_downloader()
return self._downloader_status
@property
def torrents_status(self):
if not self._torrents_status:
self._torrents_status = self.check_torrents()
return self._torrents_status
@property
def enable_rss(self):
return self.check_analyser()

View File

@@ -4,7 +4,7 @@ from typing import Optional
class RSSItem(SQLModel, table=True):
id: int = Field(default=None, primary_key=True, alias="id")
item_path: str = Field("example path", alias="item_path")
item_path: Optional[str] = Field(None, alias="item_path")
url: str = Field("https://mikanani.me", alias="url")
combine: bool = Field(True, alias="combine")
parser: str = Field("mikan", alias="parser")

View File

@@ -14,7 +14,7 @@ logger = logging.getLogger(__name__)
class RSSAnalyser(TitleParser):
def official_title_parser(self, bangumi: Bangumi, rss: RSSItem, torrent: Torrent):
if rss.parser == "mikan":
bangumi.official_title, bangumi.poster_link = self.mikan_parser(
bangumi.poster_link, bangumi.official_title = self.mikan_parser(
torrent.homepage
)
elif rss.parser == "tmdb":

View File

@@ -10,12 +10,6 @@ def start_up():
with RSSEngine() as engine:
engine.create_table()
engine.user.add_default_user()
main_rss = engine.rss.search_id(1)
if not main_rss:
engine.add_rss(settings.rss_link, name="Mikan RSS", combine=True)
elif main_rss.url != settings.rss_link:
main_rss.url = settings.rss_link
engine.rss.update(1, main_rss)
def first_run():