Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
28 changes: 28 additions & 0 deletions src/murfey/server/api/file_io_frontend.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from logging import getLogger
from pathlib import Path

from fastapi import APIRouter, Depends
from pydantic import BaseModel
from sqlmodel import Session, select

from murfey.server.api.auth import (
MurfeySessionIDFrontend as MurfeySessionID,
Expand All @@ -11,6 +14,7 @@
process_gain as _process_gain,
)
from murfey.server.murfey_db import murfey_db
from murfey.util.config import get_machine_config

logger = getLogger("murfey.server.api.file_io_frontend")

Expand All @@ -28,3 +32,27 @@ async def process_gain(
):
result = await _process_gain(session_id, gain_reference_params, db)
return result


class SymlinkParameters(BaseModel):
target: Path # these are the paths without the rsync basepath as that is what the frontend has access to
symlink: Path
override: bool = False


@router.post("/sessions/{session_id}/symlink")
async def create_symlink(
session_id: MurfeySessionID, symlink_params: SymlinkParameters, db=murfey_db
) -> str:
murfey_session = db.exec(select(Session).where(Session.id == session_id)).one()
instrument_name = murfey_session.instrument_name
machine_config = get_machine_config(instrument_name=instrument_name)[
instrument_name
]
symlink_full_path = machine_config.rsync_basepath / symlink_params.symlink
if symlink_full_path.is_symlink() and symlink_params.override:
symlink_full_path.unlink()
if symlink_full_path.exists():
return ""
symlink_full_path.symlink_to(symlink_params.target)
return str(symlink_params.symlink)
7 changes: 7 additions & 0 deletions src/murfey/util/route_manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,13 @@ murfey.server.api.file_io_frontend.router:
type: int
methods:
- POST
- path: /file_io/frontend/sessions/{session_id}/symlink
function: create_symlink
path_params:
- name: session_id
type: int
methods:
- POST
murfey.server.api.file_io_instrument.router:
- path: /file_io/instrument/visits/{visit_name}/sessions/{session_id}/suggested_path
function: suggest_path
Expand Down