From 1b9d260530c25167d8b2def62ff10ff9a1ef9a4a Mon Sep 17 00:00:00 2001 From: benya Date: Mon, 9 Feb 2026 02:31:24 +0300 Subject: [PATCH] Use BufferedInputFile for incidents_export --- handlers/system.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/handlers/system.py b/handlers/system.py index f20629d..cf65692 100644 --- a/handlers/system.py +++ b/handlers/system.py @@ -1,7 +1,7 @@ import asyncio import os from aiogram import F -from aiogram.types import Message, CallbackQuery, InlineKeyboardMarkup, InlineKeyboardButton, InputFile +from aiogram.types import Message, CallbackQuery, InlineKeyboardMarkup, InlineKeyboardButton, InputFile, BufferedInputFile from app import dp, cfg from auth import is_admin_msg from keyboards import ( @@ -428,20 +428,19 @@ async def incidents_export(msg: Message): }) if fmt == "json": payload = json.dumps(data, ensure_ascii=False, indent=2) - bio = io.BytesIO(payload.encode("utf-8")) - bio.name = f"incidents_{hours}h.json" + file_bytes = payload.encode("utf-8") + fname = f"incidents_{hours}h.json" else: sio = io.StringIO() writer = csv.DictWriter(sio, fieldnames=["timestamp", "category", "message"]) writer.writeheader() for row in data: writer.writerow(row) - bio = io.BytesIO(sio.getvalue().encode("utf-8")) - bio.name = f"incidents_{hours}h.csv" - bio.seek(0) + file_bytes = sio.getvalue().encode("utf-8") + fname = f"incidents_{hours}h.csv" summary = f"📤 Incidents export ({hours}h): {len(data)} rows, format {fmt}" await msg.answer(summary) - await msg.answer_document(document=InputFile(bio, filename=bio.name)) + await msg.answer_document(document=BufferedInputFile(file_bytes, filename=fname)) @dp.message(F.text == "🔒 SSL")