Merge pull request #133 from 0623forbidden/get_downloadable_url

Add get_url method for Downloadable
This commit is contained in:
Alex Root Junior 2019-05-24 21:44:34 +02:00 committed by GitHub
commit 9c0bc2d489
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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)