11from logging import getLogger
2+ from pathlib import Path
23
34from fastapi import APIRouter , Depends
5+ from pydantic import BaseModel
6+ from sqlmodel import Session , select
47
58from murfey .server .api .auth import (
69 MurfeySessionIDFrontend as MurfeySessionID ,
1114 process_gain as _process_gain ,
1215)
1316from murfey .server .murfey_db import murfey_db
17+ from murfey .util .config import get_machine_config
1418
1519logger = getLogger ("murfey.server.api.file_io_frontend" )
1620
@@ -28,3 +32,28 @@ async def process_gain(
2832):
2933 result = await _process_gain (session_id , gain_reference_params , db )
3034 return result
35+
36+
37+ class SymlinkParameters (BaseModel ):
38+ target : Path # these are the paths without the rsync basepath as that is what the frontend has access to
39+ symlink : Path
40+ override : bool = False
41+
42+
43+ @router .post ("/sessions/{session_id}/symlink" )
44+ async def create_symlink (
45+ session_id : MurfeySessionID , symlink_params : SymlinkParameters , db = murfey_db
46+ ) -> str :
47+ murfey_session = db .exec (select (Session ).where (Session .id == session_id )).one ()
48+ instrument_name = murfey_session .instrument_name
49+ machine_config = get_machine_config (instrument_name = instrument_name )[
50+ instrument_name
51+ ]
52+ symlink_full_path = machine_config .rsync_basepath / symlink_params .symlink
53+ if symlink_full_path .is_symlink ():
54+ if symlink_params .override :
55+ symlink_full_path .unlink ()
56+ elif symlink_full_path .exists ():
57+ return ""
58+ symlink_full_path .symlink_to (symlink_params .target )
59+ return str (symlink_params .symlink )
0 commit comments