This commit is contained in:
jxxghp
2023-06-17 17:34:18 +08:00
parent f85e960fa9
commit acdec220f7
42 changed files with 423 additions and 253 deletions

View File

@ -1,7 +1,9 @@
from typing import Any
from fastapi import APIRouter, Depends, BackgroundTasks
from app import schemas
from app.chain.douban_sync import DoubanSyncChain
from app.chain.douban import DoubanChain
from app.db.models.user import User
from app.db.userauth import get_current_active_superuser
@ -12,15 +14,15 @@ def start_douban_chain():
"""
启动链式任务
"""
DoubanSyncChain().process()
DoubanChain().sync()
@router.get("/sync", response_model=schemas.Response)
async def sync_douban(
background_tasks: BackgroundTasks,
_: User = Depends(get_current_active_superuser)):
_: User = Depends(get_current_active_superuser)) -> Any:
"""
查询所有订阅
同步豆瓣想看
"""
background_tasks.add_task(start_douban_chain)
return {"success": True}

View File

@ -1,20 +1,59 @@
from typing import List, Any
from fastapi import APIRouter, Depends
from app import schemas
from app.chain.identify import IdentifyChain
from app.chain.media import MediaChain
from app.core.context import MediaInfo
from app.db.models.user import User
from app.db.userauth import get_current_active_user
from app.schemas.types import MediaType
router = APIRouter()
@router.post("/recognize", response_model=schemas.Context)
@router.get("/recognize", response_model=schemas.Context)
async def recognize(title: str,
subtitle: str = None,
_: User = Depends(get_current_active_user)):
_: User = Depends(get_current_active_user)) -> Any:
"""
识别媒体信息
"""
# 识别媒体信息
context = IdentifyChain().process(title=title, subtitle=subtitle)
context = MediaChain().recognize_by_title(title=title, subtitle=subtitle)
return context.to_dict()
@router.get("/tmdb", response_model=schemas.MediaInfo)
async def tmdb_info(tmdbid: int, type_name: str) -> Any:
"""
根据TMDBID查询媒体信息
"""
mtype = MediaType.MOVIE if type_name == MediaType.MOVIE.value else MediaType.TV
media = MediaChain().recognize_media(tmdbid=tmdbid, mtype=mtype)
if media:
return media.to_dict()
else:
return schemas.MediaInfo()
@router.get("/douban", response_model=schemas.MediaInfo)
async def douban_info(doubanid: str) -> Any:
"""
根据豆瓣ID查询豆瓣媒体信息
"""
doubaninfo = MediaChain().douban_info(doubanid=doubanid)
if doubaninfo:
return MediaInfo(douban_info=doubaninfo).to_dict()
else:
return schemas.MediaInfo()
@router.get("/search", response_model=List[schemas.MediaInfo])
async def search_by_title(title: str,
_: User = Depends(get_current_active_user)) -> Any:
"""
搜索媒体信息
"""
_, medias = MediaChain().search(title=title)
return [media.to_dict() for media in medias]

View File

@ -5,7 +5,7 @@ from fastapi import Request
from starlette.responses import PlainTextResponse
from app import schemas
from app.chain.user_message import UserMessageChain
from app.chain.message import MessageChain
from app.core.config import settings
from app.log import logger
from app.modules.wechat.WXBizMsgCrypt3 import WXBizMsgCrypt
@ -17,7 +17,7 @@ def start_message_chain(body: Any, form: Any, args: Any):
"""
启动链式任务
"""
UserMessageChain().process(body=body, form=form, args=args)
MessageChain().process(body=body, form=form, args=args)
@router.post("/", response_model=schemas.Response)
@ -33,7 +33,8 @@ async def user_message(background_tasks: BackgroundTasks, request: Request):
@router.get("/")
async def wechat_verify(echostr: str, msg_signature: str, timestamp: Union[str, int], nonce: str):
async def wechat_verify(echostr: str, msg_signature: str,
timestamp: Union[str, int], nonce: str) -> Any:
"""
用户消息响应
"""

