fix(im): make presigned URL flow diagnosable end-to-end

When IM image rendering breaks, operators previously had no log line to
correlate against the IM platform's fetch attempt. Add observability
hooks on both ends and unblock HEAD probes so common IM previews work
at all.

- log rewriteStorageURLs success/failure/no-op with the full signed URL
  (operators can copy it from logs and verify public reachability)
- log presigned handler 4xx with client_ip + UA + tenant_id + file_path
  so failures correlate against IM platform fetch logs; use the request
  context so trace IDs are preserved
- accept HEAD on /api/v1/files/presigned: IM platforms (Feishu, Slack
  etc.) probe with HEAD before GET when rendering image previews, and a
  401 there is enough to break the inline image even when the GET would
  have succeeded
- add Admin-only GET /api/v1/files/presigned-preview that returns the
  exact URL an IM channel would embed for the calling tenant, for
  self-service verification without sending a real IM message
- clarify APP_EXTERNAL_URL and MINIO_ENDPOINT public-reachability rules
  in .env.example; misconfigured endpoints are the most common cause of
  "image broken in IM" reports
This commit is contained in:
wizardchen
2026-05-27 20:50:20 +08:00
committed by lyingbug
parent f5820c13ac
commit ae4ec0cf06
5 changed files with 395 additions and 23 deletions
+15 -3
View File
@@ -169,9 +169,16 @@ APP_PORT=8080
# 远程部署如后端为 HTTPS,需设为 https
# APP_SCHEME=http
# 应用外部访问地址(用于 IM 渠道中生成图片等文件的可访问链接)
# 设置为 WeKnora 实例的外部可访问 URL,如 https://weknora.example.com
# 不设置时,IM 渠道中本地存储的图片将无法正常显示(云存储不受影响)
# 应用外部访问地址(仅影响 IM 渠道中 local 后端的图片/文件链接)
# 设置为 WeKnora 实例的「IM 平台 / 客户端公网可达」URL,如 https://weknora.example.com
#
# 作用范围:
# - local 后端:必须设置,否则 IM 收到的是 local://... 路径,无法渲染
# - MinIO/COS/OSS/S3/TOS/OBS/KS3:不读取此变量;它们的链接由各自 SDK 生成,
# host 由对应的 *_ENDPOINT 决定,同样必须公网可达
#
# 内网 IP(192.168.x / 10.x / 172.16-31.x)和 localhost 对飞书 / 企微 / Slack
# 等 IM 平台服务器都不可达;本地开发请用 ngrok / cloudflared / frp 之类的隧道。
# APP_EXTERNAL_URL=
# 前端服务端口,默认为80
@@ -312,6 +319,11 @@ CONCURRENCY_POOL_SIZE=5
# 如果使用MinIO作为文件存储,需要配置以下参数
# MinIO访问端点(host:port),连接外部MinIO时需修改
#
# 重要:用于 IM 渠道时,MINIO_ENDPOINT 必须是 IM 平台 / 客户端公网可达的 host。
# MinIO SDK 生成的 presigned URL 直接使用这个 host,飞书 / 企微 / Slack 等都
# 无法解析 docker-compose 的内部服务名 minio:9000,会导致 IM 中图片不显示。
# 推荐做法:配置一个公网域名(如 minio.example.com)并启用 HTTPS。
# MINIO_ENDPOINT=minio:9000
# MinIO访问密钥