Files

28 lines
897 B
Python

"""
backend/app/services/hxops_tool_api.py
文件用途:解析 HXOPS 对外 Tool API 基地址(Dify Chatflow / OpenAPI / 签名下载链接)。
"""
from __future__ import annotations
from flask import current_app, has_request_context, request
def resolve_HXOPS_TOOLS_API_BASE(*, config: dict | None = None, request_host: str | None = None) -> str:
"""返回无尾斜杠的 hxops 对外根地址,如 http://192.168.100.192:8891。"""
cfg = config
if cfg is None and current_app:
cfg = current_app.config
cfg = cfg or {}
for key in ("HXOPS_TOOLS_API_BASE", "HXOPS_TOOLS_API_BASE", "PUBLIC_BASE_URL"):
configured = str(cfg.get(key) or "").strip().rstrip("/")
if configured:
return configured
host = request_host
if host is None and has_request_context():
host = request.host_url.rstrip("/")
return host or ""