Use BufferedInputFile for incidents_export
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user