from telethon import TelegramClient from fastapi import Request class Sanity: client: TelegramClient media = None chat_id: int = -1001925049183 file_id: int req: Request limit: int offset: int async def file_exists(self): try: self.media = await self.client.get_messages( entity=self.chat_id, ids=self.file_id ) return self.media except Exception as e: pass def check_ranges(self): range_header = self.req.headers.get("Range") if range_header: offset = range_header.split("=")[1].split("-")[0] or 0 limit = range_header.split("=")[1].split("-")[1] or self.media.file.size else: offset = 0 limit = self.media.file.size self.offset = int(offset) self.limit = int(limit) if ( (limit > self.media.file.size) or (self.offset < 0) or (self.limit < self.offset) ): return False else: return True