diff --git a/aiogram/bot/base.py b/aiogram/bot/base.py index d1d36f36..b8425f9b 100644 --- a/aiogram/bot/base.py +++ b/aiogram/bot/base.py @@ -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 diff --git a/aiogram/types/mixins.py b/aiogram/types/mixins.py index 396633ad..f11a1760 100644 --- a/aiogram/types/mixins.py +++ b/aiogram/types/mixins.py @@ -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)