Spaces:
Runtime error
Runtime error
from src.Classes.Sanity import Sanity | |
from aiohttp.web import Request | |
from aiohttp import web | |
from telethon import TelegramClient | |
from telethon.tl.types import Message | |
from src.Classes.Download import Download | |
class Handler: | |
req: Request | |
client: TelegramClient | |
chat_id = -1001278111932 | |
message: Message | |
route: str | |
head = False | |
sanity: Sanity | |
def __init__(self, req: Request, client, route=None, head=False): | |
self.head = head | |
self.req = req | |
self.client = client | |
self.sanity = Sanity() | |
self.sanity.client = self.client | |
self.sanity.chat_id = self.chat_id | |
self.sanity.req = self.req | |
self.sanity.file_id = int(self.req.match_info["id"]) | |
async def sanity_checks(self): | |
self.message = await self.sanity.file_exists() | |
try: | |
if not self.message.media: | |
return web.json_response( | |
status=404, | |
data={"Error": "File Does not Exist", "route": self.route}, | |
) | |
except: | |
return web.json_response( | |
status=404, data={"Error": "File Does not Exist", "route": self.route} | |
) | |
if self.sanity.check_ranges() == False: | |
return web.json_response( | |
status=416, | |
text="416: Range Not Satisfiable", | |
headers={"Content-Range": f"bytes */{self.message.file.size}"}, | |
) | |
async def process_request(self): | |
response = await self.sanity_checks() | |
if type(response) is web.Response: | |
return response | |
# download/stream | |
return await Download(self).handle_request() | |