Skip to content

Commit

Permalink
refactor: Simplifying etag computation
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed May 20, 2022
1 parent c577b28 commit 9c6609a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
5 changes: 2 additions & 3 deletions pkg/crud/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (a App) handleDir(w http.ResponseWriter, r *http.Request, request provider.
}

if query.GetBool(r, "thumbnail") {
a.thumbnailApp.List(w, r, request, item, items)
a.thumbnailApp.List(w, r, items)
return renderer.Page{}, nil
}

Expand Down Expand Up @@ -178,8 +178,7 @@ func (a App) serveGeoJSON(w http.ResponseWriter, r *http.Request, request provid
return
}

hash := a.exifHash(r.Context(), items)
etag, ok := provider.EtagMatch(w, r, hash)
etag, ok := provider.EtagMatch(w, r, a.exifHash(r.Context(), items))
if ok {
return
}
Expand Down
12 changes: 2 additions & 10 deletions pkg/thumbnail/thumbnail.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/ViBiOh/httputils/v4/pkg/httperror"
"github.com/ViBiOh/httputils/v4/pkg/logger"
prom "github.com/ViBiOh/httputils/v4/pkg/prometheus"
"github.com/ViBiOh/httputils/v4/pkg/query"
"github.com/ViBiOh/httputils/v4/pkg/request"
"github.com/ViBiOh/httputils/v4/pkg/sha"
"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -196,22 +195,15 @@ func (a App) Serve(w http.ResponseWriter, r *http.Request, item absto.Item) {
}

// List return all thumbnail in a base64 form
func (a App) List(w http.ResponseWriter, r *http.Request, request provider.Request, item absto.Item, items []absto.Item) {
func (a App) List(w http.ResponseWriter, r *http.Request, items []absto.Item) {
if len(items) == 0 {
w.WriteHeader(http.StatusNoContent)
return
}

ctx := r.Context()

var hash string
if query.GetBool(r, "search") || request.IsStory() {
hash = a.thumbnailHash(ctx, items)
} else if thumbnails, err := a.ListDir(ctx, item); err == nil {
hash = sha.New(thumbnails)
}

etag, ok := provider.EtagMatch(w, r, hash)
etag, ok := provider.EtagMatch(w, r, a.thumbnailHash(ctx, items))
if ok {
return
}
Expand Down

0 comments on commit 9c6609a

Please sign in to comment.