mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
优化download(),成功时返回值第二位是已下载文件的绝对路径
This commit is contained in:
parent
e03a67c3a5
commit
f2ca4fad46
@ -315,6 +315,12 @@ class SessionPage(object):
|
|||||||
:return: 下载是否成功(bool)和状态信息(成功时信息为文件路径)的元组
|
:return: 下载是否成功(bool)和状态信息(成功时信息为文件路径)的元组
|
||||||
"""
|
"""
|
||||||
# 生成的response不写入self._response,是临时的
|
# 生成的response不写入self._response,是临时的
|
||||||
|
if file_exists == 'skip' and Path(f'{goal_path}\\{rename}').exists():
|
||||||
|
if show_msg:
|
||||||
|
print(f'{file_url}\n{goal_path}\\{rename}\nSkipped.\n')
|
||||||
|
|
||||||
|
return False, 'Skipped because a file with the same name already exists.'
|
||||||
|
|
||||||
kwargs['stream'] = True
|
kwargs['stream'] = True
|
||||||
|
|
||||||
if 'timeout' not in kwargs:
|
if 'timeout' not in kwargs:
|
||||||
@ -383,9 +389,8 @@ class SessionPage(object):
|
|||||||
goal_path += goal_Path.drive if key == 0 and goal_Path.drive else re_SUB(r'[*:|<>?"]', '', i).strip()
|
goal_path += goal_Path.drive if key == 0 and goal_Path.drive else re_SUB(r'[*:|<>?"]', '', i).strip()
|
||||||
goal_path += '\\' if i != '\\' and key < len(goal_Path.parts) - 1 else ''
|
goal_path += '\\' if i != '\\' and key < len(goal_Path.parts) - 1 else ''
|
||||||
|
|
||||||
goal_Path = Path(goal_path)
|
goal_Path = Path(goal_path).absolute()
|
||||||
goal_Path.mkdir(parents=True, exist_ok=True)
|
goal_Path.mkdir(parents=True, exist_ok=True)
|
||||||
goal_path = goal_Path.absolute()
|
|
||||||
full_path = Path(f'{goal_path}\\{full_name}')
|
full_path = Path(f'{goal_path}\\{full_name}')
|
||||||
|
|
||||||
if full_path.exists():
|
if full_path.exists():
|
||||||
@ -448,7 +453,7 @@ class SessionPage(object):
|
|||||||
download_status, info = False, 'File size is 0.'
|
download_status, info = False, 'File size is 0.'
|
||||||
|
|
||||||
else:
|
else:
|
||||||
download_status, info = True, 'Success.'
|
download_status, info = True, str(full_path)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
# 删除下载出错文件
|
# 删除下载出错文件
|
||||||
|
Loading…
x
Reference in New Issue
Block a user