MCPcopy Index your code
hub / github.com/TechifyBots/File-Stream-Bot / render_page

Function render_page

biisal/utils/render_template.py:12–45  ·  view source on GitHub ↗
(id, secure_hash, src=None)

Source from the content-addressed store, hash-verified

10import jinja2
11
12async def render_page(id, secure_hash, src=None):
13 file = await StreamBot.get_messages(int(Var.BIN_CHANNEL), int(id))
14 file_data = await get_file_ids(StreamBot, int(Var.BIN_CHANNEL), int(id))
15 if file_data.unique_id[:6] != secure_hash:
16 logging.debug(f"link hash: {secure_hash} - {file_data.unique_id[:6]}")
17 logging.debug(f"Invalid hash for message with - ID {id}")
18 raise InvalidHash
19
20 src = urllib.parse.urljoin(
21 Var.URL,
22 f"{id}/{urllib.parse.quote_plus(file_data.file_name)}?hash={secure_hash}",
23 )
24
25 tag = file_data.mime_type.split("/")[0].strip()
26 file_size = humanbytes(file_data.file_size)
27 if tag in ["video", "audio"]:
28 template_file = "biisal/template/req.html"
29 else:
30 template_file = "biisal/template/dl.html"
31 async with aiohttp.ClientSession() as s:
32 async with s.get(src) as u:
33 file_size = humanbytes(int(u.headers.get("Content-Length")))
34
35 with open(template_file) as f:
36 template = jinja2.Template(f.read())
37
38 file_name = file_data.file_name.replace("_", " ")
39
40 return template.render(
41 file_name=file_name,
42 file_url=src,
43 file_size=file_size,
44 file_unique_id=file_data.unique_id,
45 )

Callers 1

stream_handlerFunction · 0.90

Calls 2

get_file_idsFunction · 0.90
humanbytesFunction · 0.90

Tested by

no test coverage detected