Implement photo selector

This commit is contained in:
2024-08-07 18:07:41 -04:00
parent 12befa0ac3
commit 298fed011d
5 changed files with 160 additions and 16 deletions

34
main.go
View File

@@ -58,8 +58,6 @@ func main() {
}
return photoPrismURL
}()
copy := *photoPrismURL
fmt.Println(copy)
collageNameGen = NewNameGen()
imagesDirFs = os.DirFS(imagesDir)
imagesURLPath := "images"
@@ -147,6 +145,38 @@ func main() {
w.Header().Set("Content-Type", "application/json")
w.Write(jData)
})
http.HandleFunc("/load-photos/{albumID}", func(w http.ResponseWriter, r *http.Request) {
albumID := r.PathValue("albumID")
photos, err := LoadPhotos(albumID)
if err != nil {
slog.Error("failed to load photos", "error", err, "album", albumID)
w.WriteHeader(http.StatusInternalServerError)
return
}
photoURLs := []string{}
for _, photo := range photos {
photoURLs = append(photoURLs, fmt.Sprintf("/%s/%s.jpg", photosPath, photo.FileUID))
}
go func() {
for _, photo := range photos {
_, err := DownloadPhoto(&photo)
if err != nil {
slog.Error("failed to download photo", "error", err, "album", albumID, "photoID", photo.FileUID)
}
}
}()
jData, err := json.Marshal(photoURLs)
if err != nil {
slog.Error("failed to marshal photoURLs", "error", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
w.Write(jData)
})
addrType, server, done, err := anyhttp.Serve(listenAddr, idle.WrapHandler(nil))
if err != nil {
slog.Error("anyhttp Serve failed", "error", err)