left4me/l4d2web/services/workshop_paths.py
mwiegand f0230e17d3
feat(l4d2-web): overlay path helpers and creation
Adds workshop_paths.cache_path(steam_id) returning
$LEFT4ME_ROOT/workshop_cache/{steam_id}.vpk with digit-only validation.

Adds overlay_creation.generate_overlay_path(id) and
create_overlay_directory(overlay) with exist_ok=False so a stray dir from a
prior failed delete surfaces loudly instead of shadowing fresh content.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 16:38:39 +02:00

24 lines
686 B
Python

"""Cache-path helpers for workshop content.
The cache lives at `$LEFT4ME_ROOT/workshop_cache/{steam_id}.vpk`. Steam IDs
are validated digit-only here so callers don't need to guard separately.
"""
from __future__ import annotations
import re
from pathlib import Path
from l4d2host.paths import get_left4me_root
_NUMERIC_ID_RE = re.compile(r"^\d+$")
def workshop_cache_root() -> Path:
return get_left4me_root() / "workshop_cache"
def cache_path(steam_id: str) -> Path:
if not isinstance(steam_id, str) or not _NUMERIC_ID_RE.fullmatch(steam_id):
raise ValueError(f"steam_id must be digits only: {steam_id!r}")
return workshop_cache_root() / f"{steam_id}.vpk"