This commit is contained in:
Your Name
2026-04-17 15:13:46 +08:00
parent fe87c7b343
commit 0e096947fc
19 changed files with 791 additions and 151 deletions

View File

@@ -11,6 +11,31 @@ def domain_root() -> Path:
return Path(settings.domain_root)
def resolve_domain_path(*relative_paths: str) -> Path | None:
root = domain_root()
candidates: list[Path] = []
seen: set[str] = set()
for relative_path in relative_paths:
text = str(relative_path or "").strip()
if not text:
continue
candidate = root / text
candidate_key = str(candidate)
if candidate_key not in seen:
seen.add(candidate_key)
candidates.append(candidate)
if "/" not in text and "\\" not in text:
nested_candidate = root / "logs" / text
nested_key = str(nested_candidate)
if nested_key not in seen:
seen.add(nested_key)
candidates.append(nested_candidate)
for candidate in candidates:
if candidate.exists():
return candidate
return candidates[0] if candidates else None
def read_json(relative_path: str, default: dict | list | None = None):
path = domain_root() / relative_path
if not path.exists():
@@ -30,8 +55,8 @@ def write_json(relative_path: str, payload) -> None:
def tail_lines(relative_path: str, max_lines: int = 120) -> list[str]:
path = domain_root() / relative_path
if not path.exists():
path = resolve_domain_path(relative_path)
if path is None or not path.exists():
return []
with path.open("r", encoding="utf-8", errors="replace") as handle:
return handle.read().splitlines()[-max_lines:]