feat: 获取文件列表按时间排序近到远

This commit is contained in:
TsMask
2025-06-27 11:05:15 +08:00
parent f293304eec
commit 2787c544bb
2 changed files with 11 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ package ssh
import ( import (
"fmt" "fmt"
"sort"
"strings" "strings"
"be.ems/src/framework/cmd" "be.ems/src/framework/cmd"
@@ -99,5 +100,10 @@ func FileList(sshClient *ConnSSH, path, search string) ([]FileListRow, error) {
FileName: fileName, FileName: fileName,
}) })
} }
// 按时间排序
sort.Slice(rows, func(i, j int) bool {
return rows[i].ModifiedTime > rows[j].ModifiedTime
})
return rows, nil return rows, nil
} }

View File

@@ -3,6 +3,7 @@ package file
import ( import (
"os" "os"
"path/filepath" "path/filepath"
"sort"
) )
// FileListRow 文件列表行数据 // FileListRow 文件列表行数据
@@ -74,5 +75,9 @@ func FileList(path, search string) ([]FileListRow, error) {
}) })
} }
// 按时间排序
sort.Slice(rows, func(i, j int) bool {
return rows[i].ModifiedTime > rows[j].ModifiedTime
})
return rows, nil return rows, nil
} }