Revert "Added: Show file size."

This commit is contained in:
Dr.Caduceus
2023-11-06 15:40:26 +05:30
committed by GitHub
3 changed files with 7 additions and 11 deletions

View File

@@ -5,7 +5,7 @@ from .config import Telegram, LOGGER_CONFIG_JSON
dictConfig(LOGGER_CONFIG_JSON)
version = 1.1
version = 1.0
logger = getLogger('bot')
TelegramBot = Client(
@@ -16,4 +16,4 @@ TelegramBot = Client(
plugins={"root": "bot/plugins"},
workers = Telegram.BOT_WORKERS,
max_concurrent_transmissions=1000
)
)

View File

@@ -39,7 +39,6 @@ async def get_file_properties(msg: Message):
if not media: abort(400, 'Unknown file type.')
file_name = getattr(media, 'file_name', None)
file_size = getattr(media, 'file_size', 0)
if not file_name:
file_format = {
@@ -54,4 +53,4 @@ async def get_file_properties(msg: Message):
mime_type = guess_type(file_name)[0] or 'application/octet-stream'
return file_name, file_size, mime_type
return file_name, mime_type

View File

@@ -1,6 +1,6 @@
from quart import Blueprint, Response, request, render_template, redirect
from .error import abort
from bot import TelegramBot
from bot import version, TelegramBot
from bot.config import Telegram, Server
from bot.modules.telegram import get_message, get_file_properties
@@ -18,19 +18,16 @@ async def transmit_file(file_id):
if code != file.caption:
abort(403)
file_name, file_size, mime_type = await get_file_properties(file)
file_name, mime_type = await get_file_properties(file)
headers = {
'Content-Type': mime_type,
'Content-Disposition': f'attachment; filename="{file_name}"',
'Content-Length': file_size
'Content-Disposition': f'attachment; filename="{file_name}"'
}
file_stream = TelegramBot.stream_media(file)
return Response(file_stream, headers=headers)
@bp.route('/stream/<int:file_id>')
async def stream_file(file_id):
code = request.args.get('code') or abort(401)
@@ -41,4 +38,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}')
return redirect(f'https://t.me/{Telegram.BOT_USERNAME}?start=file_{file_id}_{code}')