Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxghp committed Oct 9, 2024
1 parent 084b5c8 commit cadc0b0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 42 deletions.
24 changes: 19 additions & 5 deletions app/api/endpoints/subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,20 +432,34 @@ def subscribe_share(
@router.post("/fork", summary="复用订阅", response_model=schemas.Response)
def subscribe_fork(
sub: schemas.SubscribeShare,
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
current_user: User = Depends(get_current_active_user)) -> Any:
"""
复用订阅
"""
sub_dict = sub.dict()
for key in sub_dict.keys():
if not hasattr(schemas.Subscribe, key):
sub_dict.pop("id")
for key in list(sub_dict.keys()):
if not hasattr(schemas.Subscribe(), key):
sub_dict.pop(key)
result = create_subscribe(subscribe_in=schemas.Subscribe(**sub_dict))
result = create_subscribe(subscribe_in=schemas.Subscribe(**sub_dict),
current_user=current_user)
if result.success:
SubscribeHelper().sub_fork(share_id=sub.share_id)
SubscribeHelper().sub_fork(share_id=sub.id)
return result


@router.get("/shares", summary="查询分享的订阅", response_model=List[schemas.SubscribeShare])
def popular_subscribes(
name: str = None,
page: int = 1,
count: int = 30,
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
"""
查询分享的订阅
"""
return SubscribeHelper().get_shares(name=name, page=page, count=count)


@router.get("/{subscribe_id}", summary="订阅详情", response_model=schemas.Subscribe)
def read_subscribe(
subscribe_id: int,
Expand Down
58 changes: 22 additions & 36 deletions app/helper/subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class SubscribeHelper(metaclass=Singleton):

_sub_share = f"{settings.MP_SERVER_HOST}/subscribe/share"

_sub_shares = f"{settings.MP_SERVER_HOST}/subscribe/shares"

_sub_fork = f"{settings.MP_SERVER_HOST}/subscribe/fork/%s"

def __init__(self):
Expand Down Expand Up @@ -106,21 +108,7 @@ def sub_report(self) -> bool:
timeout=10).post(self._sub_report,
json={
"subscribes": [
{
"name": sub.name,
"year": sub.year,
"type": sub.type,
"tmdbid": sub.tmdbid,
"imdbid": sub.imdbid,
"tvdbid": sub.tvdbid,
"doubanid": sub.doubanid,
"bangumiid": sub.bangumiid,
"season": sub.season,
"poster": sub.poster,
"backdrop": sub.backdrop,
"vote": sub.vote,
"description": sub.description
} for sub in subscribes
sub.to_dict() for sub in subscribes
]
})
return True if res else False
Expand All @@ -135,33 +123,15 @@ def sub_share(self, subscribe_id: int,
subscribe = SubscribeOper().get(subscribe_id)
if not subscribe:
return False, "订阅不存在"
subscribe_dict = subscribe.to_dict()
subscribe_dict.pop("id")
res = RequestUtils(content_type="application/json",
timeout=10).post(self._sub_share,
json={
"share_title": share_title,
"share_comment": share_comment,
"share_user": share_user,
"name": subscribe.name,
"year": subscribe.year,
"type": subscribe.type,
"tmdbid": subscribe.tmdbid,
"imdbid": subscribe.imdbid,
"tvdbid": subscribe.tvdbid,
"doubanid": subscribe.doubanid,
"bangumiid": subscribe.bangumiid,
"season": subscribe.season,
"poster": subscribe.poster,
"backdrop": subscribe.backdrop,
"vote": subscribe.vote,
"description": subscribe.description,
"include": subscribe.include,
"exclude": subscribe.include,
"quality": subscribe.include,
"resolution": subscribe.include,
"effect": subscribe.include,
"total_episode": subscribe.include,
"custom_words": subscribe.include,
"media_category": subscribe.include,
**subscribe_dict
})
if res is None:
return False, "连接MoviePilot服务器失败"
Expand All @@ -185,3 +155,19 @@ def sub_fork(self, share_id: int) -> Tuple[bool, str]:
return True, ""
else:
return False, res.json().get("message")

@cached(cache=TTLCache(maxsize=20, ttl=1800))
def get_shares(self, name: str, page: int = 1, count: int = 30) -> List[dict]:
"""
获取订阅分享数据
"""
if not settings.SUBSCRIBE_STATISTIC_SHARE:
return []
res = RequestUtils(timeout=15).get_res(self._sub_shares, params={
"name": name,
"page": page,
"count": count
})
if res and res.status_code == 200:
return res.json()
return []
2 changes: 1 addition & 1 deletion app/schemas/subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Config:

class SubscribeShare(BaseModel):
# 分享ID
share_id: Optional[int] = None
id: Optional[int] = None
# 订阅ID
subscribe_id: Optional[int] = None
# 分享标题
Expand Down

0 comments on commit cadc0b0

Please sign in to comment.