diff --git a/main.go b/main.go index 9bb3c478a8c6fcdc06d1ce91e41dc7546b91d649..e153ae39f06042a4a80a7a7efd64e3c7e7b4c1ef 100644 --- a/main.go +++ b/main.go @@ -346,6 +346,92 @@ func main() { fmt.Fprint(w, "Image not found") }))) + http.Handle("/a/", http.StripPrefix("/a/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + user := parseUser(r) + + type AlbumImage struct { + Id string + Title string + Description string + Position int + } + + type Album struct { + Id string + Title string + Description string + CreatedAt time.Time + Images []AlbumImage + } + + type AlbumDetailData struct { + User UserInfo + Album Album + IsMine bool + } + + _, albumId := path.Split(r.URL.Path) + result, err := db.Query(` + SELECT + id, + owner, + coalesce(title, ''), + coalesce(description, ''), + coalesce(created_at, to_timestamp(0)) + FROM albums + WHERE id = $1 + `, albumId) + if err != nil { + panic(err) + } + + var info Album + if result.Next() { + var owner string + err := result.Scan(&info.Id, &owner, &info.Title, &info.Description, &info.CreatedAt) + if err != nil { + panic(err) + } + + result, err := db.Query(` + SELECT + image, + title, + description, + position + FROM album_images + WHERE album = $1 + ORDER BY position ASC + `, albumId) + if err != nil { + panic(err) + } + + for result.Next() { + var image AlbumImage + err := result.Scan(&image.Id, &owner, &image.Title, &image.Description, &image.Position) + if err != nil { + panic(err) + } + + info.Images = append(info.Images, image) + } + + if err = returnResult(w, "album_detail.html", AlbumDetailData{ + user, + info, + owner == user.Id, + }); err != nil { + panic(err) + } + + return + } + + w.WriteHeader(http.StatusNotFound) + fmt.Fprint(w, "Image not found") + }))) + http.HandleFunc("/me/images/", func(w http.ResponseWriter, r *http.Request) { user := parseUser(r)