Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix /api/waitlist API (#726)

* move /waitlist to /api/waitlist where its expected

* parse waitlist API request as JSON, duh

authored by

Jake Gold and committed by
GitHub
211fce47 0ca09613

+30 -3
+30 -3
bskyweb/cmd/bskyweb/server.go
··· 2 2 3 3 import ( 4 4 "context" 5 + "encoding/json" 5 6 "fmt" 6 7 "io/fs" 8 + "io/ioutil" 7 9 "net/http" 8 10 "os" 9 11 "strings" ··· 132 134 e.GET("/profile/:handle/post/:rkey/reposted-by", server.WebGeneric) 133 135 134 136 // Mailmodo 135 - e.POST("/waitlist", func(c echo.Context) error { 136 - email := strings.TrimSpace(c.FormValue("email")) 137 - if err := mailmodo.AddToList(c.Request().Context(), mailmodoListName, email); err != nil { 137 + e.POST("/api/waitlist", func(c echo.Context) error { 138 + type jsonError struct { 139 + Error string `json:"error"` 140 + } 141 + 142 + // Read the API request. 143 + type apiRequest struct { 144 + Email string `json:"email"` 145 + } 146 + 147 + bodyReader := http.MaxBytesReader(c.Response(), c.Request().Body, 16*1024) 148 + payload, err := ioutil.ReadAll(bodyReader) 149 + if err != nil { 138 150 return err 151 + } 152 + var req apiRequest 153 + if err := json.Unmarshal(payload, &req); err != nil { 154 + return c.JSON(http.StatusBadRequest, jsonError{Error: "Invalid API request"}) 155 + } 156 + 157 + if req.Email == "" { 158 + return c.JSON(http.StatusBadRequest, jsonError{Error: "Please enter a valid email address."}) 159 + } 160 + 161 + if err := mailmodo.AddToList(c.Request().Context(), mailmodoListName, req.Email); err != nil { 162 + log.Errorf("adding email to waitlist failed: %s", err) 163 + return c.JSON(http.StatusBadRequest, jsonError{ 164 + Error: "Storing email in waitlist failed. Please enter a valid email address.", 165 + }) 139 166 } 140 167 return c.JSON(http.StatusOK, map[string]bool{"success": true}) 141 168 })