Skip to content

Commit

Permalink
feat: only show files (close #735)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Mar 13, 2022
1 parent 7be476c commit 15651a4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
11 changes: 6 additions & 5 deletions model/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 14 additions & 2 deletions server/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

0 comments on commit 15651a4

Please sign in to comment.