diff --git a/app/modules/emby/emby.py b/app/modules/emby/emby.py index fc8500c1..e7b52a62 100644 --- a/app/modules/emby/emby.py +++ b/app/modules/emby/emby.py @@ -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 diff --git a/app/modules/filemanager/storages/alipan.py b/app/modules/filemanager/storages/alipan.py index e5be38a6..da8a6942 100644 --- a/app/modules/filemanager/storages/alipan.py +++ b/app/modules/filemanager/storages/alipan.py @@ -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 diff --git a/app/modules/filemanager/storages/rclone.py b/app/modules/filemanager/storages/rclone.py index 8ad3a209..3e7ba305 100644 --- a/app/modules/filemanager/storages/rclone.py +++ b/app/modules/filemanager/storages/rclone.py @@ -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 diff --git a/app/modules/filemanager/storages/u115.py b/app/modules/filemanager/storages/u115.py index 8c623185..1a8fa692 100644 --- a/app/modules/filemanager/storages/u115.py +++ b/app/modules/filemanager/storages/u115.py @@ -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 diff --git a/app/modules/jellyfin/jellyfin.py b/app/modules/jellyfin/jellyfin.py index d97d4ff3..2c530e35 100644 --- a/app/modules/jellyfin/jellyfin.py +++ b/app/modules/jellyfin/jellyfin.py @@ -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 diff --git a/app/modules/plex/plex.py b/app/modules/plex/plex.py index 9bcbc41b..3a4c16a4 100644 --- a/app/modules/plex/plex.py +++ b/app/modules/plex/plex.py @@ -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