diff --git a/src/openflexure_microscope_server/serve_static_files.py b/src/openflexure_microscope_server/serve_static_files.py index c6ad80f4..6476393b 100644 --- a/src/openflexure_microscope_server/serve_static_files.py +++ b/src/openflexure_microscope_server/serve_static_files.py @@ -15,7 +15,8 @@ def add_static_file(app: FastAPI, fname: str, folder: str): def add_static_files(app: FastAPI): #with importlib.resources.as_file(openflexure_microscope_server) as p: # static_path = p.join("/static/") - static_path = "./src/openflexure_microscope_server/static" + #TODO: don't hard code this! + static_path = "/var/openflexure/application/openflexure-microscope-server/src/openflexure_microscope_server/static" if not os.path.isdir(static_path): raise RuntimeError("Can't find static files :(") diff --git a/src/openflexure_microscope_server/server.py b/src/openflexure_microscope_server/server.py index dc261851..c47dec15 100644 --- a/src/openflexure_microscope_server/server.py +++ b/src/openflexure_microscope_server/server.py @@ -2,6 +2,7 @@ from __future__ import annotations import logging import importlib.resources import os.path +from fastapi import Response from fastapi.staticfiles import StaticFiles from fastapi.responses import FileResponse, RedirectResponse from labthings_fastapi.thing_server import ThingServer @@ -30,4 +31,25 @@ except RuntimeError: print("Failed to add static files - you will have to do without them!") -app = thing_server.app \ No newline at end of file +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. +# This is necessary until Connect is rebuilt. +@app.get("/routes") +def routes_stub() -> dict[str, dict]: + fake_routes = [ + "/api/v2/", + "/api/v2/streams/snapshot", + ] + return {url: {"url": url, "methods": ["GET"]} for url in fake_routes} + +class JPEGResponse(Response): + media_type = "image/jpeg" + +@app.get("/api/v2/streams/snapshot") +@app.head("/api/v2/streams/snapshot") +async def thumbnail() -> JPEGResponse: + blob = await thing_server.things["/camera/"].lores_mjpeg_stream.grab_frame() + return JPEGResponse(blob) \ No newline at end of file