From cc64a3e49e63cf91be3df35fb8f4657d8253be5a Mon Sep 17 00:00:00 2001 From: LidolLxf <130628034+LidolLxf@users.noreply.github.com> Date: Wed, 27 Nov 2024 18:56:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20webconsole=20=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=98=BE=E7=A4=BA=E6=96=87=E4=BB=B6=E5=A4=A7?= =?UTF-8?q?=E5=B0=8F=20(#3615)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: webconsole 文件列表显示文件大小 * feat: webconsole 文件列表显示文件大小优化 --- .../console/repository/bkrepo.go | 10 +++++--- .../bcs-webconsole/console/repository/cos.go | 10 +++++--- .../bcs-webconsole/console/repository/repo.go | 8 +++++- .../bcs-webconsole/console/web/service.go | 2 +- .../console/web/templates/replay.html | 25 ++++++++++++++++++- 5 files changed, 46 insertions(+), 9 deletions(-) diff --git a/bcs-services/bcs-webconsole/console/repository/bkrepo.go b/bcs-services/bcs-webconsole/console/repository/bkrepo.go index 1fdc6e5ac2..16552e10a5 100644 --- a/bcs-services/bcs-webconsole/console/repository/bkrepo.go +++ b/bcs-services/bcs-webconsole/console/repository/bkrepo.go @@ -22,6 +22,7 @@ import ( "os" "github.com/Tencent/bk-bcs/bcs-common/common/blog" + "github.com/dustin/go-humanize" "github.com/Tencent/bk-bcs/bcs-services/bcs-webconsole/console/config" ) @@ -112,7 +113,7 @@ func (b *bkrepoStorage) IsExist(ctx context.Context, filePath string) (bool, err } // ListFile list of files under a bkRepo folder -func (b *bkrepoStorage) ListFile(ctx context.Context, folderName string) ([]string, error) { +func (b *bkrepoStorage) ListFile(ctx context.Context, folderName string) ([]FileContent, error) { // 节点详情 https://github.com/TencentBlueKing/bk-repo/blob/master/docs/apidoc/node/node.md // GET /repository/api/node/page/{projectId}/{repoName}/{fullPath} // 目前一天最多一千条,pageSize限制为1000条 @@ -120,7 +121,7 @@ func (b *bkrepoStorage) ListFile(ctx context.Context, folderName string) ([]stri config.G.Repository.Bkrepo.Endpoint, config.G.Repository.Bkrepo.Project, config.G.Repository.Bkrepo.Repo, folderName) - files := make([]string, 0) + var files []FileContent req, err := http.NewRequestWithContext(ctx, http.MethodGet, rawURL, nil) if err != nil { return files, err @@ -143,7 +144,10 @@ func (b *bkrepoStorage) ListFile(ctx context.Context, folderName string) ([]stri for _, record := range listResult.Data.Records { if !record.Folder { - files = append(files, record.Name) + files = append(files, FileContent{ + FileName: record.Name, + ProcessedSize: humanize.Bytes(uint64(record.Size)), + }) } } return files, nil diff --git a/bcs-services/bcs-webconsole/console/repository/cos.go b/bcs-services/bcs-webconsole/console/repository/cos.go index 1b97926dc8..f60a488fbe 100644 --- a/bcs-services/bcs-webconsole/console/repository/cos.go +++ b/bcs-services/bcs-webconsole/console/repository/cos.go @@ -22,6 +22,7 @@ import ( "os" "strings" + "github.com/dustin/go-humanize" "github.com/tencentyun/cos-go-sdk-v5" "github.com/Tencent/bk-bcs/bcs-services/bcs-webconsole/console/config" @@ -56,7 +57,7 @@ func (c *cosStorage) UploadFileByReader(ctx context.Context, r io.Reader, filePa } // ListFile list current folder files -func (c *cosStorage) ListFile(ctx context.Context, folderName string) ([]string, error) { +func (c *cosStorage) ListFile(ctx context.Context, folderName string) ([]FileContent, error) { var marker string folderName = strings.Trim(folderName, "/") folderName += "/" @@ -66,7 +67,7 @@ func (c *cosStorage) ListFile(ctx context.Context, folderName string) ([]string, MaxKeys: 200, // 设置最大遍历出多少个对象, 一次 listobject 最大支持1000 } - files := make([]string, 0) + var files []FileContent isTruncated := true for isTruncated { opt.Marker = marker @@ -79,7 +80,10 @@ func (c *cosStorage) ListFile(ctx context.Context, folderName string) ([]string, } for _, content := range v.Contents { fn := strings.TrimPrefix(content.Key, folderName) - files = append(files, fn) + files = append(files, FileContent{ + FileName: fn, + ProcessedSize: humanize.Bytes(uint64(content.Size)), + }) } isTruncated = v.IsTruncated // 是否还有数据 marker = v.NextMarker // 设置下次请求的起始 key diff --git a/bcs-services/bcs-webconsole/console/repository/repo.go b/bcs-services/bcs-webconsole/console/repository/repo.go index 8d62e5cc5f..c8dc4bfd91 100644 --- a/bcs-services/bcs-webconsole/console/repository/repo.go +++ b/bcs-services/bcs-webconsole/console/repository/repo.go @@ -23,7 +23,7 @@ import ( type Provider interface { UploadFile(ctx context.Context, localFile, filePath string) error UploadFileByReader(ctx context.Context, r io.Reader, filePath string) error - ListFile(ctx context.Context, folderName string) ([]string, error) + ListFile(ctx context.Context, folderName string) ([]FileContent, error) ListFolders(ctx context.Context, folderName string) ([]string, error) DeleteFolders(ctx context.Context, folderName string) error IsExist(ctx context.Context, filePath string) (bool, error) @@ -43,3 +43,9 @@ func NewProvider(providerType string) (Provider, error) { return nil, fmt.Errorf("repo provider %s is not supported", providerType) } } + +// FileContent repo file content +type FileContent struct { + FileName string + ProcessedSize string +} diff --git a/bcs-services/bcs-webconsole/console/web/service.go b/bcs-services/bcs-webconsole/console/web/service.go index f13973d2a0..d764871967 100644 --- a/bcs-services/bcs-webconsole/console/web/service.go +++ b/bcs-services/bcs-webconsole/console/web/service.go @@ -86,7 +86,7 @@ func (s *service) ReplayFilesPageHandler(c *gin.Context) { } // 按照时间逆序排 sort.Slice(fileNames, func(i, j int) bool { - return fileNames[i] > fileNames[j] + return fileNames[i].FileName > fileNames[j].FileName }) data := gin.H{ "folder_name": folderName, diff --git a/bcs-services/bcs-webconsole/console/web/templates/replay.html b/bcs-services/bcs-webconsole/console/web/templates/replay.html index 70e761f79a..788136cd39 100644 --- a/bcs-services/bcs-webconsole/console/web/templates/replay.html +++ b/bcs-services/bcs-webconsole/console/web/templates/replay.html @@ -17,10 +17,33 @@