Skip to content

Commit

Permalink
fix 文件链接错误问题
Browse files Browse the repository at this point in the history
  • Loading branch information
lemisky committed Feb 6, 2025
1 parent 8977093 commit fcc7367
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 12 additions & 10 deletions src/aligo/apis/CustomShare.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from typing import List, Dict

from aligo.core import Core
from aligo.request import GetFileListRequest, GetFileRequest, CreateFolderRequest
from aligo.request import CreateFolderRequest
from aligo.request import GetFileRequest, GetFileListRequest, GetDownloadUrlRequest
from aligo.types import BaseFile
from aligo.types.Enum import CheckNameMode

Expand All @@ -14,21 +15,23 @@ class CustomShare(Core):

_ALIGO_SHARE_SCHEMA = 'aligo://'

@staticmethod
def __share_files_by_aligo(files: List[BaseFile]) -> List:
def __share_files_by_aligo(self, files: List[BaseFile]) -> List:
"""..."""
result = []
for file in files:
result.append({
'name': file.name,
'content_hash': file.content_hash,
'size': file.size,
'url': file.download_url or file.url
'url': file.download_url or self._core_get_download_url(GetDownloadUrlRequest(
file_id=file.file_id,
drive_id=file.drive_id,
file_name=file.name,
)).url
})
return result

@staticmethod
def share_file_by_aligo(file: BaseFile) -> str:
def share_file_by_aligo(self, file: BaseFile) -> str:
"""
自定义分享文件
:param file: [BaseFile] 分享文件(BaseFile对象)
Expand All @@ -44,11 +47,10 @@ def share_file_by_aligo(file: BaseFile) -> str:
>>> result = ali.share_file_by_aligo(file)
>>> print(result)
"""
result = CustomShare.__share_files_by_aligo([file])
result = self.__share_files_by_aligo([file])
return CustomShare._ALIGO_SHARE_SCHEMA + base64.b64encode(json.dumps(result).encode()).decode()

@staticmethod
def share_files_by_aligo(files: List[BaseFile]) -> str:
def share_files_by_aligo(self, files: List[BaseFile]) -> str:
"""
自定义分享文件
:param files: [List[BaseFile]] 分享文件列表(BaseFile对象列表)
Expand All @@ -64,7 +66,7 @@ def share_files_by_aligo(files: List[BaseFile]) -> str:
>>> result = ali.share_files_by_aligo(files)
>>> print(result)
"""
result = CustomShare.__share_files_by_aligo(files)
result = self.__share_files_by_aligo(files)
return CustomShare._ALIGO_SHARE_SCHEMA + base64.b64encode(json.dumps(result).encode()).decode()

def __share_folder_by_aligo(self, parent_file_id: str, drive_id: str = None) -> List:
Expand Down
2 changes: 1 addition & 1 deletion src/aligo/core/Download.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def download_files(self, files: List[BaseFile], local_folder: str = '.') -> List
file_path = os.path.join(local_folder, file.name)
file_path = self._core_download_file(
file_path,
file.download_url or file.url or self._core_get_download_url(GetDownloadUrlRequest(
file.download_url or self._core_get_download_url(GetDownloadUrlRequest(
file_id=file.file_id,
drive_id=file.drive_id,
file_name=file.name,
Expand Down

0 comments on commit fcc7367

Please sign in to comment.