--wip-- [skip ci]
This commit is contained in:
1 parent
72bc974aa6
commit
bca93f6c6c
12 files changed
+256
-54
No files matched your search
@@ -5,6 +5,7 @@ import (
|
||||
"log/slog"
|
||||
"net/http"
|
||||
|
||||
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/handlers/rest"
|
||||
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/pkg/templer"
|
||||
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/web/pages"
|
||||
)
|
||||
@@ -14,8 +15,8 @@ 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)
|
||||
slog.Error("could not get gallery set", "err", err)
|
||||
rest.SendErr(w, err)
|
||||
return
|
||||
}
|
||||
ctx := r.Context()
|
||||
@@ -23,9 +24,22 @@ func (h *Handler) gallery(w http.ResponseWriter, r *http.Request) {
|
||||
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()))
|
||||
ctx = templer.AppendHeader(ctx, fmt.Sprintf(`<link rel="preload" href="%s?w=800" as="image" />`, image.URL()))
|
||||
}
|
||||
|
||||
h.r.Render(ctx, w, r, pages.GallerySet(imgs))
|
||||
}
|
||||
|
||||
func (h *Handler) image(w http.ResponseWriter, r *http.Request) {
|
||||
uid := r.PathValue("image_uid")
|
||||
|
||||
slog.Debug("image from gallery", "uid", uid)
|
||||
prev, next, err := h.srv.GetPrevAndNext(r.Context(), uid)
|
||||
if err != nil {
|
||||
slog.Error("could not get gallery", "err", err)
|
||||
rest.SendErr(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
h.r.Render(r.Context(), w, r, pages.GalleryImage(uid, next, prev))
|
||||
}
|
||||
Reference in new issue
Block a user