fix subscribe api
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from typing import List, Any, Union
|
||||
from typing import List, Any
|
||||
|
||||
from fastapi import APIRouter, Request, BackgroundTasks, Depends, HTTPException, Header
|
||||
from sqlalchemy.orm import Session
|
||||
@@ -35,8 +35,8 @@ async def read_subscribes(
|
||||
return Subscribe.list(db)
|
||||
|
||||
|
||||
@router.get("/{mediaid}", summary="查询订阅", response_model=schemas.Subscribe)
|
||||
async def subscribe_info_by_id(
|
||||
@router.get("/media/{mediaid}", summary="查询订阅", response_model=schemas.Subscribe)
|
||||
async def subscribe_mediaid(
|
||||
mediaid: str,
|
||||
season: int = None,
|
||||
db: Session = Depends(get_db),
|
||||
@@ -54,6 +54,17 @@ async def subscribe_info_by_id(
|
||||
return result if result else Subscribe()
|
||||
|
||||
|
||||
@router.get("/{subscribe_id}", summary="订阅详情", response_model=schemas.Subscribe)
|
||||
async def read_subscribe(
|
||||
subscribe_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||
"""
|
||||
根据订阅编号查询订阅信息
|
||||
"""
|
||||
return Subscribe.get(db, subscribe_id)
|
||||
|
||||
|
||||
@router.post("/", summary="新增订阅", response_model=schemas.Response)
|
||||
async def create_subscribe(
|
||||
*,
|
||||
@@ -73,15 +84,17 @@ async def create_subscribe(
|
||||
title = subscribe_in.name
|
||||
else:
|
||||
title = None
|
||||
result = SubscribeChain().add(mtype=mtype,
|
||||
title=title,
|
||||
year=subscribe_in.year,
|
||||
tmdbid=subscribe_in.tmdbid,
|
||||
season=subscribe_in.season,
|
||||
doubanid=subscribe_in.doubanid,
|
||||
username=current_user.name,
|
||||
exist_ok=True)
|
||||
return schemas.Response(success=True if result else False, message=result)
|
||||
sid, message = SubscribeChain().add(mtype=mtype,
|
||||
title=title,
|
||||
year=subscribe_in.year,
|
||||
tmdbid=subscribe_in.tmdbid,
|
||||
season=subscribe_in.season,
|
||||
doubanid=subscribe_in.doubanid,
|
||||
username=current_user.name,
|
||||
exist_ok=True)
|
||||
return schemas.Response(success=True if sid else False, message=message, data={
|
||||
"id": sid
|
||||
})
|
||||
|
||||
|
||||
@router.put("/", summary="更新订阅", response_model=schemas.Subscribe)
|
||||
|
@@ -311,11 +311,11 @@ async def arr_add_movie(apikey: str, movie: RadarrMovie) -> Any:
|
||||
status_code=403,
|
||||
detail="认证失败!",
|
||||
)
|
||||
sid = SubscribeChain().add(title=movie.title,
|
||||
year=movie.year,
|
||||
mtype=MediaType.MOVIE,
|
||||
tmdbid=movie.tmdbId,
|
||||
userid="Seerr")
|
||||
sid, message = SubscribeChain().add(title=movie.title,
|
||||
year=movie.year,
|
||||
mtype=MediaType.MOVIE,
|
||||
tmdbid=movie.tmdbId,
|
||||
userid="Seerr")
|
||||
if sid:
|
||||
return {
|
||||
"id": sid
|
||||
@@ -323,7 +323,7 @@ async def arr_add_movie(apikey: str, movie: RadarrMovie) -> Any:
|
||||
else:
|
||||
raise HTTPException(
|
||||
status_code=500,
|
||||
detail="添加订阅失败!"
|
||||
detail=f"添加订阅失败:{message}"
|
||||
)
|
||||
|
||||
|
||||
@@ -626,15 +626,16 @@ async def arr_add_series(apikey: str, tv: schemas.SonarrSeries) -> Any:
|
||||
detail="认证失败!",
|
||||
)
|
||||
sid = 0
|
||||
message = ""
|
||||
for season in tv.seasons:
|
||||
if not season.get("monitored"):
|
||||
continue
|
||||
sid = SubscribeChain().add(title=tv.title,
|
||||
year=tv.year,
|
||||
season=season.get("seasonNumber"),
|
||||
tmdbid=tv.tmdbId,
|
||||
mtype=MediaType.TV,
|
||||
userid="Seerr")
|
||||
sid, message = SubscribeChain().add(title=tv.title,
|
||||
year=tv.year,
|
||||
season=season.get("seasonNumber"),
|
||||
tmdbid=tv.tmdbId,
|
||||
mtype=MediaType.TV,
|
||||
userid="Seerr")
|
||||
|
||||
if sid:
|
||||
return {
|
||||
@@ -643,7 +644,7 @@ async def arr_add_series(apikey: str, tv: schemas.SonarrSeries) -> Any:
|
||||
else:
|
||||
raise HTTPException(
|
||||
status_code=500,
|
||||
detail="添加订阅失败!"
|
||||
detail=f"添加订阅失败:{message}"
|
||||
)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user