chore: custom error
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package restimage
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
|
||||
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/components/images"
|
||||
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/handlers/restutil"
|
||||
)
|
||||
|
||||
func (h *Handler) getImage(w http.ResponseWriter, r *http.Request) {
|
||||
uid := r.PathValue("uid")
|
||||
|
||||
var err error
|
||||
options := images.Options{}
|
||||
options.Height, err = restutil.IntParam(r, "h")
|
||||
if err != nil {
|
||||
restutil.SendErr(w, err)
|
||||
return
|
||||
}
|
||||
options.Width, err = restutil.IntParam(r, "w")
|
||||
if err != nil {
|
||||
restutil.SendErr(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
options.Quality, err = restutil.IntParam(r, "q")
|
||||
if err != nil {
|
||||
restutil.SendErr(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
img, mime, err := h.img.GetImage(r.Context(), uid, options)
|
||||
if err != nil {
|
||||
slog.Error("error wile serving image", "err", err, "uid", uid)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Add("Content-Type", mime)
|
||||
io.Copy(w, img)
|
||||
}
|
||||
Reference in New Issue
Block a user