MCPcopy
hub / github.com/AstrBotDevs/AstrBot / get_file

Method get_file

astrbot/core/message/components.py:824–853  ·  view source on GitHub ↗

异步获取文件。请注意在使用后清理下载的文件, 以免占用过多空间 Args: allow_return_url: 是否允许以文件 http 下载链接的形式返回,这允许您自行控制是否需要下载文件。 注意,如果为 True,也可能返回文件路径。 Returns: str: 文件路径或者 http 下载链接

(self, allow_return_url: bool = False)

Source from the content-addressed store, hash-verified

822 self.file_ = value
823
824 async def get_file(self, allow_return_url: bool = False) -> str:
825 """异步获取文件。请注意在使用后清理下载的文件, 以免占用过多空间
826
827 Args:
828 allow_return_url: 是否允许以文件 http 下载链接的形式返回,这允许您自行控制是否需要下载文件。
829 注意,如果为 True,也可能返回文件路径。
830 Returns:
831 str: 文件路径或者 http 下载链接
832
833 """
834 if allow_return_url and self.url:
835 return self.url
836
837 if self.file_:
838 path = self.file_
839 if is_file_uri(path):
840 path = file_uri_to_path(path)
841
842 if os.path.exists(path):
843 return os.path.abspath(path)
844
845 if self.url:
846 await self._download_file()
847 if self.file_:
848 path = self.file_
849 if is_file_uri(path):
850 path = file_uri_to_path(path)
851 return os.path.abspath(path)
852
853 return ""
854
855 async def _download_file(self) -> None:
856 """下载文件"""

Calls 3

_download_fileMethod · 0.95
is_file_uriFunction · 0.90
file_uri_to_pathFunction · 0.90