mirror of https://github.com/Xhofe/alist
feat: add readme field to list resp
parent
e614faa99b
commit
35b04ffa9c
|
@ -59,7 +59,7 @@ func whetherHide(user *model.User, meta *model.Meta, path string) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
// if meta doesn't apply to sub_folder, don't hide
|
// 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
|
return false
|
||||||
}
|
}
|
||||||
// if is guest, hide
|
// if is guest, hide
|
||||||
|
|
|
@ -4,8 +4,11 @@ type Meta struct {
|
||||||
ID uint `json:"id" gorm:"primaryKey"`
|
ID uint `json:"id" gorm:"primaryKey"`
|
||||||
Path string `json:"path" gorm:"unique" binding:"required"`
|
Path string `json:"path" gorm:"unique" binding:"required"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
Write bool `json:"upload"`
|
PSub bool `json:"p_sub"`
|
||||||
|
Write bool `json:"write"`
|
||||||
|
WSub bool `json:"w_sub"`
|
||||||
Hide string `json:"hide"`
|
Hide string `json:"hide"`
|
||||||
SubFolder bool `json:"sub_folder"`
|
HSub bool `json:"h_sub"`
|
||||||
Readme string `json:"readme"`
|
Readme string `json:"readme"`
|
||||||
|
RSub bool `json:"r_sub"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ func canMkdirOrPut(meta *model.Meta, path string) bool {
|
||||||
if meta == nil || !meta.Write {
|
if meta == nil || !meta.Write {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return meta.SubFolder || meta.Path == path
|
return meta.WSub || meta.Path == path
|
||||||
}
|
}
|
||||||
|
|
||||||
type MoveCopyReq struct {
|
type MoveCopyReq struct {
|
||||||
|
|
|
@ -34,6 +34,7 @@ type ObjResp struct {
|
||||||
type FsListResp struct {
|
type FsListResp struct {
|
||||||
Content []ObjResp `json:"content"`
|
Content []ObjResp `json:"content"`
|
||||||
Total int64 `json:"total"`
|
Total int64 `json:"total"`
|
||||||
|
Readme string `json:"readme"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func FsList(c *gin.Context) {
|
func FsList(c *gin.Context) {
|
||||||
|
@ -66,9 +67,17 @@ func FsList(c *gin.Context) {
|
||||||
common.SuccessResp(c, FsListResp{
|
common.SuccessResp(c, FsListResp{
|
||||||
Content: toObjResp(objs),
|
Content: toObjResp(objs),
|
||||||
Total: int64(total),
|
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 {
|
func canAccess(user *model.User, meta *model.Meta, path string, password string) bool {
|
||||||
// if is not guest, can access
|
// if is not guest, can access
|
||||||
if user.CanAccessWithoutPassword() {
|
if user.CanAccessWithoutPassword() {
|
||||||
|
@ -79,7 +88,7 @@ func canAccess(user *model.User, meta *model.Meta, path string, password string)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
// if meta doesn't apply to sub_folder, can access
|
// 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
|
return true
|
||||||
}
|
}
|
||||||
// validate password
|
// validate password
|
||||||
|
|
|
@ -47,7 +47,7 @@ func needSign(meta *model.Meta, path string) bool {
|
||||||
if meta == nil || meta.Password == "" {
|
if meta == nil || meta.Password == "" {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if !meta.SubFolder && path != meta.Path {
|
if !meta.PSub && path != meta.Path {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
|
Loading…
Reference in New Issue