Skip to content

Commit 15651a4

Browse files
committed
feat: only show files (close AlistGo#735)
1 parent 7be476c commit 15651a4

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

model/meta.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import (
66
)
77

88
type Meta struct {
9-
ID uint `json:"id" gorm:"primaryKey"`
10-
Path string `json:"path" gorm:"unique" binding:"required"`
11-
Password string `json:"password"`
12-
Hide string `json:"hide"`
13-
Upload bool `json:"upload"`
9+
ID uint `json:"id" gorm:"primaryKey"`
10+
Path string `json:"path" gorm:"unique" binding:"required"`
11+
Password string `json:"password"`
12+
Hide string `json:"hide"`
13+
Upload bool `json:"upload"`
14+
OnlyShows string `json:"only_shows"`
1415
}
1516

1617
func GetMetaByPath(path string) (*Meta, error) {

server/common/common.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@ func SuccessResp(c *gin.Context, data ...interface{}) {
8888
}
8989

9090
func Hide(meta *model.Meta, files []model.File) []model.File {
91-
//meta, _ := model.GetMetaByPath(path)
92-
if meta != nil && meta.Hide != "" {
91+
if meta == nil {
92+
return files
93+
}
94+
if meta.Hide != "" {
9395
tmpFiles := make([]model.File, 0)
9496
hideFiles := strings.Split(meta.Hide, ",")
9597
for _, item := range files {
@@ -99,5 +101,15 @@ func Hide(meta *model.Meta, files []model.File) []model.File {
99101
}
100102
files = tmpFiles
101103
}
104+
if meta.OnlyShows != "" {
105+
tmpFiles := make([]model.File, 0)
106+
showFiles := strings.Split(meta.OnlyShows, ",")
107+
for _, item := range files {
108+
if utils.IsContain(showFiles, item.Name) {
109+
tmpFiles = append(tmpFiles, item)
110+
}
111+
}
112+
files = tmpFiles
113+
}
102114
return files
103115
}

0 commit comments

Comments
 (0)