32 lines
767 B
Go
32 lines
767 B
Go
package restgallery
|
|
|
|
import (
|
|
"fmt"
|
|
"log/slog"
|
|
"net/http"
|
|
|
|
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/pkg/templer"
|
|
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/web/pages"
|
|
)
|
|
|
|
const preloadCount = 6
|
|
|
|
func (h *Handler) gallery(w http.ResponseWriter, r *http.Request) {
|
|
imgs, err := h.srv.GetGallerySet(r.Context())
|
|
if err != nil {
|
|
slog.Error("could not get images", "err", err)
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
return
|
|
}
|
|
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))
|
|
}
|