Frontend created and rewritten a few times, with some backend fixes #1

Merged
leo merged 110 commits from plaintable into main 2023-11-08 20:38:40 +00:00
Showing only changes of commit 9002afbc7e - Show all commits

View File

@ -2,6 +2,7 @@ import mimetypes
from importlib.resources import files
from urllib.parse import unquote
import brotli
from sanic import Blueprint, Sanic, raw
from sanic.exceptions import Forbidden, NotFound
@ -58,6 +59,30 @@ def http_fileserver(app, _):
app.blueprint(bp)
www = {}
@app.before_server_start
def load_wwwroot(app, _):
www.clear()
base = files("cista")
paths = ["wwwroot"]
while path := paths.pop(0):
current = files("cista") / path
for p in current.iterdir():
if p.is_dir():
print(p)
paths.append(current / p.parts[-1])
continue
name = p.relative_to(base).as_posix()
mime = mimetypes.guess_type(name)[0] or "application/octet-stream"
data = p.read_bytes()
br = brotli.compress(data)
if len(br) >= len(data):
br = False
www[name] = data, br, mime
@app.get("/<path:path>", static=True)
async def wwwroot(req, path=""):
"""Frontend files only"""