Skip to content

Commit

Permalink
feat: add readme field to list resp
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Jun 30, 2022
1 parent e614faa commit 35b04ff
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion internal/fs/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func whetherHide(user *model.User, meta *model.Meta, path string) bool {
return false
}
// if meta doesn't apply to sub_folder, don't hide
if !utils.PathEqual(meta.Path, path) && !meta.SubFolder {
if !utils.PathEqual(meta.Path, path) && !meta.HSub {
return false
}
// if is guest, hide
Expand Down
17 changes: 10 additions & 7 deletions internal/model/meta.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package model

type Meta struct {
ID uint `json:"id" gorm:"primaryKey"`
Path string `json:"path" gorm:"unique" binding:"required"`
Password string `json:"password"`
Write bool `json:"upload"`
Hide string `json:"hide"`
SubFolder bool `json:"sub_folder"`
Readme string `json:"readme"`
ID uint `json:"id" gorm:"primaryKey"`
Path string `json:"path" gorm:"unique" binding:"required"`
Password string `json:"password"`
PSub bool `json:"p_sub"`
Write bool `json:"write"`
WSub bool `json:"w_sub"`
Hide string `json:"hide"`
HSub bool `json:"h_sub"`
Readme string `json:"readme"`
RSub bool `json:"r_sub"`
}
2 changes: 1 addition & 1 deletion server/controllers/fsmanage.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func canMkdirOrPut(meta *model.Meta, path string) bool {
if meta == nil || !meta.Write {
return false
}
return meta.SubFolder || meta.Path == path
return meta.WSub || meta.Path == path
}

type MoveCopyReq struct {
Expand Down
11 changes: 10 additions & 1 deletion server/controllers/fsread.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type ObjResp struct {
type FsListResp struct {
Content []ObjResp `json:"content"`
Total int64 `json:"total"`
Readme string `json:"readme"`
}

func FsList(c *gin.Context) {
Expand Down Expand Up @@ -66,9 +67,17 @@ func FsList(c *gin.Context) {
common.SuccessResp(c, FsListResp{
Content: toObjResp(objs),
Total: int64(total),
Readme: getReadme(meta, req.Path),
})
}

func getReadme(meta *model.Meta, path string) string {
if meta != nil && (utils.PathEqual(meta.Path, path) || meta.RSub) {
return meta.Readme
}
return ""
}

func canAccess(user *model.User, meta *model.Meta, path string, password string) bool {
// if is not guest, can access
if user.CanAccessWithoutPassword() {
Expand All @@ -79,7 +88,7 @@ func canAccess(user *model.User, meta *model.Meta, path string, password string)
return true
}
// if meta doesn't apply to sub_folder, can access
if !utils.PathEqual(meta.Path, path) && !meta.SubFolder {
if !utils.PathEqual(meta.Path, path) && !meta.PSub {
return true
}
// validate password
Expand Down
2 changes: 1 addition & 1 deletion server/middlewares/down.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func needSign(meta *model.Meta, path string) bool {
if meta == nil || meta.Password == "" {
return false
}
if !meta.SubFolder && path != meta.Path {
if !meta.PSub && path != meta.Path {
return false
}
return true
Expand Down

0 comments on commit 35b04ff

Please sign in to comment.