Добавлен filename к InputMediaBuffer

This commit is contained in:
Денис Семёнов 2025-07-27 02:12:58 +03:00
parent 7ea24fe2af
commit 6f86d15de4
3 changed files with 7 additions and 3 deletions

View File

@ -4,7 +4,6 @@ import os
import mimetypes
from typing import TYPE_CHECKING, Any, Optional
from uuid import uuid4
import aiofiles
import puremagic
@ -156,6 +155,7 @@ class BaseConnection:
async def upload_file_buffer(
self,
filename: str,
url: str,
buffer: bytes,
type: UploadType
@ -182,7 +182,7 @@ class BaseConnection:
mime_type = f"{type.value}/*"
ext = ''
basename = f'{uuid4()}{ext}'
basename = f'{filename}{ext}'
form = FormData()
form.add_field(

View File

@ -68,13 +68,15 @@ class InputMediaBuffer:
type (UploadType): Тип файла, определенный по содержимому.
"""
def __init__(self, buffer: bytes):
def __init__(self, buffer: bytes, filename: str | None = None):
"""
Инициализирует объект медиафайла из буфера.
Args:
buffer (IO): Буфер с содержимым файла.
filename (str): Название файла (по умолчанию присваивается uuid4).
"""
self.filename = filename
self.buffer = buffer
self.type = self.__detect_file_type(buffer)

View File

@ -2,6 +2,7 @@ from __future__ import annotations
from typing import TYPE_CHECKING
from json import loads
from uuid import uuid4
from ..types.input_media import InputMedia, InputMediaBuffer
from ..enums.upload_type import UploadType
@ -46,6 +47,7 @@ async def process_input_media(
)
elif isinstance(att, InputMediaBuffer):
upload_file_response = await base_connection.upload_file_buffer(
filename=att.filename or str(uuid4()),
url=upload.url,
buffer=att.buffer,
type=att.type,