Skip to content

Commit

Permalink
feat: add header to meta (ref #5317)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Oct 2, 2023
1 parent e719a1a commit 9ff83a7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
22 changes: 12 additions & 10 deletions internal/model/meta.go
@@ -1,14 +1,16 @@
package model

type Meta struct {
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"`
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"`
Header string `json:"header"`
HeaderSub bool `json:"header_sub"`
}
11 changes: 11 additions & 0 deletions server/handles/fsread.go
Expand Up @@ -49,6 +49,7 @@ type FsListResp struct {
Content []ObjResp `json:"content"`
Total int64 `json:"total"`
Readme string `json:"readme"`
Header string `json:"header"`
Write bool `json:"write"`
Provider string `json:"provider"`
}
Expand Down Expand Up @@ -97,6 +98,7 @@ func FsList(c *gin.Context) {
Content: toObjsResp(objs, reqPath, isEncrypt(meta, reqPath)),
Total: int64(total),
Readme: getReadme(meta, reqPath),
Header: getHeader(meta, reqPath),
Write: user.CanWrite() || common.CanWrite(meta, reqPath),
Provider: provider,
})
Expand Down Expand Up @@ -169,6 +171,13 @@ func getReadme(meta *model.Meta, path string) string {
return ""
}

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

func isEncrypt(meta *model.Meta, path string) bool {
if common.IsStorageSignEnabled(path) {
return true
Expand Down Expand Up @@ -225,6 +234,7 @@ type FsGetResp struct {
ObjResp
RawURL string `json:"raw_url"`
Readme string `json:"readme"`
Header string `json:"header"`
Provider string `json:"provider"`
Related []ObjResp `json:"related"`
}
Expand Down Expand Up @@ -328,6 +338,7 @@ func FsGet(c *gin.Context) {
},
RawURL: rawURL,
Readme: getReadme(meta, reqPath),
Header: getHeader(meta, reqPath),
Provider: provider,
Related: toObjsResp(related, parentPath, isEncrypt(parentMeta, parentPath)),
})
Expand Down

0 comments on commit 9ff83a7

Please sign in to comment.