Spaces:
Running
Running
BinaryONe
commited on
Commit
·
c283ccc
1
Parent(s):
59e12cf
Miseleneous Fixes
Browse files
FileStream/server/API/__init__.py
CHANGED
@@ -24,8 +24,6 @@ async def handle_v2(request):
|
|
24 |
api = web.Application()
|
25 |
|
26 |
|
27 |
-
|
28 |
-
|
29 |
cors = aiohttp_cors.setup(api, defaults={"*": aiohttp_cors.ResourceOptions(
|
30 |
allow_credentials=False,
|
31 |
expose_headers="*",
|
@@ -33,8 +31,6 @@ cors = aiohttp_cors.setup(api, defaults={"*": aiohttp_cors.ResourceOptions(
|
|
33 |
allow_methods="*"
|
34 |
)})
|
35 |
|
36 |
-
|
37 |
-
|
38 |
cors.add(api.router.add_get('/', handle_v2))
|
39 |
|
40 |
#api.router.add_get('/files', list_all_files_db)
|
|
|
24 |
api = web.Application()
|
25 |
|
26 |
|
|
|
|
|
27 |
cors = aiohttp_cors.setup(api, defaults={"*": aiohttp_cors.ResourceOptions(
|
28 |
allow_credentials=False,
|
29 |
expose_headers="*",
|
|
|
31 |
allow_methods="*"
|
32 |
)})
|
33 |
|
|
|
|
|
34 |
cors.add(api.router.add_get('/', handle_v2))
|
35 |
|
36 |
#api.router.add_get('/files', list_all_files_db)
|
FileStream/server/APP/render_template.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import jinja2
|
2 |
import aiohttp
|
3 |
import urllib.parse
|
@@ -8,6 +9,10 @@ from FileStream.Tools.file import humanbytes
|
|
8 |
db = Database(Telegram.DATABASE_URL, Telegram.SESSION_NAME)
|
9 |
|
10 |
|
|
|
|
|
|
|
|
|
11 |
async def render_page(db_id):
|
12 |
file_data = await db.get_file(db_id)
|
13 |
src = urllib.parse.urljoin(Server.URL, f'api/dl/{file_data["_id"]}')
|
@@ -15,21 +20,28 @@ async def render_page(db_id):
|
|
15 |
file_name = file_data['file']['file_name'].replace("_", " ")
|
16 |
|
17 |
if str((file_data['file']['mime_type']).split('/')[0].strip()) == 'video':
|
18 |
-
|
|
|
|
|
|
|
19 |
else:
|
20 |
-
template_file = "FileStream/server/template/dl.html"
|
|
|
|
|
21 |
async with aiohttp.ClientSession() as s:
|
22 |
async with s.get(src) as u:
|
23 |
file_size = humanbytes(int(u.headers.get('Content-Length')))
|
|
|
24 |
with open(template_file) as f:
|
25 |
template = jinja2.Template(f.read())
|
26 |
-
|
27 |
-
|
28 |
-
file_size=file_size)
|
29 |
|
30 |
|
31 |
async def render_upload():
|
|
|
32 |
template_file = "FileStream/server/template/upload.html"
|
|
|
33 |
with open(template_file) as f:
|
34 |
template = jinja2.Template(f.read())
|
35 |
return template.render()
|
|
|
1 |
+
import os
|
2 |
import jinja2
|
3 |
import aiohttp
|
4 |
import urllib.parse
|
|
|
9 |
db = Database(Telegram.DATABASE_URL, Telegram.SESSION_NAME)
|
10 |
|
11 |
|
12 |
+
# Define the path to the static folder
|
13 |
+
static_folder = os.path.join(os.path.dirname(__file__), '..', '..', 'template')
|
14 |
+
|
15 |
+
|
16 |
async def render_page(db_id):
|
17 |
file_data = await db.get_file(db_id)
|
18 |
src = urllib.parse.urljoin(Server.URL, f'api/dl/{file_data["_id"]}')
|
|
|
20 |
file_name = file_data['file']['file_name'].replace("_", " ")
|
21 |
|
22 |
if str((file_data['file']['mime_type']).split('/')[0].strip()) == 'video':
|
23 |
+
|
24 |
+
template_file = os.path.join(static_folder, "play.html")
|
25 |
+
#template_file = "FileStream/server/template/play.html"
|
26 |
+
|
27 |
else:
|
28 |
+
#template_file = "FileStream/server/template/dl.html"
|
29 |
+
template_file = os.path.join(static_folder, "dl.html")
|
30 |
+
|
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 |
+
return template.render(file_name=file_name,file_url=src,file_size=file_size)
|
|
|
39 |
|
40 |
|
41 |
async def render_upload():
|
42 |
+
|
43 |
template_file = "FileStream/server/template/upload.html"
|
44 |
+
|
45 |
with open(template_file) as f:
|
46 |
template = jinja2.Template(f.read())
|
47 |
return template.render()
|
FileStream/server/__init__.py
CHANGED
@@ -18,6 +18,10 @@ from .Middlewares.logging_middleware import logging_middleware
|
|
18 |
# Set time to consider a client inactive (e.g., 10 minutes)
|
19 |
INACTIVITY_TIMEOUT = 180 # 3 minutes
|
20 |
|
|
|
|
|
|
|
|
|
21 |
async def clear_inactive_clients():
|
22 |
"""Clear inactive clients from ACTIVE_CLIENTS."""
|
23 |
await asyncio.sleep(INACTIVITY_TIMEOUT) # Check every INACTIVITY_TIMEOUT seconds
|
@@ -43,5 +47,8 @@ def web_server():
|
|
43 |
web_app.add_subapp('/app', app)
|
44 |
web_app.add_subapp('/api', api)
|
45 |
web_app.add_subapp('/auth', auth)
|
46 |
-
|
|
|
|
|
|
|
47 |
return web_app
|
|
|
18 |
# Set time to consider a client inactive (e.g., 10 minutes)
|
19 |
INACTIVITY_TIMEOUT = 180 # 3 minutes
|
20 |
|
21 |
+
# Define the path to the template (static) folder
|
22 |
+
template_folder = os.path.join(os.path.dirname(__file__), 'template')
|
23 |
+
|
24 |
+
|
25 |
async def clear_inactive_clients():
|
26 |
"""Clear inactive clients from ACTIVE_CLIENTS."""
|
27 |
await asyncio.sleep(INACTIVITY_TIMEOUT) # Check every INACTIVITY_TIMEOUT seconds
|
|
|
47 |
web_app.add_subapp('/app', app)
|
48 |
web_app.add_subapp('/api', api)
|
49 |
web_app.add_subapp('/auth', auth)
|
50 |
+
|
51 |
+
# Add static file handler
|
52 |
+
web_app.router.add_static('/static/', template_folder)
|
53 |
+
|
54 |
return web_app
|