This commit is contained in:
jxxghp 2023-07-11 07:21:48 +08:00
parent bfddd98ae2
commit 8a4a66dec4
7 changed files with 35 additions and 24 deletions

View File

@ -34,7 +34,10 @@ def storage(_: schemas.TokenPayload = Depends(verify_token)) -> Any:
""" """
查询存储空间信息 查询存储空间信息
""" """
if settings.LIBRARY_PATH:
total_storage, free_storage = SystemUtils.space_usage(Path(settings.LIBRARY_PATH)) total_storage, free_storage = SystemUtils.space_usage(Path(settings.LIBRARY_PATH))
else:
total_storage, free_storage = 0, 0
return schemas.Storage( return schemas.Storage(
total_storage=total_storage, total_storage=total_storage,
used_storage=total_storage - free_storage used_storage=total_storage - free_storage
@ -75,6 +78,8 @@ def schedule(_: schemas.TokenPayload = Depends(verify_token)) -> Any:
# 去重 # 去重
added = [] added = []
jobs = Scheduler().list() jobs = Scheduler().list()
# 按照下次运行时间排序
jobs.sort(key=lambda x: x.next_run_time)
for job in jobs: for job in jobs:
if job.name not in added: if job.name not in added:
added.append(job.name) added.append(job.name)

View File

@ -44,8 +44,8 @@ class SearchChain(ChainBase):
return [] return []
results = self.process(mediainfo=mediainfo) results = self.process(mediainfo=mediainfo)
# 保存眲结果 # 保存眲结果
self.systemconfig.set(SystemConfigKey.SearchResults, bytes_results = pickle.dumps(results)
pickle.dumps(results)) self.systemconfig.set(SystemConfigKey.SearchResults, bytes_results)
return results return results
def search_by_title(self, title: str) -> List[TorrentInfo]: def search_by_title(self, title: str) -> List[TorrentInfo]:
@ -206,10 +206,10 @@ class SearchChain(ChainBase):
# 未开启的站点不搜索 # 未开启的站点不搜索
indexer_sites = [] 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(): 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")) state, msg = self.siteshelper.check(indexer.get("domain"))
if not state: if not state:

View File

@ -272,11 +272,11 @@ class SubscribeChain(ChainBase):
# 所有站点索引 # 所有站点索引
indexers = self.siteshelper.get_indexers() 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: 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 continue
logger.info(f'开始刷新站点资源,站点:{indexer.get("name")} ...') logger.info(f'开始刷新站点资源,站点:{indexer.get("name")} ...')
domain = StringUtils.get_url_domain(indexer.get("domain")) domain = StringUtils.get_url_domain(indexer.get("domain"))

View File

@ -55,9 +55,6 @@ class TorrentInfo:
# 种子优先级 # 种子优先级
pri_order: int = 0 pri_order: int = 0
def __getattr__(self, attribute):
return None
def __setattr__(self, name: str, value: Any): def __setattr__(self, name: str, value: Any):
self.__dict__[name] = value self.__dict__[name] = value
@ -175,9 +172,6 @@ class MediaInfo:
if self.douban_info: if self.douban_info:
self.set_douban_info(self.douban_info) self.set_douban_info(self.douban_info)
def __getattr__(self, attribute):
return None
def __setattr__(self, name: str, value: Any): def __setattr__(self, name: str, value: Any):
self.__dict__[name] = value self.__dict__[name] = value
@ -518,9 +512,6 @@ class Context:
# 种子信息 # 种子信息
torrent_info: TorrentInfo = None torrent_info: TorrentInfo = None
def __getattr__(self, attribute):
return None
def __setattr__(self, name: str, value: Any): def __setattr__(self, name: str, value: Any):
self.__dict__[name] = value self.__dict__[name] = value

View File

@ -7,10 +7,18 @@ class ObjectUtils:
@staticmethod @staticmethod
def is_obj(obj: Any): def is_obj(obj: Any):
if isinstance(obj, list) or isinstance(obj, dict): if isinstance(obj, list) \
or isinstance(obj, dict):
return True 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: else:
return str(obj).startswith("{") or str(obj).startswith("[") return str(obj).startswith("{") \
or str(obj).startswith("[")
@staticmethod @staticmethod
def arguments(func: Callable) -> int: def arguments(func: Callable) -> int:

View File

@ -42,11 +42,17 @@ class TimerUtils:
@staticmethod @staticmethod
def time_difference(input_datetime: datetime) -> str: def time_difference(input_datetime: datetime) -> str:
"""
判断输入时间与当前的时间差如果输入时间大于当前时间则返回时间差否则返回空字符串
"""
if not input_datetime: if not input_datetime:
return "" return ""
current_datetime = datetime.datetime.now(datetime.timezone.utc).astimezone() current_datetime = datetime.datetime.now(datetime.timezone.utc).astimezone()
time_difference = input_datetime - current_datetime time_difference = input_datetime - current_datetime
if time_difference.total_seconds() < 0:
return ""
days = time_difference.days days = time_difference.days
hours, remainder = divmod(time_difference.seconds, 3600) hours, remainder = divmod(time_difference.seconds, 3600)
minutes, _ = divmod(remainder, 60) minutes, _ = divmod(remainder, 60)

View File

@ -27,6 +27,7 @@ http {
location / { location / {
# 主目录
expires off; expires off;
add_header Cache-Control "no-cache, no-store, must-revalidate"; add_header Cache-Control "no-cache, no-store, must-revalidate";
root /app/public; root /app/public;
@ -34,6 +35,7 @@ http {
} }
location /assets { location /assets {
# 静态资源
expires 7d; expires 7d;
add_header Cache-Control "public"; add_header Cache-Control "public";
} }
@ -53,13 +55,15 @@ http {
proxy_pass http://backend_api; proxy_pass http://backend_api;
} }
location ~ ^/(api/v1/system/message|api/v1/system/progress/) { location ~ ^/api/v1/system/(message|progress/) {
# SSE MIME类型设置 # SSE MIME类型设置
default_type text/event-stream; default_type text/event-stream;
# 禁用缓存 # 禁用缓存
add_header Cache-Control no-cache; add_header Cache-Control no-cache;
add_header X-Accel-Buffering no; add_header X-Accel-Buffering no;
proxy_buffering off;
proxy_cache off;
# 代理设置 # 代理设置
proxy_pass http://backend_api; proxy_pass http://backend_api;
@ -87,13 +91,10 @@ http {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host; proxy_set_header Host $http_host;
proxy_set_header X-Nginx-Proxy true; proxy_set_header X-Nginx-Proxy true;
}
error_page 500 502 503 504 /50x.html; # 超时设置
location = /50x.html { proxy_read_timeout 600s;
root html;
} }
} }
upstream backend_api { upstream backend_api {