diff --git a/model/meta.go b/model/meta.go index fb3f4d3a3eb..06cbae1c33d 100644 --- a/model/meta.go +++ b/model/meta.go @@ -6,11 +6,12 @@ import ( ) type Meta struct { - ID uint `json:"id" gorm:"primaryKey"` - Path string `json:"path" gorm:"unique" binding:"required"` - Password string `json:"password"` - Hide string `json:"hide"` - Upload bool `json:"upload"` + ID uint `json:"id" gorm:"primaryKey"` + Path string `json:"path" gorm:"unique" binding:"required"` + Password string `json:"password"` + Hide string `json:"hide"` + Upload bool `json:"upload"` + OnlyShows string `json:"only_shows"` } func GetMetaByPath(path string) (*Meta, error) { diff --git a/server/common/common.go b/server/common/common.go index 60294cbb9d6..8abc198475a 100644 --- a/server/common/common.go +++ b/server/common/common.go @@ -88,8 +88,10 @@ func SuccessResp(c *gin.Context, data ...interface{}) { } func Hide(meta *model.Meta, files []model.File) []model.File { - //meta, _ := model.GetMetaByPath(path) - if meta != nil && meta.Hide != "" { + if meta == nil { + return files + } + if meta.Hide != "" { tmpFiles := make([]model.File, 0) hideFiles := strings.Split(meta.Hide, ",") for _, item := range files { @@ -99,5 +101,15 @@ func Hide(meta *model.Meta, files []model.File) []model.File { } files = tmpFiles } + if meta.OnlyShows != "" { + tmpFiles := make([]model.File, 0) + showFiles := strings.Split(meta.OnlyShows, ",") + for _, item := range files { + if utils.IsContain(showFiles, item.Name) { + tmpFiles = append(tmpFiles, item) + } + } + files = tmpFiles + } return files }