fix(report): 报告源/产物落 MinIO,去掉 gateway↔mcp-go 本地盘耦合
多机/容器化第一时间断裂的隐患(ARCHITECTURE_REVIEW §7 #1):此前报告 源(reportStore)与 .docx 产物(reportExport/reportRender)都写 mcp-go 本地 SUNDYNIX_REPORTS_DIR,gateway 再按同一路径 c.File 回流——mcp-go 与 gateway 不共享磁盘即断。 - blob 包从 gateway/internal 提到 sundynix-shared/blob,gateway 与 mcp-go 共用同一 MinIO;新增 PutBytes/GetBytes 走二进制(.docx)。 - mcp-go 注入 blob:report 源/产物优先 Put 到对象存储(键 reports/<id>.{json,docx}), 导出结果返回 minio://<key>;MinIO 未就绪回退本地盘(单机降级,getSource 兼容旧本地报告)。 - gateway ExportReport 识别 minio:// → GetBytes 流式下载,否则 c.File 本地降级。 - 测试:mcp 本地回落往返单测 + shared/blob 真 MinIO 二进制往返(BLOB_TEST_ENDPOINT 门控)。 四模块 build 绿,受影响测试全过。 - 附带:go mod tidy 引入 genproto 拆包冲突,四模块统一钉单体 genproto 新版解决 (注:勿 go work sync,会剪掉 indirect require 回落旧版重现冲突)。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -18,7 +18,7 @@ import (
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"github.com/sundynix/sundynix-gateway/internal/blob"
|
||||
"github.com/sundynix/sundynix-shared/blob"
|
||||
"github.com/sundynix/sundynix-gateway/internal/nats"
|
||||
"github.com/sundynix/sundynix-gateway/internal/store"
|
||||
"github.com/sundynix/sundynix-shared/contract"
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
@@ -72,10 +73,25 @@ func (h *Handler) ExportReport(c *gin.Context) {
|
||||
c.Header("Content-Disposition", `attachment; filename="`+id+`.md"`)
|
||||
c.Header("Content-Type", "text/markdown; charset=utf-8")
|
||||
c.String(http.StatusOK, res.Content)
|
||||
default: // docx:res.Content 为 mcp-go 落盘的 .docx 路径
|
||||
default: // docx:res.Content 为 minio://<key>(对象存储,跨机可取)或本地路径(单机降级)
|
||||
const docxMime = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
||||
c.Header("Content-Disposition", `attachment; filename="`+id+`.docx"`)
|
||||
c.Header("Content-Type", "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
|
||||
c.File(res.Content)
|
||||
c.Header("Content-Type", docxMime)
|
||||
if key, ok := strings.CutPrefix(res.Content, contract.BlobScheme); ok {
|
||||
// 对象存储:从 MinIO 流式取回,不依赖 gateway 与 mcp-go 共享本地盘。
|
||||
if h.blob == nil || !h.blob.Ready() {
|
||||
c.JSON(http.StatusBadGateway, gin.H{"error": "对象存储不可用,无法下载报告"})
|
||||
return
|
||||
}
|
||||
data, gerr := h.blob.GetBytes(c.Request.Context(), key)
|
||||
if gerr != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "报告产物已过期或不存在"})
|
||||
return
|
||||
}
|
||||
c.Data(http.StatusOK, docxMime, data)
|
||||
return
|
||||
}
|
||||
c.File(res.Content) // 本地路径:单机/共享卷降级
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
"github.com/gin-contrib/sse"
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"github.com/sundynix/sundynix-gateway/internal/blob"
|
||||
"github.com/sundynix/sundynix-shared/blob"
|
||||
"github.com/sundynix/sundynix-gateway/internal/dsl"
|
||||
"github.com/sundynix/sundynix-gateway/internal/nats"
|
||||
"github.com/sundynix/sundynix-gateway/internal/payment"
|
||||
|
||||
Reference in New Issue
Block a user