fix storage logging

This commit is contained in:
jxxghp
2025-03-25 08:34:36 +08:00
parent 4be7426ae7
commit e83fe0aabe
5 changed files with 97 additions and 95 deletions

View File

@@ -1,5 +1,4 @@
import json
import logging
from datetime import datetime
from pathlib import Path
from typing import Optional, List, Dict
@@ -102,20 +101,20 @@ class Alist(StorageBase, metaclass=Singleton):
"""
if resp is None:
logger.warning("请求登录失败无法连接alist服务")
logger.warning("【alist】请求登录失败无法连接alist服务")
return ""
if resp.status_code != 200:
logger.warning(f"更新令牌请求发送失败,状态码:{resp.status_code}")
logger.warning(f"【alist】更新令牌请求发送失败,状态码:{resp.status_code}")
return ""
result = resp.json()
if result["code"] != 200:
logger.critical(f'更新令牌,错误信息:{result["message"]}')
logger.critical(f'【alist】更新令牌,错误信息:{result["message"]}')
return ""
logger.debug("AList获取令牌成功")
logger.debug("【alist】AList获取令牌成功")
return result["data"]["token"]
def __get_header_with_token(self) -> dict:
@@ -200,19 +199,19 @@ class Alist(StorageBase, metaclass=Singleton):
"""
if resp is None:
logging.warning(f"请求获取目录 {fileitem.path} 的文件列表失败无法连接alist服务")
logger.warn(f"【alist】请求获取目录 {fileitem.path} 的文件列表失败无法连接alist服务")
return []
if resp.status_code != 200:
logging.warning(
f"请求获取目录 {fileitem.path} 的文件列表失败,状态码:{resp.status_code}"
logger.warn(
f"【alist】请求获取目录 {fileitem.path} 的文件列表失败,状态码:{resp.status_code}"
)
return []
result = resp.json()
if result["code"] != 200:
logging.warning(
f'获取目录 {fileitem.path} 的文件列表失败,错误信息:{result["message"]}'
logger.warn(
f'【alist】获取目录 {fileitem.path} 的文件列表失败,错误信息:{result["message"]}'
)
return []
@@ -258,15 +257,15 @@ class Alist(StorageBase, metaclass=Singleton):
}
"""
if resp is None:
logging.warning(f"请求创建目录 {path} 失败无法连接alist服务")
logger.warn(f"【alist】请求创建目录 {path} 失败无法连接alist服务")
return None
if resp.status_code != 200:
logging.warning(f"请求创建目录 {path} 失败,状态码:{resp.status_code}")
logger.warn(f"【alist】请求创建目录 {path} 失败,状态码:{resp.status_code}")
return None
result = resp.json()
if result["code"] != 200:
logging.warning(f'创建目录 {path} 失败,错误信息:{result["message"]}')
logger.warn(f'【alist】创建目录 {path} 失败,错误信息:{result["message"]}')
return None
return self.get_item(path)
@@ -348,15 +347,15 @@ class Alist(StorageBase, metaclass=Singleton):
}
"""
if resp is None:
logging.warning(f"请求获取文件 {path} 失败无法连接alist服务")
logger.warn(f"【alist】请求获取文件 {path} 失败无法连接alist服务")
return None
if resp.status_code != 200:
logging.warning(f"请求获取文件 {path} 失败,状态码:{resp.status_code}")
logger.warn(f"【alist】请求获取文件 {path} 失败,状态码:{resp.status_code}")
return None
result = resp.json()
if result["code"] != 200:
logging.debug(f'获取文件 {path} 失败,错误信息:{result["message"]}')
logger.debug(f'【alist】获取文件 {path} 失败,错误信息:{result["message"]}')
return None
return schemas.FileItem(
@@ -405,18 +404,18 @@ class Alist(StorageBase, metaclass=Singleton):
}
"""
if resp is None:
logging.warning(f"请求删除文件 {fileitem.path} 失败无法连接alist服务")
logger.warn(f"【alist】请求删除文件 {fileitem.path} 失败无法连接alist服务")
return False
if resp.status_code != 200:
logging.warning(
f"请求删除文件 {fileitem.path} 失败,状态码:{resp.status_code}"
logger.warn(
f"【alist】请求删除文件 {fileitem.path} 失败,状态码:{resp.status_code}"
)
return False
result = resp.json()
if result["code"] != 200:
logging.warning(
f'删除文件 {fileitem.path} 失败,错误信息:{result["message"]}'
logger.warn(
f'【alist】删除文件 {fileitem.path} 失败,错误信息:{result["message"]}'
)
return False
return True
@@ -447,18 +446,18 @@ class Alist(StorageBase, metaclass=Singleton):
}
"""
if not resp:
logging.warning(f"请求重命名文件 {fileitem.path} 失败无法连接alist服务")
logger.warn(f"【alist】请求重命名文件 {fileitem.path} 失败无法连接alist服务")
return False
if resp.status_code != 200:
logging.warning(
f"请求重命名文件 {fileitem.path} 失败,状态码:{resp.status_code}"
logger.warn(
f"【alist】请求重命名文件 {fileitem.path} 失败,状态码:{resp.status_code}"
)
return False
result = resp.json()
if result["code"] != 200:
logging.warning(
f'重命名文件 {fileitem.path} 失败,错误信息:{result["message"]}'
logger.warn(
f'【alist】重命名文件 {fileitem.path} 失败,错误信息:{result["message"]}'
)
return False
@@ -512,15 +511,15 @@ class Alist(StorageBase, metaclass=Singleton):
}
"""
if not resp:
logging.warning(f"请求获取文件 {path} 失败无法连接alist服务")
logger.warn(f"【alist】请求获取文件 {path} 失败无法连接alist服务")
return None
if resp.status_code != 200:
logging.warning(f"请求获取文件 {path} 失败,状态码:{resp.status_code}")
logger.warn(f"【alist】请求获取文件 {path} 失败,状态码:{resp.status_code}")
return None
result = resp.json()
if result["code"] != 200:
logging.warning(f'获取文件 {path} 失败,错误信息:{result["message"]}')
logger.warn(f'【alist】获取文件 {path} 失败,错误信息:{result["message"]}')
return None
if result["data"]["raw_url"]:
@@ -568,7 +567,7 @@ class Alist(StorageBase, metaclass=Singleton):
)
if resp.status_code != 200:
logging.warning(f"请求上传文件 {path} 失败,状态码:{resp.status_code}")
logger.warn(f"【alist】请求上传文件 {path} 失败,状态码:{resp.status_code}")
return None
new_item = self.get_item(Path(fileitem.path) / path.name)
@@ -617,20 +616,20 @@ class Alist(StorageBase, metaclass=Singleton):
}
"""
if resp is None:
logging.warning(
f"请求复制文件 {fileitem.path} 失败无法连接alist服务"
logger.warn(
f"【alist】请求复制文件 {fileitem.path} 失败无法连接alist服务"
)
return False
if resp.status_code != 200:
logging.warning(
f"请求复制文件 {fileitem.path} 失败,状态码:{resp.status_code}"
logger.warn(
f"【alist】请求复制文件 {fileitem.path} 失败,状态码:{resp.status_code}"
)
return False
result = resp.json()
if result["code"] != 200:
logging.warning(
f'复制文件 {fileitem.path} 失败,错误信息:{result["message"]}'
logger.warn(
f'【alist】复制文件 {fileitem.path} 失败,错误信息:{result["message"]}'
)
return False
# 重命名
@@ -676,20 +675,20 @@ class Alist(StorageBase, metaclass=Singleton):
}
"""
if resp is None:
logging.warning(
f"请求移动文件 {fileitem.path} 失败无法连接alist服务"
logger.warn(
f"【alist】请求移动文件 {fileitem.path} 失败无法连接alist服务"
)
return False
if resp.status_code != 200:
logging.warning(
f"请求移动文件 {fileitem.path} 失败,状态码:{resp.status_code}"
logger.warn(
f"【alist】请求移动文件 {fileitem.path} 失败,状态码:{resp.status_code}"
)
return False
result = resp.json()
if result["code"] != 200:
logging.warning(
f'移动文件 {fileitem.path} 失败,错误信息:{result["message"]}'
logger.warn(
f'【alist】移动文件 {fileitem.path} 失败,错误信息:{result["message"]}'
)
return False
return True