From 80d98dd135e163489fef11153b88c2d71f44cc02 Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Tue, 16 Nov 2021 11:25:43 +0800 Subject: [PATCH] sort model by time desc --- modules/storage/obs.go | 4 ++++ routers/repo/cloudbrain.go | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/modules/storage/obs.go b/modules/storage/obs.go index c25787703..acf660e56 100755 --- a/modules/storage/obs.go +++ b/modules/storage/obs.go @@ -8,6 +8,7 @@ import ( "io" "net/url" "path" + "sort" "strconv" "strings" @@ -222,6 +223,9 @@ func GetObsListObject(jobName, parentDir string) ([]FileInfo, error) { } fileInfos = append(fileInfos, fileInfo) } + sort.Slice(fileInfos, func(i, j int) bool { + return fileInfos[i].ModTime > fileInfos[j].ModTime + }) return fileInfos, err } else { if obsError, ok := err.(obs.ObsError); ok { diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index a344ee69c..1e1f7bf38 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -10,6 +10,7 @@ import ( "os" "os/exec" "regexp" + "sort" "strconv" "strings" "time" @@ -533,6 +534,10 @@ func CloudBrainShowModels(ctx *context.Context) { fileInfos[i].ModTime = temp.Local().Format("2006-01-02 15:04:05") } + sort.Slice(fileInfos, func(i, j int) bool { + return fileInfos[i].ModTime > fileInfos[j].ModTime + }) + ctx.Data["Path"] = dirArray ctx.Data["Dirs"] = fileInfos ctx.Data["task"] = task