From 8a4a66dec4e21f48cdee56a62dcd426810754a6c Mon Sep 17 00:00:00 2001 From: jxxghp Date: Tue, 11 Jul 2023 07:21:48 +0800 Subject: [PATCH] fix bugs --- app/api/endpoints/dashboard.py | 7 ++++++- app/chain/search.py | 8 ++++---- app/chain/subscribe.py | 4 ++-- app/core/context.py | 9 --------- app/utils/object.py | 12 ++++++++++-- app/utils/timer.py | 6 ++++++ nginx.conf | 13 +++++++------ 7 files changed, 35 insertions(+), 24 deletions(-) diff --git a/app/api/endpoints/dashboard.py b/app/api/endpoints/dashboard.py index 262a6f3c..9634daf5 100644 --- a/app/api/endpoints/dashboard.py +++ b/app/api/endpoints/dashboard.py @@ -34,7 +34,10 @@ def storage(_: schemas.TokenPayload = Depends(verify_token)) -> Any: """ 查询存储空间信息 """ - total_storage, free_storage = SystemUtils.space_usage(Path(settings.LIBRARY_PATH)) + if settings.LIBRARY_PATH: + total_storage, free_storage = SystemUtils.space_usage(Path(settings.LIBRARY_PATH)) + else: + total_storage, free_storage = 0, 0 return schemas.Storage( total_storage=total_storage, used_storage=total_storage - free_storage @@ -75,6 +78,8 @@ def schedule(_: schemas.TokenPayload = Depends(verify_token)) -> Any: # 去重 added = [] jobs = Scheduler().list() + # 按照下次运行时间排序 + jobs.sort(key=lambda x: x.next_run_time) for job in jobs: if job.name not in added: added.append(job.name) diff --git a/app/chain/search.py b/app/chain/search.py index 6f6cc295..0da19cbf 100644 --- a/app/chain/search.py +++ b/app/chain/search.py @@ -44,8 +44,8 @@ class SearchChain(ChainBase): return [] results = self.process(mediainfo=mediainfo) # 保存眲结果 - self.systemconfig.set(SystemConfigKey.SearchResults, - pickle.dumps(results)) + bytes_results = pickle.dumps(results) + self.systemconfig.set(SystemConfigKey.SearchResults, bytes_results) return results def search_by_title(self, title: str) -> List[TorrentInfo]: @@ -206,10 +206,10 @@ class SearchChain(ChainBase): # 未开启的站点不搜索 indexer_sites = [] # 配置的索引站点 - config_indexers = self.systemconfig.get(SystemConfigKey.IndexerSites) or [] + config_indexers = [str(sid) for sid in self.systemconfig.get(SystemConfigKey.IndexerSites) or []] for indexer in self.siteshelper.get_indexers(): # 检查站点索引开关 - if not config_indexers or indexer.get("id") in config_indexers: + if not config_indexers or str(indexer.get("id")) in config_indexers: # 站点流控 state, msg = self.siteshelper.check(indexer.get("domain")) if not state: diff --git a/app/chain/subscribe.py b/app/chain/subscribe.py index 272aebbc..f2d82f0a 100644 --- a/app/chain/subscribe.py +++ b/app/chain/subscribe.py @@ -272,11 +272,11 @@ class SubscribeChain(ChainBase): # 所有站点索引 indexers = self.siteshelper.get_indexers() # 配置的索引站点 - config_indexers = self.systemconfig.get(SystemConfigKey.IndexerSites) or [] + config_indexers = [str(sid) for sid in self.systemconfig.get(SystemConfigKey.IndexerSites) or []] # 遍历站点缓存资源 for indexer in indexers: # 未开启的站点不搜索 - if config_indexers and indexer.get("id") not in config_indexers: + if config_indexers and str(indexer.get("id")) not in config_indexers: continue logger.info(f'开始刷新站点资源,站点:{indexer.get("name")} ...') domain = StringUtils.get_url_domain(indexer.get("domain")) diff --git a/app/core/context.py b/app/core/context.py index bcb499b2..0c740f2d 100644 --- a/app/core/context.py +++ b/app/core/context.py @@ -55,9 +55,6 @@ class TorrentInfo: # 种子优先级 pri_order: int = 0 - def __getattr__(self, attribute): - return None - def __setattr__(self, name: str, value: Any): self.__dict__[name] = value @@ -175,9 +172,6 @@ class MediaInfo: if self.douban_info: self.set_douban_info(self.douban_info) - def __getattr__(self, attribute): - return None - def __setattr__(self, name: str, value: Any): self.__dict__[name] = value @@ -518,9 +512,6 @@ class Context: # 种子信息 torrent_info: TorrentInfo = None - def __getattr__(self, attribute): - return None - def __setattr__(self, name: str, value: Any): self.__dict__[name] = value diff --git a/app/utils/object.py b/app/utils/object.py index 15910c86..944e51f9 100644 --- a/app/utils/object.py +++ b/app/utils/object.py @@ -7,10 +7,18 @@ class ObjectUtils: @staticmethod def is_obj(obj: Any): - if isinstance(obj, list) or isinstance(obj, dict): + if isinstance(obj, list) \ + or isinstance(obj, dict): return True + elif isinstance(obj, str) \ + or isinstance(obj, int) \ + or isinstance(obj, float) \ + or isinstance(obj, bool) \ + or isinstance(obj, bytes): + return False else: - return str(obj).startswith("{") or str(obj).startswith("[") + return str(obj).startswith("{") \ + or str(obj).startswith("[") @staticmethod def arguments(func: Callable) -> int: diff --git a/app/utils/timer.py b/app/utils/timer.py index acea9390..f7018b4a 100644 --- a/app/utils/timer.py +++ b/app/utils/timer.py @@ -42,11 +42,17 @@ class TimerUtils: @staticmethod def time_difference(input_datetime: datetime) -> str: + """ + 判断输入时间与当前的时间差,如果输入时间大于当前时间则返回时间差,否则返回空字符串 + """ if not input_datetime: return "" current_datetime = datetime.datetime.now(datetime.timezone.utc).astimezone() time_difference = input_datetime - current_datetime + if time_difference.total_seconds() < 0: + return "" + days = time_difference.days hours, remainder = divmod(time_difference.seconds, 3600) minutes, _ = divmod(remainder, 60) diff --git a/nginx.conf b/nginx.conf index e13e2a33..d1e0b22d 100644 --- a/nginx.conf +++ b/nginx.conf @@ -27,6 +27,7 @@ http { location / { + # 主目录 expires off; add_header Cache-Control "no-cache, no-store, must-revalidate"; root /app/public; @@ -34,6 +35,7 @@ http { } location /assets { + # 静态资源 expires 7d; add_header Cache-Control "public"; } @@ -53,13 +55,15 @@ http { proxy_pass http://backend_api; } - location ~ ^/(api/v1/system/message|api/v1/system/progress/) { + location ~ ^/api/v1/system/(message|progress/) { # SSE MIME类型设置 default_type text/event-stream; # 禁用缓存 add_header Cache-Control no-cache; add_header X-Accel-Buffering no; + proxy_buffering off; + proxy_cache off; # 代理设置 proxy_pass http://backend_api; @@ -87,13 +91,10 @@ http { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-Nginx-Proxy true; - } - error_page 500 502 503 504 /50x.html; - location = /50x.html { - root html; + # 超时设置 + proxy_read_timeout 600s; } - } upstream backend_api {