fix(module-compiler): dynamically resolve content repo path and eliminate hardcoded user workstation path

This commit is contained in:
Urvish Prajapati 2026-11-23 12:28:56 +05:30
parent a4d37fcf1a
commit 4c52d6278f
1 changed files with 56 additions and 6 deletions

View File

@ -4,6 +4,7 @@ import copy
import io import io
import json import json
import logging import logging
import os
import re import re
import zipfile import zipfile
from datetime import datetime, timezone from datetime import datetime, timezone
@ -18,9 +19,54 @@ from app.db.models import BuilderCategory, BuilderDisease, BuilderModule, Builde
logger = logging.getLogger("acupedia.builder.compiler") logger = logging.getLogger("acupedia.builder.compiler")
DEFAULT_CONTENT_REPO_PATH = Path(
"/home/cspl/urvish/CSPL/Panacea/acupedia_content/acupedia-content" def get_default_content_repo_path() -> Path:
) """Dynamically resolves the content repository path without machine-specific hardcoded paths."""
# 1. Environment variables
for env_var in ("ACUPEDIA_CONTENT_PATH", "CONTENT_PATH", "MODULES_ROOT"):
val = os.getenv(env_var)
if val:
p = Path(val).resolve()
if p.exists() and p.is_dir():
return p
# 2. Docker container standard mount (/app/content)
container_mount = Path("/app/content")
if container_mount.exists() and container_mount.is_dir():
return container_mount
# 3. Dynamic search relative to this source file repository
current_file = Path(__file__).resolve()
for parent in current_file.parents:
candidates = [
parent / "acupedia_content" / "acupedia-content",
parent / "acupedia-content",
parent / "acupedia_content",
parent / "content",
]
for candidate in candidates:
if candidate.exists() and (candidate / "config.json").exists():
return candidate
if candidate.exists() and candidate.is_dir() and (candidate / "modules").exists():
return candidate
# 4. Search relative to current working directory
cwd = Path.cwd().resolve()
for candidate in [
cwd / "acupedia_content" / "acupedia-content",
cwd.parent / "acupedia_content" / "acupedia-content",
cwd / "acupedia-content",
cwd.parent / "acupedia-content",
cwd / "content",
]:
if candidate.exists() and candidate.is_dir():
return candidate
# Fallback relative to project structure
try:
return current_file.parents[5] / "acupedia_content" / "acupedia-content"
except IndexError:
return cwd / "content"
class ModuleContentCompiler: class ModuleContentCompiler:
@ -474,11 +520,15 @@ class ModuleContentCompiler:
repo_root: Path | None = None, repo_root: Path | None = None,
) -> dict[str, Any]: ) -> dict[str, Any]:
module, files = await self.compile_module(module_code) module, files = await self.compile_module(module_code)
target_root = repo_root or DEFAULT_CONTENT_REPO_PATH target_root = repo_root or get_default_content_repo_path()
if not target_root.exists(): if not target_root.exists():
raise HTTPException( raise HTTPException(
status_code=500, status_code=400,
detail=f"Content repository directory not found at: {target_root}", detail=(
f"Content repository directory not found on server (checked: {target_root}). "
"Please configure the CONTENT_PATH environment variable, or use 'Download Acupedia (.zip)' "
"from the Export menu to download the production bundle directly to your computer."
),
) )
module_folder_name = f"{module.code}-{module.slug}" module_folder_name = f"{module.code}-{module.slug}"