fix storage api

This commit is contained in:
jxxghp
2024-08-16 11:59:45 +08:00
parent 8485d4ec30
commit af88618fbd
6 changed files with 42 additions and 9 deletions

View File

@@ -15,7 +15,7 @@ from app.utils.http import RequestUtils
class Emby:
def __init__(self, host: str, apikey: str, play_host: str = None, **kwargs):
def __init__(self, host: str = None, apikey: str = None, play_host: str = None, **kwargs):
if not host or not apikey:
logger.error("Emby服务器配置不完整")
return

View File

@@ -65,6 +65,8 @@ class AliPan(StorageBase):
move_file_url = "https://api.aliyundrive.com/v2/file/move"
# 上传文件完成
upload_file_complete_url = "https://api.aliyundrive.com/v2/file/complete"
# 查询存储详情
storage_info_url = "https://api.aliyundrive.com/adrive/v1/user/driveCapacityDetails"
def __handle_error(self, res: Response, apiname: str, action: bool = True):
"""
@@ -749,4 +751,17 @@ class AliPan(StorageBase):
"""
存储使用情况
"""
pass
params = self.__access_params
if not params:
return None
headers = self.__get_headers(params)
res = RequestUtils(headers=headers, timeout=10).post_res(self.storage_info_url, json={})
if res:
result = res.json()
return schemas.StorageUsage(
total=result.get("drive_total_size"),
available=result.get("drive_total_size") - result.get("drive_used_size")
)
else:
self.__handle_error(res, "查询存储详情")
return None

View File

@@ -38,7 +38,7 @@ class Rclone(StorageBase):
path = Path(filepath)
if not path.parent.exists():
path.parent.mkdir(parents=True)
path.write_bytes(conf.get('content'))
path.write_text(conf.get('content'))
@staticmethod
def __get_hidden_shell():
@@ -315,4 +315,21 @@ class Rclone(StorageBase):
"""
存储使用情况
"""
pass
try:
ret = subprocess.run(
[
'rclone', 'about',
'MP:'
],
capture_output=True,
startupinfo=self.__get_hidden_shell()
)
if ret.returncode == 0:
items = json.loads(ret.stdout)
return schemas.StorageUsage(
total=items.get("total"),
available=items.get("free")
)
except Exception as err:
logger.error(f"rclone获取存储使用情况失败{err}")
return None

View File

@@ -56,7 +56,7 @@ class U115Pan(StorageBase, metaclass=Singleton):
cookie_dict = self.get_config()
if not cookie_dict:
return None
return Credential.from_dict(cookie_dict.dict())
return Credential.from_dict(cookie_dict.dict().get("config"))
def __save_credentail(self, credential: Credential):
"""
@@ -381,8 +381,9 @@ class U115Pan(StorageBase, metaclass=Singleton):
"""
存储使用情况
"""
total, used = self.storage()
if total:
info = self.storage()
if info:
total, used = info
return schemas.StorageUsage(
total=total,
available=total - used

View File

@@ -12,7 +12,7 @@ from app.utils.http import RequestUtils
class Jellyfin:
def __init__(self, host: str, apikey: str, play_host: str = None, **kwargs):
def __init__(self, host: str = None, apikey: str = None, play_host: str = None, **kwargs):
if not host or not apikey:
logger.error("Jellyfin服务器配置不完整")
return

View File

@@ -19,7 +19,7 @@ class Plex:
_plex = None
_session = None
def __init__(self, host: str, token: str, play_host: str = None, **kwargs):
def __init__(self, host: str = None, token: str = None, play_host: str = None, **kwargs):
if not host or not token:
logger.error("Plex服务器配置不完整")
return