diff options
| author | RanXom <saiyedshizain@gmail.com> | 2026-07-13 19:42:27 +0530 |
|---|---|---|
| committer | RanXom <saiyedshizain@gmail.com> | 2026-07-13 19:42:27 +0530 |
| commit | 8e8f0bd38f0cc0ee435ae2ed392a206e1ea73a32 (patch) | |
| tree | 93ec34c177b6a48d90d5024313c3a10f5b7c5d2b /internal/api | |
| parent | 5f9a07afe0fd42cd9870c864eb30941343bf51e9 (diff) | |
| download | galleryd-8e8f0bd38f0cc0ee435ae2ed392a206e1ea73a32.tar.xz galleryd-8e8f0bd38f0cc0ee435ae2ed392a206e1ea73a32.zip | |
feat(api): serve original photos
Diffstat (limited to 'internal/api')
| -rw-r--r-- | internal/api/new.go | 5 | ||||
| -rw-r--r-- | internal/api/photo.go | 43 |
2 files changed, 47 insertions, 1 deletions
diff --git a/internal/api/new.go b/internal/api/new.go index e2399e5..7febfe7 100644 --- a/internal/api/new.go +++ b/internal/api/new.go @@ -35,5 +35,10 @@ func New(config Config) *Server { srv.handleThumbnail, ) + srv.mux.HandleFunc( + "GET /photo/{id}", + srv.handlePhoto, + ) + return srv } diff --git a/internal/api/photo.go b/internal/api/photo.go index 7174491..37f9587 100644 --- a/internal/api/photo.go +++ b/internal/api/photo.go @@ -1,6 +1,13 @@ package api -import "time" +import ( + "errors" + "log" + "net/http" + "time" + + "github.com/RanXom/galleryd/internal/service" +) type photoResponse struct { ID string `json:"id"` @@ -10,3 +17,37 @@ type photoResponse struct { ThumbnailURL string `json:"thumbnail"` PhotoURL string `json:"photo"` } + +func (s *Server) handlePhoto( + 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 + } + + http.ServeFile( + w, + r, + photo.Path, + ) +} |