feat: return project-relative workspace mapping in query responses
This commit is contained in:
@@ -28,6 +28,8 @@ class Settings(BaseSettings):
|
||||
|
||||
xdg_cache_home: Path = Path("/var/lib/qmd/cache")
|
||||
xdg_config_home: Path = Path("/var/lib/qmd/config")
|
||||
container_data_root: Path = Path("/data")
|
||||
project_data_relative_root: str = "data"
|
||||
|
||||
@model_validator(mode="after")
|
||||
def _normalize_paths(self) -> "Settings":
|
||||
|
||||
@@ -57,7 +57,7 @@ class QueryService:
|
||||
return QueryResponse(
|
||||
ok=True,
|
||||
branch=sync_meta.branch,
|
||||
resolved_workspace=str(sync_meta.workspace_path),
|
||||
resolved_workspace=sync_meta.workspace_relative_path,
|
||||
commit_hash=sync_meta.commit_hash,
|
||||
synced_at=sync_meta.synced_at,
|
||||
query_type=request.query_type,
|
||||
@@ -90,7 +90,7 @@ class QueryService:
|
||||
return SyncResponse(
|
||||
ok=True,
|
||||
branch=sync_meta.branch,
|
||||
resolved_workspace=str(sync_meta.workspace_path),
|
||||
resolved_workspace=sync_meta.workspace_relative_path,
|
||||
commit_hash=sync_meta.commit_hash,
|
||||
synced_at=sync_meta.synced_at,
|
||||
qmd_collection=sync_meta.qmd_collection,
|
||||
|
||||
@@ -18,6 +18,7 @@ class SyncMetadata:
|
||||
branch: str
|
||||
workspace_name: str
|
||||
workspace_path: Path
|
||||
workspace_relative_path: str
|
||||
qmd_collection: str
|
||||
qmd_index: str
|
||||
commit_hash: str
|
||||
@@ -118,6 +119,7 @@ class SyncService:
|
||||
branch=resolved.branch,
|
||||
workspace_name=resolved.workspace_name,
|
||||
workspace_path=resolved.workspace_path,
|
||||
workspace_relative_path=self._to_project_relative_path(resolved.workspace_path),
|
||||
qmd_collection=resolved.qmd_collection,
|
||||
qmd_index=resolved.qmd_index,
|
||||
commit_hash=git_sync.commit_hash,
|
||||
@@ -147,6 +149,7 @@ class SyncService:
|
||||
"branch": metadata.branch,
|
||||
"workspace": metadata.workspace_name,
|
||||
"workspace_path": str(metadata.workspace_path),
|
||||
"workspace_relative_path": metadata.workspace_relative_path,
|
||||
"qmd_collection": metadata.qmd_collection,
|
||||
"qmd_index": metadata.qmd_index,
|
||||
"commit_hash": metadata.commit_hash,
|
||||
@@ -159,3 +162,10 @@ class SyncService:
|
||||
"synced_at": metadata.synced_at.isoformat(),
|
||||
}
|
||||
path.write_text(json.dumps(payload, ensure_ascii=True, indent=2), encoding="utf-8")
|
||||
|
||||
def _to_project_relative_path(self, path: Path) -> str:
|
||||
try:
|
||||
rel = path.relative_to(self.settings.container_data_root)
|
||||
return str(Path(self.settings.project_data_relative_root) / rel)
|
||||
except ValueError:
|
||||
return str(path)
|
||||
|
||||
Reference in New Issue
Block a user