diff options
author | Gabriel Arakaki Giovanini <mail@gabrielgio.me> | 2023-08-18 21:57:47 +0200 |
---|---|---|
committer | Gabriel Arakaki Giovanini <mail@gabrielgio.me> | 2023-08-18 21:57:47 +0200 |
commit | a1f09d1f143012570a62bcb2a8fe51c439ad68fb (patch) | |
tree | 591cf29229453f2402fc82f50f6b4e0bee8f0e22 /pkg | |
parent | d2a9e162352646e7f1550823c3d88496590f8760 (diff) | |
download | lens-a1f09d1f143012570a62bcb2a8fe51c439ad68fb.tar.gz lens-a1f09d1f143012570a62bcb2a8fe51c439ad68fb.tar.bz2 lens-a1f09d1f143012570a62bcb2a8fe51c439ad68fb.zip |
feat: Make mosaic reusable
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/list/list.go | 6 | ||||
-rw-r--r-- | pkg/view/media.go | 11 |
2 files changed, 9 insertions, 8 deletions
diff --git a/pkg/list/list.go b/pkg/list/list.go index 3aa9d65..b6b6b89 100644 --- a/pkg/list/list.go +++ b/pkg/list/list.go @@ -13,15 +13,15 @@ type Pair[T, U any] struct { Right U } -func Chunck[T any](slice []T, size int) [][]T { +func Distribuite[T any](slice []T, size int) [][]T { chuncks := make([][]T, size) for i := 0; i < len(slice); i += size { for x := 0; x < size; x++ { end := i + x - if end > len(slice) { - break + if end >= len(slice) { + return chuncks } chuncks[x] = append(chuncks[x], slice[end]) diff --git a/pkg/view/media.go b/pkg/view/media.go index 3124119..d5aace2 100644 --- a/pkg/view/media.go +++ b/pkg/view/media.go @@ -44,7 +44,8 @@ func getPagination(r *http.Request) *repository.Pagination { } if albumIDStr == "" { - page = 0 + id := uint(0) + albumID = &id } else if p, err := strconv.Atoi(albumIDStr); err == nil { id := uint(p) albumID = &id @@ -132,9 +133,9 @@ func (self *MediaView) GetThumbnail(w http.ResponseWriter, r *http.Request) erro } func (self *MediaView) SetMyselfIn(r *ext.Router) { - r.GET("/media/", self.Index) - r.POST("/media/", self.Index) + r.GET("/media", self.Index) + r.POST("/media", self.Index) - r.GET("/media/image/", self.GetImage) - r.GET("/media/thumbnail/", self.GetThumbnail) + r.GET("/media/image", self.GetImage) + r.GET("/media/thumbnail", self.GetThumbnail) } |