Add get_url method for Downloadable

This commit is contained in:
0623forbidden 2019-05-24 17:54:48 +07:00
parent 13e64d6394
commit 71466c4960
2 changed files with 17 additions and 1 deletions

View file

@ -185,7 +185,7 @@ class BaseBot:
if destination is None:
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')
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)
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]:
"""
Send file

View file

@ -45,5 +45,18 @@ class Downloadable:
else:
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):
return hash(self.file_id)