Opt: gen default path

pull/47/head
zijiren233 3 years ago
parent a343a7cad5
commit a7d00ba712

@ -42,7 +42,6 @@ func List(ctx *gin.Context) {
return
}
req.Path = strings.TrimRight(req.Path, "/")
if !strings.HasPrefix(req.Path, "/") {
req.Path = "/" + req.Path
}
@ -79,20 +78,10 @@ func List(ctx *gin.Context) {
return
}
var resp model.VendorFSListResp
resp.Total = data.Total
if req.Path == "/" {
req.Path = ""
}
for i, v := range strings.Split(req.Path, `/`) {
var p = v
if i != 0 {
p = fmt.Sprintf("%s/%s", resp.Paths[i-1].Path, v)
}
resp.Paths = append(resp.Paths, &model.Path{
Name: v,
Path: p,
})
req.Path = strings.TrimRight(req.Path, "/")
resp := model.VendorFSListResp{
Total: data.Total,
Paths: model.GenDefaultPaths(req.Path),
}
for _, flr := range data.Content {
resp.Items = append(resp.Items, &model.Item{

@ -1,5 +1,10 @@
package model
import (
"fmt"
"strings"
)
type VendorMeResp[T any] struct {
IsLogin bool `json:"isLogin"`
Info T `json:"info,omitempty"`
@ -11,13 +16,32 @@ type VendorFSListResp struct {
Total uint64 `json:"total"`
}
type Item struct {
Name string `json:"name"`
Path string `json:"path"`
IsDir bool `json:"isDir"`
func GenDefaultPaths(path string) []*Path {
paths := []*Path{}
path = strings.TrimRight(path, "/")
for i, v := range strings.Split(path, `/`) {
if i != 0 {
paths = append(paths, &Path{
Name: v,
Path: fmt.Sprintf("%s/%s", paths[i-1].Path, v),
})
} else {
paths = append(paths, &Path{
Name: v,
Path: v,
})
}
}
return paths
}
type Path struct {
Name string `json:"name"`
Path string `json:"path"`
}
type Item struct {
Name string `json:"name"`
Path string `json:"path"`
IsDir bool `json:"isDir"`
}

Loading…
Cancel
Save