diff --git a/bot/server/main.py b/bot/server/main.py index e715347..1fca5f4 100644 --- a/bot/server/main.py +++ b/bot/server/main.py @@ -1,6 +1,6 @@ from quart import Blueprint, Response, request, render_template, redirect from .error import abort -from bot import version, TelegramBot +from bot import TelegramBot from bot.config import Telegram, Server from bot.modules.telegram import get_message, get_file_properties @@ -18,16 +18,19 @@ async def transmit_file(file_id): if code != file.caption: abort(403) - file_name, mime_type = await get_file_properties(file) + file_name, file_size, mime_type = await get_file_properties(file) + headers = { 'Content-Type': mime_type, - 'Content-Disposition': f'attachment; filename="{file_name}"' + 'Content-Disposition': f'attachment; filename="{file_name}"', + 'Content-Length': file_size } file_stream = TelegramBot.stream_media(file) return Response(file_stream, headers=headers) + @bp.route('/stream/') async def stream_file(file_id): code = request.args.get('code') or abort(401) @@ -38,4 +41,4 @@ async def stream_file(file_id): async def file_deeplink(file_id): code = request.args.get('code') or abort(401) - return redirect(f'https://t.me/{Telegram.BOT_USERNAME}?start=file_{file_id}_{code}') \ No newline at end of file + return redirect(f'https://t.me/{Telegram.BOT_USERNAME}?start=file_{file_id}_{code}')