Fix data directory save location and mount path

This commit is contained in:
Julian Stirling 2026-05-10 13:57:12 +01:00
parent fa5aaaf254
commit b6efb73cba
4 changed files with 13 additions and 7 deletions

View file

@ -86,7 +86,7 @@ def customise_server(
)
add_v2_endpoints(server)
add_static_files(server.app, application_config.data_folder)
add_static_files(server, application_config.data_folder)
# Configure logging to DEBUG if requested in CLI args.
if debug:

View file

@ -6,6 +6,8 @@ from fastapi import FastAPI
from fastapi.responses import FileResponse, RedirectResponse
from fastapi.staticfiles import StaticFiles
import labthings_fastapi as lt
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_PATH = os.path.normpath(os.path.join(THIS_DIR, "..", "static"))
@ -35,7 +37,7 @@ def add_static_file(app: FastAPI, fname: str, folder: str) -> None:
)
def add_static_files(app: FastAPI, data_folder: str) -> None:
def add_static_files(server: lt.ThingServer, data_folder: str) -> None:
"""Add the static files responsible for the webapp app to the FastAPI app.
Note that any file in the root of the static dir will not be cached. However, the
@ -43,9 +45,10 @@ def add_static_files(app: FastAPI, data_folder: str) -> None:
The Vue CSS and JS are hashed, so if updated their filename will update. The most
important file not to cache is "index.html".
:param app: The FastAPI app to add to, in this case the OpenFlexure server
:param server: The LabThings server.
:param data_folder: The directory for any data.
"""
app = server.app
check_static_dir()
@app.get("/", response_class=RedirectResponse)
@ -71,7 +74,7 @@ def add_static_files(app: FastAPI, data_folder: str) -> None:
if not os.path.isdir(data_folder):
os.makedirs(data_folder)
app.mount(
"/data/",
server._api_prefix.rstrip("/") + "/data/",
StaticFiles(directory=data_folder),
name="data",
)

View file

@ -31,7 +31,7 @@ class OFMThing(lt.Thing):
raise ValueError("No application configuration was supplied.")
app_data_dir = application_config["data_folder"]
self._data_dir = os.path.join(
os.path.normpath(str(app_data_dir)), os.path.normpath(self.path.strip("/"))
os.path.normpath(str(app_data_dir)), os.path.normpath(self.name)
)
return self