View File

@ -0,0 +1,24 @@
from typing import List, Any
from fastapi import APIRouter, Depends
from app import schemas
from app.chain.search import SearchChain
from app.db.models.user import User
from app.db.userauth import get_current_active_user
from app.schemas.types import MediaType
router = APIRouter()
@router.get("/tmdbid", response_model=List[schemas.Context])
async def search_by_tmdbid(tmdbid: int,
mtype: str = None,
_: User = Depends(get_current_active_user)) -> Any:
"""
根据TMDBID搜索资源
"""
if mtype:
mtype = MediaType.TV if mtype == MediaType.TV.value else MediaType.MOVIE
torrents = SearchChain().search_by_tmdbid(tmdbid=tmdbid, mtype=mtype)
return [torrent.to_dict() for torrent in torrents]

View File

@ -43,7 +43,7 @@ async def update_site(
@router.get("/cookiecloud", response_model=schemas.Response)
async def cookie_cloud_sync(_: User = Depends(get_current_active_user)) -> dict:
async def cookie_cloud_sync(_: User = Depends(get_current_active_user)) -> Any:
"""
运行CookieCloud同步站点信息
"""

View File

@ -20,14 +20,14 @@ def start_subscribe_chain(title: str, year: str,
"""
启动订阅链式任务
"""
SubscribeChain().process(title=title, year=year,
mtype=mtype, tmdbid=tmdbid, season=season, username=username)
SubscribeChain().add(title=title, year=year,
mtype=mtype, tmdbid=tmdbid, season=season, username=username)
@router.get("/", response_model=List[schemas.Subscribe])
async def read_subscribes(
db: Session = Depends(get_db),
_: User = Depends(get_current_active_superuser)):
_: User = Depends(get_current_active_superuser)) -> Any:
"""
查询所有订阅
"""
@ -43,7 +43,7 @@ async def create_subscribe(
"""
新增订阅
"""
result = SubscribeChain().process(**subscribe_in.dict())
result = SubscribeChain().add(**subscribe_in.dict())
return {"success": result}
@ -83,7 +83,7 @@ async def delete_subscribe(
@router.post("/seerr", response_model=schemas.Response)
async def seerr_subscribe(request: Request, background_tasks: BackgroundTasks,
authorization: str = Header(None)):
authorization: str = Header(None)) -> Any:
"""
Jellyseerr/Overseerr订阅
"""
@ -136,7 +136,7 @@ async def seerr_subscribe(request: Request, background_tasks: BackgroundTasks,
@router.get("/refresh", response_model=schemas.Response)
async def refresh_subscribes(
_: User = Depends(get_current_active_superuser)):
_: User = Depends(get_current_active_superuser)) -> Any:
"""
刷新所有订阅
"""
@ -146,7 +146,7 @@ async def refresh_subscribes(
@router.get("/search", response_model=schemas.Response)
async def search_subscribes(
_: User = Depends(get_current_active_superuser)):
_: User = Depends(get_current_active_superuser)) -> Any:
"""
搜索所有订阅
"""

View File

@ -3,7 +3,7 @@ from typing import Any
from fastapi import APIRouter, BackgroundTasks, Request
from app import schemas
from app.chain.webhook_message import WebhookMessageChain
from app.chain.webhook import WebhookChain
from app.core.config import settings
router = APIRouter()
@ -13,11 +13,12 @@ def start_webhook_chain(body: Any, form: Any, args: Any):
"""
启动链式任务
"""
WebhookMessageChain().process(body=body, form=form, args=args)
WebhookChain().message(body=body, form=form, args=args)
@router.post("/", response_model=schemas.Response)
async def webhook_message(background_tasks: BackgroundTasks, token: str, request: Request):
async def webhook_message(background_tasks: BackgroundTasks,
token: str, request: Request) -> Any:
"""
Webhook响应
"""