mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-15 20:02:22 +00:00
Add get_url method for Downloadable
This commit is contained in:
parent
13e64d6394
commit
71466c4960
2 changed files with 17 additions and 1 deletions
|
|
@ -185,7 +185,7 @@ class BaseBot:
|
||||||
if destination is None:
|
if destination is None:
|
||||||
destination = io.BytesIO()
|
destination = io.BytesIO()
|
||||||
|
|
||||||
url = api.Methods.file_url(token=self.__token, path=file_path)
|
url = self.get_file_url(file_path)
|
||||||
|
|
||||||
dest = destination if isinstance(destination, io.IOBase) else open(destination, 'wb')
|
dest = destination if isinstance(destination, io.IOBase) else open(destination, 'wb')
|
||||||
async with self.session.get(url, timeout=timeout, proxy=self.proxy, proxy_auth=self.proxy_auth) as response:
|
async with self.session.get(url, timeout=timeout, proxy=self.proxy, proxy_auth=self.proxy_auth) as response:
|
||||||
|
|
@ -199,6 +199,9 @@ class BaseBot:
|
||||||
dest.seek(0)
|
dest.seek(0)
|
||||||
return dest
|
return dest
|
||||||
|
|
||||||
|
def get_file_url(self, file_path):
|
||||||
|
return api.Methods.file_url(token=self.__token, path=file_path)
|
||||||
|
|
||||||
async def send_file(self, file_type, method, file, payload) -> Union[Dict, base.Boolean]:
|
async def send_file(self, file_type, method, file, payload) -> Union[Dict, base.Boolean]:
|
||||||
"""
|
"""
|
||||||
Send file
|
Send file
|
||||||
|
|
|
||||||
|
|
@ -45,5 +45,18 @@ class Downloadable:
|
||||||
else:
|
else:
|
||||||
return await self.bot.get_file(self.file_id)
|
return await self.bot.get_file(self.file_id)
|
||||||
|
|
||||||
|
async def get_url(self):
|
||||||
|
"""
|
||||||
|
Get file url.
|
||||||
|
|
||||||
|
Attention!!
|
||||||
|
This method has security vulnerabilities for the reason that result
|
||||||
|
contains bot's *access token* in open form. Use at your own risk!
|
||||||
|
|
||||||
|
:return: url
|
||||||
|
"""
|
||||||
|
file = await self.get_file()
|
||||||
|
return self.bot.get_file_url(file.file_path)
|
||||||
|
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return hash(self.file_id)
|
return hash(self.file_id)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue