Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxghp committed Jul 10, 2023
1 parent bfddd98 commit 8a4a66d
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 24 deletions.
7 changes: 6 additions & 1 deletion app/api/endpoints/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions app/chain/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def search_by_tmdbid(self, tmdbid: int, mtype: MediaType = None) -> List[Context
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]:
Expand Down Expand Up @@ -206,10 +206,10 @@ def __search_all_sites(self, mediainfo: Optional[MediaInfo] = None,
# 未开启的站点不搜索
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:
Expand Down
4 changes: 2 additions & 2 deletions app/chain/subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,11 @@ def refresh(self):
# 所有站点索引
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"))
Expand Down
9 changes: 0 additions & 9 deletions app/core/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -175,9 +172,6 @@ def __post_init__(self):
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

Expand Down Expand Up @@ -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

Expand Down
12 changes: 10 additions & 2 deletions app/utils/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions app/utils/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,17 @@ def random_scheduler(num_executions: int = 1,

@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)
Expand Down
13 changes: 7 additions & 6 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ http {


location / {
# 主目录
expires off;
add_header Cache-Control "no-cache, no-store, must-revalidate";
root /app/public;
index index.html;
}

location /assets {
# 静态资源
expires 7d;
add_header Cache-Control "public";
}
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 8a4a66d

Please sign in to comment.