From 5bb9bd6c6d2a975e6e9d7e078e71cef38c6a1edf Mon Sep 17 00:00:00 2001 From: abdullaev388 Date: Sat, 25 Dec 2021 23:09:30 +0500 Subject: [PATCH] opportunity to save file without creating directory according to it's type --- aiogram/types/mixins.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/aiogram/types/mixins.py b/aiogram/types/mixins.py index 7d06d4c4..18cca4e9 100644 --- a/aiogram/types/mixins.py +++ b/aiogram/types/mixins.py @@ -18,6 +18,7 @@ class Downloadable: chunk_size=65536, seek=True, make_dirs=True, + make_file_type_dir=True, *, destination_dir: Optional[Union[str, pathlib.Path]] = None, destination_file: Optional[Union[str, pathlib.Path, IOBase]] = None @@ -32,6 +33,7 @@ class Downloadable: :param chunk_size: Integer :param seek: Boolean - go to start of file when downloading is finished. :param make_dirs: Make dirs if not exist + :param make_file_type_dir: Make directory according to file type. :param destination_dir: directory for saving files :param destination_file: path to the file or instance of :class:`io.IOBase`. For e. g. :class:`io.BytesIO` :return: destination @@ -49,6 +51,7 @@ class Downloadable: destination, destination_dir, destination_file, + make_file_type_dir ) return await self.bot.download_file( @@ -60,9 +63,12 @@ class Downloadable: make_dirs=make_dirs ) - async def _prepare_destination(self, dest, destination_dir, destination_file): + async def _prepare_destination(self, dest, destination_dir, destination_file, make_file_type_dir): file = await self.get_file() + if not make_file_type_dir: + file.file_path = file.file_path.split('/')[-1] + if not(any((dest, destination_dir, destination_file))): destination = file.file_path