| import os |
| from aiohttp import web |
| from aiohttp.http_exceptions import BadStatusLine |
|
|
| |
| from ..Functions.downloader import media_streamer |
| from .render_template import render_page, render_upload |
| from FileStream.Exceptions import FIleNotFound, InvalidHash |
|
|
|
|
| |
|
|
|
|
| tasks = [] |
|
|
|
|
| |
| 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 |
|
|
| |
| async def upload_handler(request: web.Request): |
| |
| 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 |
|
|
|
|