Skip to content

Commit

Permalink
fix #37 #36
Browse files Browse the repository at this point in the history
  • Loading branch information
yaronzz committed Jul 14, 2023
1 parent 32e599d commit cf17066
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 28 deletions.
2 changes: 1 addition & 1 deletion b2a/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
https://github.com/yaronzz/BaiduYunToAliYun
'''
VERSION = '2023.07.04.1'
VERSION = '2023.07.14.1'

aliplat = AliPlat()
bdyplat = BdyPlat()
Expand Down
64 changes: 37 additions & 27 deletions b2a/aliplat.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,33 +110,43 @@ def list(self, remotePath: str, nextMarker: str = None) -> List[FileAttr]:
if not sid:
return []

try:
requests_data = {"drive_id": self.driveId, "parent_file_id": sid, 'marker': nextMarker, 'limit': 100}
requests_post = requests.post('https://api.aliyundrive.com/adrive/v3/file/list',
data=json.dumps(requests_data),
headers=self.headers,
verify=False).json()
ret = []
for item in requests_post['items']:
obj = FileAttr()
obj.isfile = item['type'] != 'folder'
obj.name = item['name']
obj.path = remotePath + '/' + item['name']
obj.uid = item['file_id']
obj.size = item['size'] if 'size' in item else 0
if not obj.isfile:
self.__updatePathId__(obj.path, obj.uid)

ret.append(obj)

next_marker = requests_post.get('next_marker')
if next_marker and nextMarker != requests_post['next_marker']:
ret.extend(self.list(remotePath, next_marker))

return ret
except Exception as e:
printErr("获取目录文件列表失败:" + str(e))
return []
retry = 3
while True:
try:
retry -= 1
requests_data = {"drive_id": self.driveId, "parent_file_id": sid, 'marker': nextMarker, 'limit': 100}
requests_post = requests.post('https://api.aliyundrive.com/adrive/v3/file/list',
data=json.dumps(requests_data),
headers=self.headers,
verify=False).json()
if 'items' not in requests_post:
if retry > 0:
time.sleep(1)
continue
printErr("获取目录文件列表失败:" + requests_post['code'])
return []

ret = []
for item in requests_post['items']:
obj = FileAttr()
obj.isfile = item['type'] != 'folder'
obj.name = item['name']
obj.path = remotePath + '/' + item['name']
obj.uid = item['file_id']
obj.size = item['size'] if 'size' in item else 0
if not obj.isfile:
self.__updatePathId__(obj.path, obj.uid)

ret.append(obj)

next_marker = requests_post.get('next_marker')
if next_marker and nextMarker != requests_post['next_marker']:
ret.extend(self.list(remotePath, next_marker))

return ret
except Exception as e:
printErr("获取目录文件列表失败:" + str(e))
return []

def __mkdir__(self, folderName, parentFolderId='root') -> (bool, str):
folderName = folderName.strip('/')
Expand Down
Binary file modified exe/b2a.exe
Binary file not shown.

0 comments on commit cf17066

Please sign in to comment.