File size: 1,424 Bytes
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
from aiohttp import web
from aiohttp.http_exceptions import BadStatusLine

from .Functions.downloader import media_streamer
from FileStream.server.exceptions import FIleNotFound, InvalidHash
from FileStream.server.render_template import render_page, render_upload


async def handle_v2(request):
    return web.Response(text="Hello from app v2!")


#@sub_app.get("/watch/{path}", allow_head=True)
async def stream_handler(request: web.Request):
  try:
    path = request.match_info["path"]
    return web.Response(text=await render_page(path), content_type='text/html')
  except InvalidHash as e:
    raise web.HTTPForbidden(text=e.message)
  except FIleNotFound as e:
    raise web.HTTPNotFound(text=e.message)
  except (AttributeError, BadStatusLine, ConnectionResetError):
    pass

#@sub_app.get("/up", allow_head=True)
async def upload_handler(request: web.Request):
  # global faster_client,index,session, new_file_id
  await asyncio.gather(*tasks)
  try:
    return web.Response(text=await render_upload(), content_type='text/html')
  except InvalidHash as e:
    raise web.HTTPForbidden(text=e.message)
  except FIleNotFound as e:
    raise web.HTTPNotFound(text=e.message)
  except (AttributeError, BadStatusLine, ConnectionResetError):
    pass

sub_app = web.Application()
sub_app.router.add_get('/', handle_v2)
sub_app.router.add_get('/watch/{path}', stream_handler)
sub_app.router.add_get('/up', upload_handler)