[#137] Add index page support
Some checks failed
/ DCO (pull_request) Successful in 1m1s
/ Builds (pull_request) Successful in 55s
/ Lint (pull_request) Failing after 1m22s
/ Tests (pull_request) Successful in 57s
/ Vulncheck (pull_request) Successful in 1m28s

Signed-off-by: Nikita Zinkevich <n.zinkevich@yadro.com>
This commit is contained in:
Nikita Zinkevich 2024-09-30 12:16:04 +03:00
parent 585971ebf7
commit 20f3ba6879
3 changed files with 9 additions and 18 deletions

View file

@ -187,12 +187,6 @@ func (s *appSettings) IndexPageEnabled() bool {
return s.returnIndexPage return s.returnIndexPage
} }
func (s *appSettings) IndexPageTemplatePath() string {
s.mu.RLock()
defer s.mu.RUnlock()
return s.indexPageTemplatePath
}
func (s *appSettings) IndexPageTemplate() string { func (s *appSettings) IndexPageTemplate() string {
s.mu.RLock() s.mu.RLock()
defer s.mu.RUnlock() defer s.mu.RUnlock()
@ -211,12 +205,6 @@ func (s *appSettings) setReturnIndexPage(val bool) {
s.mu.Unlock() s.mu.Unlock()
} }
func (s *appSettings) setIndexTemplatePath(val string) {
s.mu.Lock()
s.indexPageTemplatePath = val
s.mu.Unlock()
}
func (s *appSettings) setIndexTemplate(val string) { func (s *appSettings) setIndexTemplate(val string) {
s.mu.Lock() s.mu.Lock()
s.indexPageTemplate = val s.indexPageTemplate = val
@ -227,7 +215,7 @@ func (a *app) loadIndexPageTemplate() {
if !a.settings.IndexPageEnabled() { if !a.settings.IndexPageEnabled() {
return return
} }
reader, err := os.Open(a.settings.IndexPageTemplatePath()) reader, err := os.Open(a.cfg.GetString(cfgIndexPageTemplatePath))
if err != nil { if err != nil {
a.settings.setIndexTemplate("") a.settings.setIndexTemplate("")
a.log.Warn(logs.FailedToReadIndexPageTemplate, zap.Error(err)) a.log.Warn(logs.FailedToReadIndexPageTemplate, zap.Error(err))
@ -560,7 +548,6 @@ func (a *app) updateSettings() {
a.settings.setDefaultTimestamp(a.cfg.GetBool(cfgUploaderHeaderEnableDefaultTimestamp)) a.settings.setDefaultTimestamp(a.cfg.GetBool(cfgUploaderHeaderEnableDefaultTimestamp))
a.settings.setZipCompression(a.cfg.GetBool(cfgZipCompression)) a.settings.setZipCompression(a.cfg.GetBool(cfgZipCompression))
a.settings.setReturnIndexPage(a.cfg.GetBool(cfgIndexPageEnabled)) a.settings.setReturnIndexPage(a.cfg.GetBool(cfgIndexPageEnabled))
a.settings.setIndexTemplatePath(a.cfg.GetString(cfgIndexPageTemplatePath))
a.settings.setClientCut(a.cfg.GetBool(cfgClientCut)) a.settings.setClientCut(a.cfg.GetBool(cfgClientCut))
a.settings.setBufferMaxSizeForPut(a.cfg.GetUint64(cfgBufferMaxSizeForPut)) a.settings.setBufferMaxSizeForPut(a.cfg.GetUint64(cfgBufferMaxSizeForPut))
a.settings.setNamespaceHeader(a.cfg.GetString(cfgResolveNamespaceHeader)) a.settings.setNamespaceHeader(a.cfg.GetString(cfgResolveNamespaceHeader))

View file

@ -18,8 +18,11 @@ import (
) )
const ( const (
dateFormat = "02-01-2006 15:04" dateFormat = "02-01-2006 15:04"
attrOID, attrCreated, attrFileName, attrSize = "OID", "Created", "FileName", "Size" attrOID = "OID"
attrCreated = "Created"
attrFileName = "FileName"
attrSize = "Size"
) )
type ( type (
@ -110,7 +113,7 @@ func urlencode(prefix, filename, size, created string) string {
} }
func (h *Handler) browseObjects(c *fasthttp.RequestCtx, bucketInfo *data.BucketInfo, prefix string) { func (h *Handler) browseObjects(c *fasthttp.RequestCtx, bucketInfo *data.BucketInfo, prefix string) {
var log = h.log.With(zap.String("bucket", bucketInfo.Name)) log := h.log.With(zap.String("bucket", bucketInfo.Name))
ctx := utils.GetContextFromRequest(c) ctx := utils.GetContextFromRequest(c)
nodes, err := h.listObjects(ctx, bucketInfo, prefix) nodes, err := h.listObjects(ctx, bucketInfo, prefix)
if err != nil { if err != nil {
@ -119,6 +122,7 @@ func (h *Handler) browseObjects(c *fasthttp.RequestCtx, bucketInfo *data.BucketI
} }
respObjects := make([]ResponseObject, len(nodes)) respObjects := make([]ResponseObject, len(nodes))
for i, node := range nodes { for i, node := range nodes {
respObjects[i] = NewResponseObject(node) respObjects[i] = NewResponseObject(node)
} }

View file

@ -31,7 +31,6 @@ type Config interface {
ZipCompression() bool ZipCompression() bool
ClientCut() bool ClientCut() bool
IndexPageEnabled() bool IndexPageEnabled() bool
IndexPageTemplatePath() string
IndexPageTemplate() string IndexPageTemplate() string
BufferMaxSizeForPut() uint64 BufferMaxSizeForPut() uint64
NamespaceHeader() string NamespaceHeader() string
@ -235,6 +234,7 @@ func (h *Handler) byObjectName(c *fasthttp.RequestCtx, f func(context.Context, r
if h.config.IndexPageEnabled() && !download && string(c.Method()) != fasthttp.MethodHead { if h.config.IndexPageEnabled() && !download && string(c.Method()) != fasthttp.MethodHead {
if isDir(unescapedKey) || isContainerRoot(unescapedKey) { if isDir(unescapedKey) || isContainerRoot(unescapedKey) {
c.SetStatusCode(fasthttp.StatusNotFound)
h.browseObjects(c, bktInfo, unescapedKey) h.browseObjects(c, bktInfo, unescapedKey)
return return
} }