From 6598821e190f56b93fe2388f913c9d6013cd6307 Mon Sep 17 00:00:00 2001 From: zouap Date: Tue, 9 Nov 2021 15:04:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- modules/storage/obs.go | 10 +++++++++- routers/repo/ai_model_manage.go | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/modules/storage/obs.go b/modules/storage/obs.go index f22bc1dda..115fbdc45 100755 --- a/modules/storage/obs.go +++ b/modules/storage/obs.go @@ -286,9 +286,17 @@ func GetAllObsListObjectUnderDir(bucket string, prefix string) ([]FileInfo, erro input.Prefix = prefix output, err := ObsCli.ListObjects(input) fileInfos := make([]FileInfo, 0) + prefixLen := len(prefix) + 1 if err == nil { for _, val := range output.Contents { var isDir bool + if val.Key == prefix { + continue + } + log.Info("sub str=" + val.Key[prefixLen:]) + if strings.Contains(val.Key[prefixLen:], "/") { + continue + } if strings.HasSuffix(val.Key, "/") { isDir = true } else { @@ -296,7 +304,7 @@ func GetAllObsListObjectUnderDir(bucket string, prefix string) ([]FileInfo, erro } fileInfo := FileInfo{ ModTime: val.LastModified.Format("2006-01-02 15:04:05"), - FileName: val.Key[len(prefix)+1:], + FileName: val.Key[prefixLen:], Size: val.Size, IsDir: isDir, ParenDir: "", diff --git a/routers/repo/ai_model_manage.go b/routers/repo/ai_model_manage.go index ad6f52aef..949c33bb3 100644 --- a/routers/repo/ai_model_manage.go +++ b/routers/repo/ai_model_manage.go @@ -214,7 +214,7 @@ func DownloadSingleModelFile(ctx *context.Context) { func ShowSingleModel(ctx *context.Context) { id := ctx.Params(":ID") - parentDir := ctx.Query("parentDir") + //parentDir := ctx.Query("parentDir") log.Info("Show single ModelInfo start.id=" + id) task, err := models.QueryModelById(id) if err != nil { @@ -223,7 +223,7 @@ func ShowSingleModel(ctx *context.Context) { return } log.Info("bucket=" + setting.Bucket + " key=" + task.Path[len(setting.Bucket)+1:]) - models, err := storage.GetObsListObjectByBucketAndPrefix(setting.Bucket, task.Path[len(setting.Bucket)+1:], parentDir) + models, err := storage.GetAllObsListObjectUnderDir(setting.Bucket, task.Path[len(setting.Bucket)+1:]) if err != nil { log.Info("get model list failed:", err) ctx.ServerError("GetObsListObject:", err)