Change download api logic

This commit is contained in:
EstrellaXD
2023-05-11 14:11:13 +08:00
parent 0fc00c4c1c
commit dfa4b2772a
5 changed files with 29 additions and 48 deletions

View File

@@ -1,16 +1,24 @@
import logging
from .bangumi import router
from module.conf import settings
from module.models import Config
logger = logging.getLogger(__name__)
@router.get("/api/v1/getConfig", tags=["config"], response_model=Config)
async def get_config():
return settings
# Reverse proxy
@router.post("/api/v1/updateConfig", tags=["config"], response_model=Config)
async def update_config(config: Config):
settings.save(config_dict=config.dict())
return settings
try:
settings.save(config_dict=config.dict())
logger.info("Config updated")
return {"status": "Success"}
except Exception as e:
logger.warning(e)
return {"status": "Failed to update config"}

View File

@@ -1,6 +1,7 @@
from .config import router
from module.models.api import *
from module.models import BangumiData
from module.manager import FullSeasonGet
from module.rss import RSSAnalyser
@@ -9,34 +10,30 @@ def link_process(link):
return RSSAnalyser().rss_to_data(link, full_parse=False)
@router.post("/api/v1/download/collection", tags=["download"])
async def collection(link: RssLink):
@router.post("/api/v1/download/analysis", tags=["download"])
async def analysis(link: RssLink):
data = link_process(link)
if data:
with FullSeasonGet() as season:
season.download_collection(data[0], link)
return data[0]
else:
return {"status": "Failed to parse link"}
@router.post("/api/v1/download/collection", tags=["download"])
async def download_collection(data: BangumiData):
if data:
with FullSeasonGet() as season:
season.download_collection(data, data.rss_link)
return {"status": "Success"}
else:
return {"status": "Failed to parse link"}
@router.post("/api/v1/download/subscribe", tags=["download"])
async def subscribe(link: RssLink):
data = link_process(link)
async def subscribe(data: BangumiData):
if data:
with FullSeasonGet() as season:
season.add_subscribe(data[0], link)
return data[0]
else:
return {"status": "Failed to parse link"}
@router.post("/api/v1/download/manual", tags=["download"])
async def manual(link: RssLink):
data = link_process(link)
if data:
with FullSeasonGet() as season:
season.download_manual(data[0], link)
return data[0]
season.add_subscribe(data)
return {"status": "Success"}
else:
return {"status": "Failed to parse link"}

View File

@@ -1,7 +1,6 @@
import os
import signal
import logging
import asyncio
from .download import router
@@ -55,25 +54,3 @@ async def shutdown_program():
logger.info("Shutting down program...")
os.kill(os.getpid(), signal.SIGINT)
return {"status": "ok"}
@router.get("/api/v1/setLog/{log_level}", tags=["program"])
async def set_log_level(log_level: str):
if log_level == "DEBUG":
logger.setLevel(logging.DEBUG)
logger.debug("Log level set to DEBUG")
elif log_level == "INFO":
logger.setLevel(logging.INFO)
logger.info("Log level set to INFO")
elif log_level == "WARNING":
logger.setLevel(logging.WARNING)
logger.warning("Log level set to WARNING")
elif log_level == "ERROR":
logger.setLevel(logging.ERROR)
logger.error("Log level set to ERROR")
elif log_level == "CRITICAL":
logger.setLevel(logging.CRITICAL)
logger.critical("Log level set to CRITICAL")
else:
return {"status": "invalid log level"}
return {"status": "ok"}

View File

@@ -48,7 +48,6 @@ class Settings(Config):
os.makedirs("config")
with open(CONFIG_PATH, "w", encoding="utf-8") as f:
json.dump(config_dict, f, indent=4)
logger.info(f"Config saved")
def rss_link(self):
if "://" not in self.rss_parser.custom_url:

View File

@@ -93,8 +93,8 @@ class FullSeasonGet(DownloadClient):
self.add_torrent(download)
logger.info("Completed!")
def add_subscribe(self, data: BangumiData, link):
self.add_rss_feed(link, item_path=data.official_title)
def add_subscribe(self, data: BangumiData):
self.add_rss_feed(data.rss_link, item_path=data.official_title)
self.set_rule(data)