feat: add project_path output to ProjectSource node
ProjectSource now outputs a third value: the project's folder path,
fetched from the new /api/projects/{name} endpoint. Useful for
building paths to files relative to the project directory.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -28,6 +28,7 @@ def register_api_routes(db: ProjectDB) -> None:
|
|||||||
|
|
||||||
app.add_api_route("/api/projects", _list_projects, methods=["GET"])
|
app.add_api_route("/api/projects", _list_projects, methods=["GET"])
|
||||||
app.add_api_route("/api/active-project", _get_active_project, methods=["GET"])
|
app.add_api_route("/api/active-project", _get_active_project, methods=["GET"])
|
||||||
|
app.add_api_route("/api/projects/{name}", _get_project, methods=["GET"])
|
||||||
app.add_api_route("/api/projects/{name}/files", _list_files, methods=["GET"])
|
app.add_api_route("/api/projects/{name}/files", _list_files, methods=["GET"])
|
||||||
app.add_api_route("/api/projects/{name}/files/{file_name}/sequences", _list_sequences, methods=["GET"])
|
app.add_api_route("/api/projects/{name}/files/{file_name}/sequences", _list_sequences, methods=["GET"])
|
||||||
app.add_api_route("/api/projects/{name}/files/{file_name}/data", _get_data, methods=["GET"])
|
app.add_api_route("/api/projects/{name}/files/{file_name}/data", _get_data, methods=["GET"])
|
||||||
@@ -52,6 +53,15 @@ def _get_active_project() -> dict[str, Any]:
|
|||||||
return {"project": config.get("current_project", "")}
|
return {"project": config.get("current_project", "")}
|
||||||
|
|
||||||
|
|
||||||
|
def _get_project(name: str) -> dict[str, Any]:
|
||||||
|
db = _get_db()
|
||||||
|
proj = db.get_project(name)
|
||||||
|
if not proj:
|
||||||
|
raise HTTPException(status_code=404, detail=f"Project '{name}' not found")
|
||||||
|
return {"name": proj["name"], "folder_path": proj["folder_path"],
|
||||||
|
"description": proj.get("description", "")}
|
||||||
|
|
||||||
|
|
||||||
def _list_files(name: str) -> dict[str, Any]:
|
def _list_files(name: str) -> dict[str, Any]:
|
||||||
db = _get_db()
|
db = _get_db()
|
||||||
files = db.list_project_files(name)
|
files = db.list_project_files(name)
|
||||||
|
|||||||
+12
-3
@@ -67,6 +67,13 @@ def _fetch_json(url: str) -> dict:
|
|||||||
return {"error": "parse_error", "message": str(e)}
|
return {"error": "parse_error", "message": str(e)}
|
||||||
|
|
||||||
|
|
||||||
|
def _fetch_project(manager_url: str, project: str) -> dict:
|
||||||
|
"""Fetch project details (including folder_path) from the NiceGUI REST API."""
|
||||||
|
p = urllib.parse.quote(project, safe='')
|
||||||
|
url = f"{manager_url.rstrip('/')}/api/projects/{p}"
|
||||||
|
return _fetch_json(url)
|
||||||
|
|
||||||
|
|
||||||
def _fetch_data(manager_url: str, project: str, file: str, seq: int) -> dict:
|
def _fetch_data(manager_url: str, project: str, file: str, seq: int) -> dict:
|
||||||
"""Fetch sequence data from the NiceGUI REST API."""
|
"""Fetch sequence data from the NiceGUI REST API."""
|
||||||
p = urllib.parse.quote(project, safe='')
|
p = urllib.parse.quote(project, safe='')
|
||||||
@@ -221,14 +228,16 @@ class ProjectSource:
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
RETURN_TYPES = ("INT", "STRING",)
|
RETURN_TYPES = ("INT", "STRING", "STRING")
|
||||||
RETURN_NAMES = ("sequence_number", "file_name",)
|
RETURN_NAMES = ("sequence_number", "file_name", "project_path")
|
||||||
FUNCTION = "hold_config"
|
FUNCTION = "hold_config"
|
||||||
CATEGORY = "JSON Manager/project"
|
CATEGORY = "JSON Manager/project"
|
||||||
OUTPUT_NODE = True
|
OUTPUT_NODE = True
|
||||||
|
|
||||||
def hold_config(self, manager_url, project_name, file_name, sequence_number, label):
|
def hold_config(self, manager_url, project_name, file_name, sequence_number, label):
|
||||||
return (sequence_number, file_name,)
|
proj = _fetch_project(manager_url, project_name)
|
||||||
|
folder_path = proj.get("folder_path", "") if "error" not in proj else ""
|
||||||
|
return (sequence_number, file_name, folder_path)
|
||||||
|
|
||||||
|
|
||||||
class ProjectKey:
|
class ProjectKey:
|
||||||
|
|||||||
Reference in New Issue
Block a user