Formatted with Ruff
This commit is contained in:
parent
27aec769a2
commit
9fd8fc37f1
19 changed files with 680 additions and 392 deletions
|
|
@ -43,5 +43,3 @@ def serve_from_cli(argv: Optional[list[str]] = None):
|
|||
uvicorn.run(app, host=args.host, port=args.port)
|
||||
else:
|
||||
raise e
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ from socket import gethostname
|
|||
|
||||
def add_v2_endpoints(thing_server: ThingServer):
|
||||
app = thing_server.app
|
||||
|
||||
# TODO: update openflexure connect to make this unnecessary!!
|
||||
# The endpoints below fool OpenFlexure Connect into thinking we are a
|
||||
# v2 microscope, so we show up correctly.
|
||||
|
|
@ -15,7 +16,7 @@ def add_v2_endpoints(thing_server: ThingServer):
|
|||
fake_routes = [
|
||||
"/api/v2/",
|
||||
"/api/v2/streams/snapshot",
|
||||
"/api/v2/instrument/settings/name"
|
||||
"/api/v2/instrument/settings/name",
|
||||
]
|
||||
return {url: {"url": url, "methods": ["GET"]} for url in fake_routes}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,22 +4,23 @@ from fastapi import FastAPI
|
|||
import os
|
||||
import pathlib
|
||||
|
||||
|
||||
def add_static_file(app: FastAPI, fname: str, folder: str):
|
||||
print(f"Adding route for /{fname}")
|
||||
p=os.path.join(folder, fname)
|
||||
app.get(
|
||||
f"/{fname}",
|
||||
response_class=FileResponse,
|
||||
include_in_schema=False
|
||||
)(lambda: FileResponse(p))
|
||||
p = os.path.join(folder, fname)
|
||||
app.get(f"/{fname}", response_class=FileResponse, include_in_schema=False)(
|
||||
lambda: FileResponse(p)
|
||||
)
|
||||
|
||||
|
||||
def add_static_files(app: FastAPI):
|
||||
#with importlib.resources.as_file(openflexure_microscope_server) as p:
|
||||
# with importlib.resources.as_file(openflexure_microscope_server) as p:
|
||||
# static_path = p.join("/static/")
|
||||
#TODO: don't hard code this!
|
||||
# TODO: don't hard code this!
|
||||
search_paths = [
|
||||
"/var/openflexure/application/openflexure-microscope-server/src/openflexure_microscope_server/static",
|
||||
pathlib.Path().absolute() / "application/openflexure-microscope-server/src/openflexure_microscope_server/static",
|
||||
pathlib.Path().absolute()
|
||||
/ "application/openflexure-microscope-server/src/openflexure_microscope_server/static",
|
||||
]
|
||||
if __file__:
|
||||
search_paths.append(pathlib.Path(__file__).parent.parent / "static")
|
||||
|
|
@ -34,6 +35,7 @@ def add_static_files(app: FastAPI):
|
|||
@app.get("/", response_class=RedirectResponse)
|
||||
async def redirect_fastapi():
|
||||
return "/index.html"
|
||||
|
||||
for fname in os.listdir(static_path):
|
||||
fpath = os.path.join(static_path, fname)
|
||||
if os.path.isfile(fpath):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue