Skip to content

Commit

Permalink
refactor: Update S3 breadcrumbs in index.html template
Browse files Browse the repository at this point in the history
  • Loading branch information
tttol committed Jul 1, 2024
1 parent fee8235 commit dac544f
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 9 deletions.
2 changes: 1 addition & 1 deletion core/util/breadcrumbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
func GenerateBreadcrumbs(path string) map[string]interface{} {
breadcrumbs := make(map[string]interface{})
parts := strings.Split(path, "/")
fullPath := ""
fullPath := "/s3"
for i, part := range parts {
if part == "" {
continue
Expand Down
2 changes: 0 additions & 2 deletions core/util/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ func GenerateS3Objects(r *http.Request, path string) ([]model.S3Object, error) {
obj.Name = entry.Name()
obj.FullPath = filepath.Join(r.URL.Path, entry.Name())
obj.IsDir = entry.IsDir()
slog.Info("S3Object", "data", obj)

s3Objects = append(s3Objects, obj)
}
slog.Info("S3Objects", "data", s3Objects)

return s3Objects, nil
}
8 changes: 3 additions & 5 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
<div class="mx-auto w-3/4 p-3 bg-emerald-800 rounded-xl">
<div class="flex justify-between">
<div class="text-lg">
<a href="/s3" class="text-cyan-400 underline-offset-2 hover:opacity-60">s3://</a>
{{range .}}
{{if .IsDir}}
<span> / <a href="{{.FullPath}}" class="text-cyan-400 underline-offset-2 hover:opacity-60">{{.Name}}</a></span>
{{end}}
<a href="/s3" class="text-cyan-400 underline-offset-2 hover:opacity-60">s3:</a>
{{range $key, $value := .Breadcrumbs}}
<span> / <a href="{{$value}}" class="text-cyan-400 underline-offset-2 hover:opacity-60">{{$key}}</a></span>
{{end}}
</div>
<div id="upload" class="inline-block bg-blue-500 text-white w-auto font-bold py-2 px-2 rounded-full mb-3 hover:opacity-60">
Expand Down
3 changes: 2 additions & 1 deletion web/s3_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func S3Handler(w http.ResponseWriter, r *http.Request) {

dataMap := map[string]interface{}{
"S3Objects": s3Objects,
"breadcrumbs": "Some additional data",
"Breadcrumbs": util.GenerateBreadcrumbs(path),
}

tmpl, err := template.ParseFiles("static/index.html")
Expand All @@ -37,6 +37,7 @@ func S3Handler(w http.ResponseWriter, r *http.Request) {
return
}

slog.Info("dataMap", "dataMap", dataMap)
tmpl.Execute(w, dataMap)
}
func download(path string) {
Expand Down

0 comments on commit dac544f

Please sign in to comment.