This commit is contained in:
1 parent
c678c7aa45
commit
72bc974aa6
3 files changed
+24
-1
No files matched your search
@@ -11,6 +11,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/components/images"
|
||||||
"github.com/valkey-io/valkey-go"
|
"github.com/valkey-io/valkey-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -22,6 +23,10 @@ type Image struct {
|
|||||||
Height int
|
Height int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i Image) URL() string {
|
||||||
|
return images.URLFromUID(i.UID)
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
imagesKey = "gallery:images:list"
|
imagesKey = "gallery:images:list"
|
||||||
hashKey = "gallery:images:hash"
|
hashKey = "gallery:images:hash"
|
||||||
|
|||||||
@@ -33,6 +33,11 @@ func UIDFromPath(path string) (uid string, err error) {
|
|||||||
|
|
||||||
func URLFromPath(path string) (url string, err error) {
|
func URLFromPath(path string) (url string, err error) {
|
||||||
uid, err := UIDFromPath(path)
|
uid, err := UIDFromPath(path)
|
||||||
|
url = URLFromUID(uid)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func URLFromUID(uid string) (url string) {
|
||||||
url = "/images/" + uid
|
url = "/images/" + uid
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
package restgallery
|
package restgallery
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/pkg/templer"
|
||||||
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/web/pages"
|
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/web/pages"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const preloadCount = 6
|
||||||
|
|
||||||
func (h *Handler) gallery(w http.ResponseWriter, r *http.Request) {
|
func (h *Handler) gallery(w http.ResponseWriter, r *http.Request) {
|
||||||
imgs, err := h.srv.GetGallerySet(r.Context())
|
imgs, err := h.srv.GetGallerySet(r.Context())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -14,5 +18,14 @@ func (h *Handler) gallery(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
h.r.Render(r.Context(), w, r, pages.GallerySet(imgs))
|
ctx := r.Context()
|
||||||
|
for i, image := range imgs.LG.Images {
|
||||||
|
if i > preloadCount {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
slog.Info("preloading images", "img", image.UID)
|
||||||
|
ctx = templer.AppendHeader(ctx, fmt.Sprintf(`<link rel="preload" href="%s" as="image" />`, image.URL()))
|
||||||
|
}
|
||||||
|
|
||||||
|
h.r.Render(ctx, w, r, pages.GallerySet(imgs))
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user