aboutsummaryrefslogtreecommitdiff
path: root/internal/api/thumb.go
diff options
context:
space:
mode:
authorSaiyed Shizain <saiyedshizain@gmail.com>2026-07-13 19:45:40 +0530
committerGitHub <noreply@github.com>2026-07-13 19:45:40 +0530
commit5d4eaf85434658f6fed621016e0bc2bae59e88d1 (patch)
tree93ec34c177b6a48d90d5024313c3a10f5b7c5d2b /internal/api/thumb.go
parentf41b0b92046e1bee512b3e4143ed9dc9a9ba9713 (diff)
parent8e8f0bd38f0cc0ee435ae2ed392a206e1ea73a32 (diff)
downloadgalleryd-5d4eaf85434658f6fed621016e0bc2bae59e88d1.tar.xz
galleryd-5d4eaf85434658f6fed621016e0bc2bae59e88d1.zip
Merge pull request #8 from RanXom/feat/api
Feat/api: expose gallery HTTP API
Diffstat (limited to 'internal/api/thumb.go')
-rw-r--r--internal/api/thumb.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/internal/api/thumb.go b/internal/api/thumb.go
new file mode 100644
index 0000000..0e18ade
--- /dev/null
+++ b/internal/api/thumb.go
@@ -0,0 +1,58 @@
+package api
+
+import (
+ "errors"
+ "log"
+ "net/http"
+
+ "github.com/RanXom/galleryd/internal/service"
+)
+
+func (s *Server) handleThumbnail(
+ w http.ResponseWriter,
+ r *http.Request,
+) {
+ id := r.PathValue("id")
+
+ photo, err := s.gallery.Photo(r.Context(), id)
+ if err != nil {
+ if errors.Is(err, service.ErrPhotoNotFound) {
+ writeError(
+ w,
+ http.StatusNotFound,
+ "photo not found",
+ )
+ return
+ }
+
+ log.Printf("lookup photo: %v", err)
+
+ writeError(
+ w,
+ http.StatusInternalServerError,
+ "failed to lookup photo",
+ )
+ return
+ }
+
+ thumb, err := s.thumbnails.Generate(
+ r.Context(),
+ photo,
+ )
+ if err != nil {
+ log.Printf("generate thumbnail: %v", err)
+
+ writeError(
+ w,
+ http.StatusInternalServerError,
+ "failed to generate thumbnail",
+ )
+ return
+ }
+
+ http.ServeFile(
+ w,
+ r,
+ thumb.Path,
+ )
+}