File size: 1,575 Bytes
c283ccc
e566133
12e4bed
e566133
 
 
 
 
 
 
 
c283ccc
5c52c74
c283ccc
 
e566133
 
 
 
 
 
 
c283ccc
 
 
 
e566133
c283ccc
 
 
e566133
 
 
c283ccc
e566133
 
c283ccc
7737265
6e9b48a
e566133
 
 
c283ccc
e566133
c283ccc
e566133
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import os
import jinja2
import aiohttp
import urllib.parse
from FileStream.config import Telegram, Server
from FileStream.Database import Database
from FileStream.Tools.file import humanbytes

db = Database(Telegram.DATABASE_URL, Telegram.SESSION_NAME)


# Define the path to the static folder
static_folder = os.path.join(os.path.dirname(__file__), '..','template')


async def render_page(db_id):
  file_data = await db.get_file(db_id)
  src = urllib.parse.urljoin(Server.URL, f'api/dl/{file_data["_id"]}')
  file_size = humanbytes(file_data['file']['file_size'])
  file_name = file_data['file']['file_name'].replace("_", " ")

  if str((file_data['file']['mime_type']).split('/')[0].strip()) == 'video':
    
    template_file = os.path.join(static_folder, "play.html")
    #template_file = "FileStream/server/template/play.html"

  else:
    #template_file = "FileStream/server/template/dl.html"
    template_file = os.path.join(static_folder, "dl.html")

    async with aiohttp.ClientSession() as s:
      async with s.get(src) as u:
        file_size = humanbytes(int(u.headers.get('Content-Length')))

  with open(template_file) as f:
    template = jinja2.Template(f.read())

  #print(f"* Loading Template file_name: {file_name}, file_url: {src}, file_size: {file_size}")
  return template.render(file_name=file_name, file_url=src, file_size=file_size, static_url='/static/')


async def render_upload():

  template_file = "FileStream/server/template/upload.html"

  with open(template_file) as f:
    template = jinja2.Template(f.read())
  return template.render()