import os import shutil import tempfile from pathlib import Path from typing import Optional, Tuple def get_config_dir() -> Path: """Return the user configuration directory for hunyuan3dweb.""" xdg = os.environ.get("XDG_CONFIG_HOME") base = Path(xdg) if xdg else Path.home() / ".config" path = base / "hunyuan3dweb" path.mkdir(parents=True, exist_ok=True) return path def get_cookie_path() -> Path: """Return the path to the cookies file.""" return get_config_dir() / "cookies.txt" def get_profile_dir() -> Path: """Return the path to the browser profile directory.""" path = get_config_dir() / "profile" path.mkdir(parents=True, exist_ok=True) return path def prepare_profile_dir() -> Tuple[str, Optional[str]]: """ 将标准 profile 复制到临时目录,避免 Chromium 锁冲突。 Returns: (实际使用的 profile 路径, 临时目录路径或 None)。 如果使用了临时副本,调用者应在完成后用 shutil.rmtree 删除。 """ standard = str(get_profile_dir()) if not os.path.exists(standard): return standard, None temp_root = tempfile.mkdtemp(prefix="hunyuan3dweb-profile-") temp_profile = os.path.join(temp_root, "profile") shutil.copytree(standard, temp_profile, dirs_exist_ok=True) return temp_profile, temp_root