fix(im): rewrite private storage URLs to HTTP in IM channel replies

IM platforms (Feishu, Slack, Telegram, DingTalk, Mattermost, WeCom) cannot
render provider:// URLs (local://, minio://, s3://, etc.) that appear in
LLM answers containing knowledge base images. The web frontend handles
these via the authenticated /files endpoint, but IM clients need publicly
resolvable HTTP URLs.

Changes:
- Add HMAC-SHA256 presigned URL utility (internal/utils/presign.go) for
  generating time-limited, signature-verified file access URLs
- Add GET /api/v1/files/presigned endpoint that serves files without
  session auth, verified by HMAC signature and expiry
- Update localFileService.GetFileURL() to return presigned HTTP URLs
  when APP_EXTERNAL_URL is configured (cloud backends already return
  presigned URLs via their SDKs)
- Add IM content rewriting pipeline: strip <image> XML tags, strip
  citation tags, rewrite storage URLs to HTTP — applied at all IM
  output points (streaming flush, non-streaming reply, fallback)
- Add holdback buffer in streaming flush to prevent URL/tag splitting
  across chunk boundaries

Closes #1058
This commit is contained in:
wizardchen
2026-04-28 20:22:04 +08:00
committed by lyingbug
parent 8c62a066af
commit 7fd566bc15
11 changed files with 727 additions and 39 deletions
+5
View File
@@ -148,6 +148,11 @@ APP_PORT=8080
# 远程部署如后端为 HTTPS,需设为 https
# APP_SCHEME=http
# 应用外部访问地址(用于 IM 渠道中生成图片等文件的可访问链接)
# 设置为 WeKnora 实例的外部可访问 URL,如 https://weknora.example.com
# 不设置时,IM 渠道中本地存储的图片将无法正常显示(云存储不受影响)
# APP_EXTERNAL_URL=
# 前端服务端口,默认为80
FRONTEND_PORT=80