From bd348f118c30aae0e99dc8ee551101751ba9ff3a Mon Sep 17 00:00:00 2001 From: jxxghp Date: Tue, 7 May 2024 16:01:52 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E8=AE=A2=E9=98=85=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/endpoints/subscribe.py | 9 ++++++++- app/chain/subscribe.py | 10 ++++++++++ app/helper/subscribe.py | 23 +++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/app/api/endpoints/subscribe.py b/app/api/endpoints/subscribe.py index 048da201..eec64844 100644 --- a/app/api/endpoints/subscribe.py +++ b/app/api/endpoints/subscribe.py @@ -407,5 +407,12 @@ def delete_subscribe( """ 删除订阅信息 """ - Subscribe.delete(db, subscribe_id) + subscribe = Subscribe.get(db, subscribe_id) + if subscribe: + subscribe.delete(db, subscribe_id) + # 统计订阅 + SubscribeHelper().sub_done_async({ + "tmdbid": subscribe.tmdbid, + "doubanid": subscribe.doubanid + }) return schemas.Response(success=True) diff --git a/app/chain/subscribe.py b/app/chain/subscribe.py index db19e9e0..d19cd563 100644 --- a/app/chain/subscribe.py +++ b/app/chain/subscribe.py @@ -871,6 +871,11 @@ class SubscribeChain(ChainBase): "subscribe_info": subscribe.to_dict(), "mediainfo": mediainfo.to_dict(), }) + # 统计订阅 + self.subscribehelper.sub_done_async({ + "tmdbid": mediainfo.tmdb_id, + "doubanid": mediainfo.douban_id + }) def remote_list(self, channel: MessageChannel, userid: Union[str, int] = None): """ @@ -920,6 +925,11 @@ class SubscribeChain(ChainBase): return # 删除订阅 self.subscribeoper.delete(subscribe_id) + # 统计订阅 + self.subscribehelper.sub_done_async({ + "tmdbid": subscribe.tmdbid, + "doubanid": subscribe.doubanid + }) # 重新发送消息 self.remote_list(channel, userid) diff --git a/app/helper/subscribe.py b/app/helper/subscribe.py index abe4875e..87995221 100644 --- a/app/helper/subscribe.py +++ b/app/helper/subscribe.py @@ -18,6 +18,8 @@ class SubscribeHelper(metaclass=Singleton): _sub_reg = "https://movie-pilot.org/subscribe/add" + _sub_done = "https://movie-pilot.org/subscribe/done" + _sub_report = "https://movie-pilot.org/subscribe/report" _sub_statistic = "https://movie-pilot.org/subscribe/statistic" @@ -58,6 +60,19 @@ class SubscribeHelper(metaclass=Singleton): return True return False + def sub_done(self, sub: dict) -> bool: + """ + 完成订阅统计 + """ + if not settings.SUBSCRIBE_STATISTIC_SHARE: + return False + res = RequestUtils(timeout=5, headers={ + "Content-Type": "application/json" + }).post_res(self._sub_done, json=sub) + if res and res.status_code == 200: + return True + return False + def sub_reg_async(self, sub: dict) -> bool: """ 异步新增订阅统计 @@ -66,6 +81,14 @@ class SubscribeHelper(metaclass=Singleton): Thread(target=self.sub_reg, args=(sub,)).start() return True + def sub_done_async(self, sub: dict) -> bool: + """ + 异步完成订阅统计 + """ + # 开新线程处理 + Thread(target=self.sub_done, args=(sub,)).start() + return True + def sub_report(self) -> bool: """ 上报存量订阅统计