From aba3b2dbe5ede894caa552c31beda8676a0021ed Mon Sep 17 00:00:00 2001 From: michael Date: Fri, 1 Nov 2024 13:58:52 +0100 Subject: [PATCH] add index.html to api, fix virtualio. --- node/app_api.py | 5 +++++ node/routers/static.py | 29 ++++++++------------------ node/services/backends/io/virtualio.py | 2 +- node/web_spa/index.html | 21 +++++++++++++++++++ 4 files changed, 36 insertions(+), 21 deletions(-) create mode 100644 node/web_spa/index.html diff --git a/node/app_api.py b/node/app_api.py index 7d10c42..c5f4dda 100644 --- a/node/app_api.py +++ b/node/app_api.py @@ -2,6 +2,7 @@ import logging from contextlib import asynccontextmanager +from pathlib import Path import uvicorn from fastapi import FastAPI @@ -13,6 +14,7 @@ from .common_utils import create_basic_folders from .container import container from .routers import api +from .routers.static import static_router logger = logging.getLogger(f"{__name__}") @@ -46,9 +48,12 @@ def _create_app() -> FastAPI: dependencies=[], lifespan=lifespan, ) + _app.include_router(static_router) _app.include_router(api.router) # serve data directory holding images, thumbnails, ... _app.mount("/media", StaticFiles(directory="media"), name="media") + # if not match anything above, default to deliver static files from web directory + _app.mount("/", StaticFiles(directory=Path(__file__).parent.resolve().joinpath("web_spa")), name="web_spa") async def custom_http_exception_handler(request, exc): logger.error(f"HTTPException: {repr(exc)}") diff --git a/node/routers/static.py b/node/routers/static.py index be9d40b..623555a 100644 --- a/node/routers/static.py +++ b/node/routers/static.py @@ -1,6 +1,8 @@ import logging +from pathlib import Path from fastapi import APIRouter +from fastapi.responses import FileResponse logger = logging.getLogger(__name__) static_router = APIRouter( @@ -8,23 +10,10 @@ ) -# @static_router.get("/") -# def index(): -# """ -# return homepage of booth -# """ -# headers = {"Cache-Control": "no-store, no-cache, must-revalidate"} -# return FileResponse(path=Path(__file__).parent.parent.joinpath("web_spa", "index.html").resolve(), headers=headers) - - -# @static_router.get("/private.css") -# def ui_private_css(): -# """ -# if private.css exists return the file content, otherwise send empty response to avoid 404 -# """ -# path = Path("userdata", "private.css") -# headers = {"Cache-Control": "no-store, no-cache, must-revalidate"} -# if not path.is_file(): -# return Response("/* placeholder. create private.css in userdata folder to customize css */", headers=headers) -# else: -# return FileResponse(path=path, headers=headers) +@static_router.get("/") +def index(): + """ + return homepage of booth, index is special not cached so spa updates are less a problem + """ + headers = {"Cache-Control": "no-store, no-cache, must-revalidate"} + return FileResponse(path=Path(__file__).parent.parent.joinpath("web_spa", "index.html").resolve(), headers=headers) diff --git a/node/services/backends/io/virtualio.py b/node/services/backends/io/virtualio.py index 7344688..3e5500b 100644 --- a/node/services/backends/io/virtualio.py +++ b/node/services/backends/io/virtualio.py @@ -45,7 +45,7 @@ def _gpio_fun(self): while not current_thread().stopped(): time.sleep((1.0 / self._config.fps_nominal) / 2.0) - self._on_clock_rise_in() + self._on_clock_rise_in(time.monotonic_ns()) time.sleep((1.0 / self._config.fps_nominal) / 2.0) self._on_clock_fall_in() diff --git a/node/web_spa/index.html b/node/web_spa/index.html new file mode 100644 index 0000000..4b9775a --- /dev/null +++ b/node/web_spa/index.html @@ -0,0 +1,21 @@ + + + + Photobooth-App + + + + + + + +
+

Wigglecam-Api Frontend

+

The api is just a backend with no actual frontend. This is just a collection of links, that might be helpful:

+ +
+ \ No newline at end of file