feat(file-check): 增加文件检核 Excel 下载链接解析与展示功能
This commit is contained in:
1 parent
5e7e5a8717
commit
f21216f81e
21 files changed
+885
-125
No files matched your search
@@ -1,23 +1,42 @@
|
||||
"""
|
||||
backend/app/services/hxops_tool_api.py
|
||||
文件用途:解析 HXOPS 对外 Tool API 基地址(Dify Chatflow / OpenAPI / 签名下载链接)。
|
||||
|
||||
用途:解析 HXOPS 两类对外基地址——Dify Tool API(服务端)与用户浏览器访问(下载链等)。
|
||||
依赖:Flask current_app / request。
|
||||
逻辑:Dify/RPA 调 Tool API 走 resolve_HXOPS_TOOLS_API_BASE;用户可见下载链走 resolve_hxops_user_facing_base_url。
|
||||
"""
|
||||
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 {}
|
||||
def _resolve_config(config: dict | None = None) -> dict:
|
||||
"""读取 Flask config 或空 dict。"""
|
||||
if config is not None:
|
||||
return config
|
||||
if current_app:
|
||||
return current_app.config
|
||||
return {}
|
||||
|
||||
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
|
||||
|
||||
def resolve_HXOPS_TOOLS_API_BASE(*, config: dict | None = None, request_host: str | None = None) -> str:
|
||||
"""
|
||||
返回 Dify / RPA 等服务端调用 Tool API 时使用的根地址(无尾斜杠)。
|
||||
|
||||
核心逻辑:仅读 HXOPS_TOOLS_API_BASE(常为内网 IP),与浏览器下载链、PUBLIC_BASE_URL 分离。
|
||||
|
||||
Args:
|
||||
config: 可选配置字典;缺省时读 current_app.config。
|
||||
request_host: 可选请求 host_url;缺省且在请求上下文中时取 request.host_url。
|
||||
|
||||
Returns:
|
||||
无尾斜杠的根地址,如 http://192.168.100.192:8890。
|
||||
"""
|
||||
cfg = _resolve_config(config)
|
||||
|
||||
configured = str(cfg.get("HXOPS_TOOLS_API_BASE") or "").strip().rstrip("/")
|
||||
if configured:
|
||||
return configured
|
||||
|
||||
host = request_host
|
||||
if host is None and has_request_context():
|
||||
@@ -25,3 +44,26 @@ def resolve_HXOPS_TOOLS_API_BASE(*, config: dict | None = None, request_host: st
|
||||
return host or ""
|
||||
|
||||
|
||||
def resolve_hxops_user_facing_base_url(*, config: dict | None = None) -> str:
|
||||
"""
|
||||
返回浏览器侧可访问的根地址,用于 Excel 签名下载等用户可见链接。
|
||||
|
||||
核心逻辑:仅读 HXOPS_PUBLIC_BASE_URL / WECOM_PUBLIC_BASE_URL,不复用 Tool API 内网地址或通知地址。
|
||||
|
||||
Args:
|
||||
config: 可选配置字典;缺省时读 current_app.config。
|
||||
|
||||
Returns:
|
||||
无尾斜杠的根地址,如 https://ai.example.com。
|
||||
"""
|
||||
cfg = _resolve_config(config)
|
||||
|
||||
for key in ("HXOPS_PUBLIC_BASE_URL", "WECOM_PUBLIC_BASE_URL"):
|
||||
configured = str(cfg.get(key) or "").strip().rstrip("/")
|
||||
if configured:
|
||||
return configured
|
||||
|
||||
if has_request_context():
|
||||
return request.host_url.rstrip("/")
|
||||
|
||||
return resolve_HXOPS_TOOLS_API_BASE(config=cfg)
|
||||
Reference in new issue
Block a user