feat: only show files (close #735)

pull/761/head v2.2.0
Xhofe 2022-03-13 19:37:58 +08:00
parent 7be476cce0
commit 15651a4356
2 changed files with 20 additions and 7 deletions

View File

@ -11,6 +11,7 @@ type Meta struct {
Password string `json:"password"` Password string `json:"password"`
Hide string `json:"hide"` Hide string `json:"hide"`
Upload bool `json:"upload"` Upload bool `json:"upload"`
OnlyShows string `json:"only_shows"`
} }
func GetMetaByPath(path string) (*Meta, error) { func GetMetaByPath(path string) (*Meta, error) {

View File

@ -88,8 +88,10 @@ func SuccessResp(c *gin.Context, data ...interface{}) {
} }
func Hide(meta *model.Meta, files []model.File) []model.File { func Hide(meta *model.Meta, files []model.File) []model.File {
//meta, _ := model.GetMetaByPath(path) if meta == nil {
if meta != nil && meta.Hide != "" { return files
}
if meta.Hide != "" {
tmpFiles := make([]model.File, 0) tmpFiles := make([]model.File, 0)
hideFiles := strings.Split(meta.Hide, ",") hideFiles := strings.Split(meta.Hide, ",")
for _, item := range files { for _, item := range files {
@ -99,5 +101,15 @@ func Hide(meta *model.Meta, files []model.File) []model.File {
} }
files = tmpFiles 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 return files
} }