Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for instrument image display endpoints #374

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/murfey/instrument_server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ def get_possible_gain_references(
headers={"Authorization": f"Bearer {tokens[session_id]}"},
).json()
candidates = []
for gf in secure_path(Path(machine_config["gain_reference_directory"])).glob(
"**/*"
):
for gf in secure_path(
Path(machine_config["gain_reference_directory"]), keep_spaces=True
).glob("**/*"):
if gf.is_file():
candidates.append(
File(
Expand Down
4 changes: 2 additions & 2 deletions src/murfey/server/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ def get_instrument_display_name(instrument_name: str) -> str:
machine_config = get_machine_config(instrument_name=instrument_name)[
d-j-hatton marked this conversation as resolved.
Show resolved Hide resolved
instrument_name
]
if machine_config.get(instrument_name):
return machine_config[instrument_name].display_name
if machine_config:
return machine_config.display_name
return ""


Expand Down
8 changes: 4 additions & 4 deletions src/murfey/server/api/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
machine_config = get_machine_config()


@router.get("/microscope_image/")
def get_mic_image():
if machine_config.image_path:
return FileResponse(machine_config.image_path)
@router.get("/instruments/{instrument_name}/image/")
def get_mic_image(instrument_name: str):
if machine_config[instrument_name].image_path:
return FileResponse(machine_config[instrument_name].image_path)
return None


Expand Down
2 changes: 1 addition & 1 deletion src/murfey/server/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ async def websocket_connection_endpoint(
except Exception:
await manager.broadcast(f"Client #{client_id} sent message {data}")
except WebSocketDisconnect:
log.info(f"Disconnecting Client {int(sanitise(str(client_id)))}")
log.info(f"Disconnecting Client {sanitise(str(client_id))}")
manager.disconnect(websocket, client_id, unregister_client=False)
await manager.broadcast(f"Client #{client_id} disconnected")
await manager.delete_state(f"Client {client_id}")
Expand Down
7 changes: 5 additions & 2 deletions src/murfey/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ def sanitise_nonpath(in_string: str) -> str:
return in_string


def secure_path(in_path: Path) -> Path:
secured_parts = [secure_filename(p) for p in in_path.parts]
def secure_path(in_path: Path, keep_spaces: bool = False) -> Path:
if keep_spaces:
secured_parts = [secure_filename(p) for p in in_path.parts if " " not in p]
d-j-hatton marked this conversation as resolved.
Show resolved Hide resolved
else:
secured_parts = [secure_filename(p) for p in in_path.parts]
return Path("/".join(secured_parts))


Expand Down