From 5496c776df19eb5cbc391f407ca7b8c723b219ab Mon Sep 17 00:00:00 2001 From: Rogee Date: Sun, 4 Jan 2026 18:21:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E5=99=A8=20UI=20=E5=92=8C=E6=96=87=E4=BB=B6=E5=90=8D=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=EF=BC=8C=E6=94=AF=E6=8C=81=E5=85=A8=E5=B1=8F=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/services/common.go | 18 ++++++++++++------ backend/app/services/creator.go | 15 +++++++++++++-- backend/database/fields/media_assets.go | 1 + frontend/portal/src/layout/LayoutCreator.vue | 12 ++++++------ 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/backend/app/services/common.go b/backend/app/services/common.go index 604f428..67584e0 100644 --- a/backend/app/services/common.go +++ b/backend/app/services/common.go @@ -248,7 +248,8 @@ func (s *common) CompleteUpload(ctx context.Context, userID int64, form *common_ ObjectKey: objectKey, Hash: hash, Meta: types.NewJSONType(fields.MediaAssetMeta{ - Size: totalSize, + Filename: meta.Filename, + Size: totalSize, }), } } @@ -384,7 +385,8 @@ func (s *common) Upload( ObjectKey: objectKey, Hash: hash, Meta: types.NewJSONType(fields.MediaAssetMeta{ - Size: size, + Filename: file.Filename, + Size: size, }), } } @@ -398,10 +400,14 @@ func (s *common) Upload( func (s *common) composeUploadResult(asset *models.MediaAsset) *common_dto.UploadResult { url := s.GetAssetURL(asset.ObjectKey) - filename := filepath.Base(asset.ObjectKey) - // Try to get original filename if stored? Currently objectKey has UUID prefix. - // We can store original filename in Meta if needed. For now, just return valid result. - // Meta is JSONType wrapper. + filename := asset.Meta.Data().Filename + if filename == "" { + filename = filepath.Base(asset.ObjectKey) + // Try to strip UUID prefix (36 chars + 1 underscore = 37) + if len(filename) > 37 && filename[36] == '_' { + filename = filename[37:] + } + } size := asset.Meta.Data().Size return &common_dto.UploadResult{ diff --git a/backend/app/services/creator.go b/backend/app/services/creator.go index 84a8128..9ef6ba6 100644 --- a/backend/app/services/creator.go +++ b/backend/app/services/creator.go @@ -370,7 +370,18 @@ func (s *creator) GetContent(ctx context.Context, userID int64, id string) (*cre for _, ca := range c.ContentAssets { if ca.Asset != nil { - sizeBytes := ca.Asset.Meta.Data().Size + meta := ca.Asset.Meta.Data() + name := meta.Filename + if name == "" { + // Fallback: strip UUID prefix (36 chars + 1 underscore = 37) + if len(ca.Asset.ObjectKey) > 37 && ca.Asset.ObjectKey[36] == '_' { + name = ca.Asset.ObjectKey[37:] + } else { + name = ca.Asset.ObjectKey + } + } + + sizeBytes := meta.Size sizeMB := float64(sizeBytes) / 1024.0 / 1024.0 sizeStr := cast.ToString(float64(int(sizeMB*100))/100.0) + " MB" @@ -379,7 +390,7 @@ func (s *creator) GetContent(ctx context.Context, userID int64, id string) (*cre Role: string(ca.Role), Type: string(ca.Asset.Type), URL: Common.GetAssetURL(ca.Asset.ObjectKey), - Name: ca.Asset.ObjectKey, // Simple fallback + Name: name, Size: sizeStr, Sort: int(ca.Sort), }) diff --git a/backend/database/fields/media_assets.go b/backend/database/fields/media_assets.go index d74f534..c5789aa 100644 --- a/backend/database/fields/media_assets.go +++ b/backend/database/fields/media_assets.go @@ -2,6 +2,7 @@ package fields // MediaAssetMeta 媒体资源元数据 type MediaAssetMeta struct { + Filename string `json:"filename,omitempty"` Hash string `json:"hash,omitempty"` Duration float64 `json:"duration,omitempty"` // 秒 Width int `json:"width,omitempty"` diff --git a/frontend/portal/src/layout/LayoutCreator.vue b/frontend/portal/src/layout/LayoutCreator.vue index 6b1896f..79c7fef 100644 --- a/frontend/portal/src/layout/LayoutCreator.vue +++ b/frontend/portal/src/layout/LayoutCreator.vue @@ -1,8 +1,8 @@