fix(backend): harden final MVP invariants
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"log"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -14,15 +15,15 @@ import (
|
||||
"senlinai-agent/backend/internal/models"
|
||||
)
|
||||
|
||||
// SourceDTO 是文件资料写接口的稳定响应,仅包含可公开的相对存储路径。
|
||||
// SourceDTO 是文件资料写接口的稳定响应,仅返回 opaque storage key,不暴露物理目录布局。
|
||||
type SourceDTO struct {
|
||||
ID string `json:"id"`
|
||||
ProjectID string `json:"projectId"`
|
||||
Kind string `json:"kind"`
|
||||
Title string `json:"title"`
|
||||
FilePath string `json:"filePath"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
ID string `json:"id"`
|
||||
ProjectID string `json:"projectId"`
|
||||
Kind string `json:"kind"`
|
||||
Title string `json:"title"`
|
||||
StorageKey string `json:"storageKey"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
||||
// Handler 负责 multipart 边界,文件名清理和本地路径构造始终委托给 Service。
|
||||
@@ -84,7 +85,7 @@ func (h *Handler) upload(c *gin.Context) {
|
||||
defer file.Close()
|
||||
|
||||
// 先由文件服务保存内容,再用其返回的相对路径创建资料记录;handler 不拼接任何本地路径。
|
||||
stored, err := h.service.Save(project.ID, fileHeader.Filename, file)
|
||||
stored, err := h.service.Save(project.Identity, fileHeader.Filename, file)
|
||||
if err != nil {
|
||||
httpx.Error(c, http.StatusInternalServerError, "internal_error", "文件保存失败")
|
||||
return
|
||||
@@ -104,7 +105,7 @@ func (h *Handler) upload(c *gin.Context) {
|
||||
func sourceDTO(source models.SenlinAgentSource) SourceDTO {
|
||||
return SourceDTO{
|
||||
ID: source.Identity, ProjectID: source.ProjectIdentity, Kind: source.Kind,
|
||||
Title: source.Title, FilePath: source.FilePath,
|
||||
Title: source.Title, StorageKey: filepath.Base(filepath.FromSlash(source.FilePath)),
|
||||
CreatedAt: source.CreatedAt.UTC(), UpdatedAt: source.UpdatedAt.UTC(),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user