From 9ff83a795008d4a3aaaaf0b904087a868b462a84 Mon Sep 17 00:00:00 2001 From: Andy Hsu Date: Mon, 2 Oct 2023 16:43:29 +0800 Subject: [PATCH] feat: add `header` to `meta` (ref #5317) --- internal/model/meta.go | 22 ++++++++++++---------- server/handles/fsread.go | 11 +++++++++++ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/internal/model/meta.go b/internal/model/meta.go index afbdb63fcd7..0446137a2c0 100644 --- a/internal/model/meta.go +++ b/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"` } diff --git a/server/handles/fsread.go b/server/handles/fsread.go index efc93574fa8..7c580f635e4 100644 --- a/server/handles/fsread.go +++ b/server/handles/fsread.go @@ -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"` } @@ -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, }) @@ -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 @@ -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"` } @@ -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)), })