2026-03-30 11:42:13 +02:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
2026-03-30 12:27:45 +02:00
|
|
|
import hashlib
|
2026-03-30 12:13:04 +02:00
|
|
|
|
2026-03-30 12:27:45 +02:00
|
|
|
import htpy as h
|
|
|
|
|
from quart import Quart, Response, request, url_for
|
|
|
|
|
|
|
|
|
|
from repub.pages import admin_component, shim_page
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _render_shim_page(*, stylesheet_href: str, datastar_src: str) -> tuple[str, str]:
|
|
|
|
|
head = (
|
|
|
|
|
h.title["Republisher Admin UI"],
|
|
|
|
|
h.link(rel="stylesheet", href=stylesheet_href),
|
|
|
|
|
)
|
|
|
|
|
body = str(shim_page(datastar_src=datastar_src, head=head))
|
|
|
|
|
etag = hashlib.sha256(body.encode("utf-8")).hexdigest()
|
|
|
|
|
return body, etag
|
2026-03-30 11:42:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_app() -> Quart:
|
|
|
|
|
app = Quart(__name__)
|
|
|
|
|
|
|
|
|
|
@app.get("/")
|
2026-03-30 12:27:45 +02:00
|
|
|
async def index() -> Response:
|
|
|
|
|
body, etag = _render_shim_page(
|
|
|
|
|
stylesheet_href=url_for("static", filename="app.css"),
|
|
|
|
|
datastar_src=url_for("static", filename="datastar@1.0.0-RC.8.js"),
|
|
|
|
|
)
|
|
|
|
|
if request.if_none_match.contains(etag):
|
|
|
|
|
response = Response(status=304)
|
|
|
|
|
response.set_etag(etag)
|
|
|
|
|
return response
|
|
|
|
|
|
|
|
|
|
response = Response(body, mimetype="text/html")
|
|
|
|
|
response.set_etag(etag)
|
|
|
|
|
return response
|
|
|
|
|
|
|
|
|
|
@app.post("/")
|
|
|
|
|
async def index_patch() -> Response:
|
|
|
|
|
return Response(str(admin_component()), mimetype="text/html")
|
2026-03-30 11:42:13 +02:00
|
|
|
|
|
|
|
|
return app
|