Added v2 API routes and hard-coded static files to support Connect
Connect looks for /routes and /api/v2/streams/snapshot These are now present and working. I've also hard coded the static files directory - fixing this properly is a work in progress.
This commit is contained in:
parent
60f854b7db
commit
753514c24b
2 changed files with 25 additions and 2 deletions
|
|
@ -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
|
||||
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue