fix: add _resolve_precon_dir() auto-detection so CFG.precon_dir is not empty
The precon deck list was missing after the monolith refactor because PRECON_DIR was hardcoded in services/precon_service.py with no CLI arg, env var, or auto-resolve fallback — unlike forge_jar, forge_dir, etc. Changes: - Add precon_dir field to Config class (models/state.py) - Add --precon-dir CLI arg and PRECON_DIR env var support - Add _resolve_precon_dir() with project-root, parent-dir, and forge_dir-relative detection; creates dir as fallback for downloads - Refactor precon_service.py to use _get_precon_dir() helper that reads CFG.precon_dir at runtime instead of a hardcoded module-level Path - Update routes/precon.py to use _get_precon_dir() for install endpoints - Wire _on_startup to resolve precon_dir for uvicorn-direct launches - Remove unused PRECON_DIR/PRECON_INDEX imports from routes/lab.py - Audit confirms all other CFG path fields already have fallbacks
This commit is contained in:
1 parent
a5b9d70f04
commit
fbc3bdb6b5
6 files changed
+61
-10
No files matched your search
@@ -38,8 +38,6 @@ from routes.shared import (
|
||||
StartResponse,
|
||||
StatusResponse,
|
||||
AI_PROFILES,
|
||||
PRECON_DIR,
|
||||
PRECON_INDEX,
|
||||
build_java_command,
|
||||
run_batch_subprocess,
|
||||
_run_deepseek_batch_thread,
|
||||
|
||||
+4
-3
@@ -16,7 +16,8 @@ from pathlib import Path
|
||||
from fastapi import APIRouter, HTTPException
|
||||
|
||||
import routes.shared as _shared # module reference, not value import
|
||||
from routes.shared import CFG, PRECON_DIR, download_precon_database, log
|
||||
from routes.shared import CFG, download_precon_database, log
|
||||
from services.precon_service import _get_precon_dir
|
||||
|
||||
router = APIRouter(tags=["precon"])
|
||||
|
||||
@@ -36,7 +37,7 @@ async def install_precon(req: dict):
|
||||
if not file_name:
|
||||
raise HTTPException(400, "fileName is required")
|
||||
|
||||
src = PRECON_DIR / file_name
|
||||
src = _get_precon_dir() / file_name
|
||||
if not src.exists():
|
||||
raise HTTPException(404, f"Precon not found: {file_name}")
|
||||
|
||||
@@ -71,7 +72,7 @@ async def install_precons_batch(req: dict):
|
||||
|
||||
results = []
|
||||
for file_name in file_names:
|
||||
src = PRECON_DIR / file_name
|
||||
src = _get_precon_dir() / file_name
|
||||
if not src.exists():
|
||||
results.append({"fileName": file_name, "installed": False, "error": "not found"})
|
||||
continue
|
||||
|
||||
@@ -186,6 +186,7 @@ from services.import_service import (
|
||||
from services.precon_service import (
|
||||
PRECON_DIR, PRECON_INDEX, GITHUB_PRECON_URL, PRECON_CACHE_HOURS,
|
||||
load_precon_index, _sanitize_filename, _deck_to_dck, download_precon_database,
|
||||
_get_precon_dir,
|
||||
)
|
||||
|
||||
# ══════════════════════════════════════════════════════════════
|
||||
|
||||
Reference in new issue
Block a user