fix api
This commit is contained in:
@ -546,7 +546,7 @@ class AliyunHelper:
|
||||
self.__handle_error(res, "移动文件")
|
||||
return False
|
||||
|
||||
def upload(self, parent_file_id: str, file_path: Path) -> Optional[dict]:
|
||||
def upload(self, drive_id: str, parent_file_id: str, file_path: Path) -> Optional[schemas.FileItem]:
|
||||
"""
|
||||
上传文件,并标记完成
|
||||
"""
|
||||
@ -555,7 +555,7 @@ class AliyunHelper:
|
||||
return None
|
||||
headers = self.__get_headers(params)
|
||||
res = RequestUtils(headers=headers, timeout=10).post_res(self.create_file_url, json={
|
||||
"drive_id": params.get("resourceDriveId"),
|
||||
"drive_id": drive_id,
|
||||
"parent_file_id": parent_file_id,
|
||||
"name": file_path.name,
|
||||
"type": "file",
|
||||
@ -566,7 +566,6 @@ class AliyunHelper:
|
||||
return None
|
||||
# 获取上传参数
|
||||
result = res.json()
|
||||
drive_id = result.get("drive_id")
|
||||
file_id = result.get("file_id")
|
||||
upload_id = result.get("upload_id")
|
||||
part_info_list = result.get("part_info_list")
|
||||
@ -587,10 +586,15 @@ class AliyunHelper:
|
||||
if not res:
|
||||
self.__handle_error(res, "标记上传状态")
|
||||
return None
|
||||
return {
|
||||
"drive_id": drive_id,
|
||||
"file_id": file_id
|
||||
}
|
||||
result = res.json()
|
||||
return schemas.FileItem(
|
||||
fileid=result.get("file_id"),
|
||||
drive_id=result.get("drive_id"),
|
||||
parent_fileid=result.get("parent_file_id"),
|
||||
type="file",
|
||||
name=result.get("name"),
|
||||
path=f"{file_path.parent}/{result.get('name')}",
|
||||
)
|
||||
else:
|
||||
logger.warn("上传文件失败:无法获取上传地址!")
|
||||
return None
|
||||
|
@ -233,14 +233,14 @@ class U115Helper(metaclass=Singleton):
|
||||
logger.error(f"移动115文件失败:{str(e)}")
|
||||
return False
|
||||
|
||||
def upload(self, parent_file_id: str, file_path: Path) -> Optional[dict]:
|
||||
def upload(self, parent_file_id: str, file_path: Path) -> Optional[schemas.FileItem]:
|
||||
"""
|
||||
上传文件
|
||||
"""
|
||||
if not self.__init_cloud():
|
||||
return None
|
||||
try:
|
||||
ticket = self.cloud.storage().request_upload(dir_id=parent_file_id, file_path=file_path)
|
||||
ticket = self.cloud.storage().request_upload(dir_id=parent_file_id, file_path=str(file_path))
|
||||
if ticket is None:
|
||||
logger.warn(f"115请求上传出错")
|
||||
return None
|
||||
@ -256,13 +256,23 @@ class U115Helper(metaclass=Singleton):
|
||||
)
|
||||
por = bucket.put_object_from_file(
|
||||
key=ticket.object_key,
|
||||
filename=file_path,
|
||||
filename=str(file_path),
|
||||
headers=ticket.headers,
|
||||
)
|
||||
result = por.resp.response.json()
|
||||
if result:
|
||||
logger.info(f"115上传文件成功:{result}")
|
||||
return result
|
||||
fileitem = result.get('data')
|
||||
logger.info(f"115上传文件成功:{fileitem}")
|
||||
return schemas.FileItem(
|
||||
fileid=fileitem.get('file_id'),
|
||||
parent_fileid=parent_file_id,
|
||||
type="file",
|
||||
name=fileitem.get('file_name'),
|
||||
path=f"{file_path / fileitem.get('file_name')}",
|
||||
size=fileitem.get('file_size'),
|
||||
extension=Path(fileitem.get('file_name')).suffix[1:],
|
||||
pickcode=fileitem.get('pickcode')
|
||||
)
|
||||
else:
|
||||
logger.warn(f"115上传文件失败:{por.resp.response.text}")
|
||||
return None
|
||||
|
Reference in New Issue
Block a user