diff options
| author | RanXom <saiyedshizain@gmail.com> | 2026-07-13 15:53:08 +0530 |
|---|---|---|
| committer | RanXom <saiyedshizain@gmail.com> | 2026-07-13 15:53:08 +0530 |
| commit | 56bb199787f8fc80b92779426644250f2709fd36 (patch) | |
| tree | 4fbbce3d746c22a4cbb42ec53a9abd3e698bc67b /internal/api/photos.go | |
| parent | 0bf573c82118aaa5b60ab381dee26f43b10004b3 (diff) | |
| download | galleryd-56bb199787f8fc80b92779426644250f2709fd36.tar.xz galleryd-56bb199787f8fc80b92779426644250f2709fd36.zip | |
feat(api): expose gallery photos endpoint
Diffstat (limited to 'internal/api/photos.go')
| -rw-r--r-- | internal/api/photos.go | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/internal/api/photos.go b/internal/api/photos.go new file mode 100644 index 0000000..2d492b1 --- /dev/null +++ b/internal/api/photos.go @@ -0,0 +1,47 @@ +package api + +import ( + "encoding/json" + "log" + "net/http" +) + +func (s *Server) handlePhotos( + w http.ResponseWriter, + r *http.Request, +) { + photos, err := s.gallery.Gallery(r.Context()) + if err != nil { + log.Printf("gallery: %v", err) + + http.Error( + w, + http.StatusText(http.StatusInternalServerError), + http.StatusInternalServerError, + ) + return + } + + response := make([]photoResponse, 0, len(photos)) + + for _, photo := range photos { + response = append(response, photoResponse{ + ID: photo.ID, + DateTaken: photo.DateTaken, + Width: photo.Width, + Height: photo.Height, + ThumbnailURL: "/thumb/" + photo.ID, + PhotoURL: "/photo/" + photo.ID, + }) + } + + w.Header().Set("Content-Type", "application/json") + + if err := json.NewEncoder(w).Encode(response); err != nil { + http.Error( + w, + http.StatusText(http.StatusInternalServerError), + http.StatusInternalServerError, + ) + } +} |