remove browser version management
This commit is contained in:
@@ -36,7 +36,6 @@ from ..platform.douyin import (
|
||||
from ..platform.xiaohongshu import XiaohongshuBrowser, is_xiaohongshu_share_url
|
||||
from ..proxy import ProxyExit
|
||||
from ..runtime import (
|
||||
BROWSER_VERSION_RE,
|
||||
BrowserRuntimeError,
|
||||
NativeRuntimeManager,
|
||||
has_control,
|
||||
@@ -124,7 +123,6 @@ class Gateway:
|
||||
return {
|
||||
"service": "browser-gateway",
|
||||
"node_id": self.node_id,
|
||||
"browser_versions": sorted(self.runtimes.browser_versions),
|
||||
}
|
||||
|
||||
def create(self, input: dict) -> dict:
|
||||
@@ -1232,28 +1230,6 @@ def _integer(env: Mapping[str, str], key: str, default: int) -> int:
|
||||
raise ValueError(f"{key} must be an integer") from exc
|
||||
|
||||
|
||||
def _browser_versions(env: Mapping[str, str], default_version: str, default_path: str) -> dict[str, str]:
|
||||
result = {default_version: default_path}
|
||||
raw = env.get("BROWSER_VERSION_PATHS", "").strip()
|
||||
if raw:
|
||||
try:
|
||||
decoded = json.loads(raw)
|
||||
except json.JSONDecodeError as exc:
|
||||
raise ValueError("BROWSER_VERSION_PATHS must be a JSON object") from exc
|
||||
if not isinstance(decoded, dict) or not decoded:
|
||||
raise ValueError("BROWSER_VERSION_PATHS must be a non-empty JSON object")
|
||||
result = {}
|
||||
for version, path in decoded.items():
|
||||
if not isinstance(version, str) or not BROWSER_VERSION_RE.fullmatch(version):
|
||||
raise ValueError("BROWSER_VERSION_PATHS contains an invalid version")
|
||||
if not isinstance(path, str) or not os.path.isabs(os.path.expanduser(path)):
|
||||
raise ValueError("BROWSER_VERSION_PATHS contains a non-absolute path")
|
||||
result[version] = os.path.abspath(os.path.expanduser(path))
|
||||
if default_version not in result:
|
||||
result[default_version] = default_path
|
||||
return result
|
||||
|
||||
|
||||
def load_config(env: Mapping[str, str] | None = None) -> dict:
|
||||
env = os.environ if env is None else env
|
||||
listen = env.get("LISTEN_ADDR", "0.0.0.0:8081").strip()
|
||||
@@ -1264,7 +1240,6 @@ def load_config(env: Mapping[str, str] | None = None) -> dict:
|
||||
profile_root = os.path.abspath(os.path.expanduser(env.get(
|
||||
"BROWSER_PROFILE_ROOT", "~/.local/share/creatorhub/browser-profiles"
|
||||
).strip()))
|
||||
browser_version = env.get("BROWSER_VERSION", "148.0.7778.215").strip()
|
||||
browser_path = os.path.abspath(os.path.expanduser(env.get(
|
||||
"BROWSER_PATH",
|
||||
"~/.local/share/creatorhub/browsers/fingerprint-chromium/148.0.7778.215/chrome",
|
||||
@@ -1276,8 +1251,6 @@ def load_config(env: Mapping[str, str] | None = None) -> dict:
|
||||
raise ValueError("GATEWAY_TOKEN must be at least 16 characters")
|
||||
if not state_dir or not profile_root or not os.path.isabs(state_dir) or not os.path.isabs(profile_root):
|
||||
raise ValueError("BROWSER_STATE_DIR and BROWSER_PROFILE_ROOT must be absolute")
|
||||
if not BROWSER_VERSION_RE.fullmatch(browser_version):
|
||||
raise ValueError("BROWSER_VERSION is invalid")
|
||||
if not node_id:
|
||||
node_id = ""
|
||||
elif not re.fullmatch(r"^[a-z0-9][a-z0-9._-]{0,63}$", node_id):
|
||||
@@ -1286,21 +1259,18 @@ def load_config(env: Mapping[str, str] | None = None) -> dict:
|
||||
raise ValueError("NODE_NAME is invalid")
|
||||
if not 1 <= port <= 65535:
|
||||
raise ValueError("LISTEN_ADDR port must be 1..65535")
|
||||
versions = _browser_versions(env, browser_version, browser_path)
|
||||
external_display = _optional_positive_int(env, "RUNTIME_EXTERNAL_DISPLAY")
|
||||
for version, path in versions.items():
|
||||
try:
|
||||
available = os.path.isfile(path) and os.access(path, os.X_OK)
|
||||
except (OSError, TypeError) as exc:
|
||||
raise ValueError(f"browser version {version} is unavailable") from exc
|
||||
if not available:
|
||||
raise ValueError(f"browser version {version} is unavailable")
|
||||
try:
|
||||
available = os.path.isfile(browser_path) and os.access(browser_path, os.X_OK)
|
||||
except (OSError, TypeError) as exc:
|
||||
raise ValueError("browser executable is unavailable") from exc
|
||||
if not available:
|
||||
raise ValueError("browser executable is unavailable")
|
||||
return {
|
||||
"listen": (host, port),
|
||||
"state_dir": state_dir,
|
||||
"profile_root": profile_root,
|
||||
"browser_versions": versions,
|
||||
"browser_version": browser_version,
|
||||
"browser_path": browser_path,
|
||||
"node_id": node_id,
|
||||
"node_name": node_name,
|
||||
"token": token,
|
||||
@@ -1367,7 +1337,7 @@ def run() -> None:
|
||||
state_dir=config["state_dir"],
|
||||
profile_root=config["profile_root"],
|
||||
node_id=node_id,
|
||||
browser_versions=config["browser_versions"],
|
||||
browser_path=config["browser_path"],
|
||||
cleanup_timeout=config["cleanup_timeout"],
|
||||
ready_timeout=config["ready_timeout"],
|
||||
min_free_bytes=config["min_free_bytes"],
|
||||
@@ -1384,7 +1354,7 @@ def run() -> None:
|
||||
"node_id": node_id,
|
||||
"node_name": config["node_name"],
|
||||
"listen_addr": f"{config['listen'][0]}:{config['listen'][1]}",
|
||||
"browser_version": config["browser_version"],
|
||||
"browser_path": config["browser_path"],
|
||||
"external_display": config["external_display"],
|
||||
},
|
||||
ensure_ascii=False,
|
||||
|
||||
Reference in New Issue
Block a user