This commit is contained in:
jxxghp
2025-03-24 22:57:16 +08:00
parent 0ce5ef7f56
commit 4be7426ae7
+14 -9
View File
@@ -82,9 +82,9 @@ class U115Pan(StorageBase, metaclass=Singleton):
""" """
# 生成PKCE参数 # 生成PKCE参数
code_verifier = secrets.token_urlsafe(96)[:128] code_verifier = secrets.token_urlsafe(96)[:128]
code_challenge = base64.urlsafe_b64encode( code_challenge = base64.b64encode(
hashlib.sha256(code_verifier.encode()).digest() hashlib.sha256(code_verifier.encode("utf-8")).digest()
).decode() ).decode("utf-8")
# 请求设备码 # 请求设备码
resp = self.session.post( resp = self.session.post(
"https://passportapi.115.com/open/authDeviceCode", "https://passportapi.115.com/open/authDeviceCode",
@@ -159,7 +159,7 @@ class U115Pan(StorageBase, metaclass=Singleton):
**kwargs **kwargs
) )
if resp is None: if resp is None:
logger.warn(f"请求 115 API 失败: {method} {endpoint}") logger.warn(f"{method} 请求 {endpoint} 失败!")
return None return None
# 处理速率限制 # 处理速率限制
@@ -194,7 +194,7 @@ class U115Pan(StorageBase, metaclass=Singleton):
if result_key: if result_key:
result = ret_data.get(result_key) result = ret_data.get(result_key)
if result is None: if result is None:
raise FileNotFoundError(f"请求 115 API {method} {endpoint} 失败{ret_data.get('message')}") logger.warn(f"{method} 请求 {endpoint} 出错{ret_data.get('message')}")
return result return result
return ret_data return ret_data
@@ -382,6 +382,8 @@ class U115Pan(StorageBase, metaclass=Singleton):
"file_name": name "file_name": name
} }
) )
if not resp:
return None
if not resp.get("state"): if not resp.get("state"):
if resp.get("code") == 20004: if resp.get("code") == 20004:
# 目录已存在 # 目录已存在
@@ -430,7 +432,6 @@ class U115Pan(StorageBase, metaclass=Singleton):
) )
if not init_resp: if not init_resp:
logger.warn("初始化上传失败")
return None return None
if not init_resp.get("state"): if not init_resp.get("state"):
logger.warn(f"初始化上传失败: {init_resp.get('error')}") logger.warn(f"初始化上传失败: {init_resp.get('error')}")
@@ -504,8 +505,8 @@ class U115Pan(StorageBase, metaclass=Singleton):
).decode('utf-8') ).decode('utf-8')
} }
upload_id = bucket.init_multipart_upload(target_name, headers=headers).upload_id upload_id = bucket.init_multipart_upload(target_name, headers=headers).upload_id
parts = []
# 每10M分一片 # 每10M分一片
parts = []
chunk_size = 10 * 1024 * 1024 chunk_size = 10 * 1024 * 1024
chunk_num = (file_size + chunk_size - 1) // chunk_size chunk_num = (file_size + chunk_size - 1) // chunk_size
with open(local_path, 'rb') as f: with open(local_path, 'rb') as f:
@@ -588,6 +589,8 @@ class U115Pan(StorageBase, metaclass=Singleton):
"file_name": name "file_name": name
} }
) )
if not resp:
return False
if resp["state"]: if resp["state"]:
if fileitem.path in self._id_cache: if fileitem.path in self._id_cache:
del self._id_cache[fileitem.path] del self._id_cache[fileitem.path]
@@ -688,7 +691,8 @@ class U115Pan(StorageBase, metaclass=Singleton):
"pid": dest_cid "pid": dest_cid
} }
) )
if not resp:
return False
if resp["state"]: if resp["state"]:
new_path = Path(path) / fileitem.name new_path = Path(path) / fileitem.name
new_file = self.get_item(new_path) new_file = self.get_item(new_path)
@@ -715,7 +719,8 @@ class U115Pan(StorageBase, metaclass=Singleton):
"to_cid": dest_cid "to_cid": dest_cid
} }
) )
if not resp:
return False
if resp["state"]: if resp["state"]:
new_path = Path(path) / fileitem.name new_path = Path(path) / fileitem.name
new_file = self.get_item(new_path) new_file = self.get_item(new_path)