Skip to content

Commit

Permalink
bskyweb: remove waitlist email endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob2161 committed Mar 6, 2024
1 parent f61d1e1 commit f17be2e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 132 deletions.
70 changes: 0 additions & 70 deletions bskyweb/cmd/bskyweb/mailmodo.go

This file was deleted.

12 changes: 0 additions & 12 deletions bskyweb/cmd/bskyweb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,6 @@ func run(args []string) {
// retain old PDS env var for easy transition
EnvVars: []string{"ATP_APPVIEW_HOST", "ATP_PDS_HOST"},
},
&cli.StringFlag{
Name: "mailmodo-api-key",
Usage: "Mailmodo API key",
Required: false,
EnvVars: []string{"MAILMODO_API_KEY"},
},
&cli.StringFlag{
Name: "mailmodo-list-name",
Usage: "Mailmodo contact list to add email addresses to",
Required: false,
EnvVars: []string{"MAILMODO_LIST_NAME"},
},
&cli.StringFlag{
Name: "http-address",
Usage: "Specify the local IP/port to bind to",
Expand Down
55 changes: 5 additions & 50 deletions bskyweb/cmd/bskyweb/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ package main

import (
"context"
"encoding/json"
"errors"
"fmt"
"io/fs"
"io/ioutil"
"net/http"
"os"
"os/signal"
Expand All @@ -29,25 +27,19 @@ import (
)

type Server struct {
echo *echo.Echo
httpd *http.Server
mailmodo *Mailmodo
xrpcc *xrpc.Client
echo *echo.Echo
httpd *http.Server
xrpcc *xrpc.Client
}

func serve(cctx *cli.Context) error {
debug := cctx.Bool("debug")
httpAddress := cctx.String("http-address")
appviewHost := cctx.String("appview-host")
mailmodoAPIKey := cctx.String("mailmodo-api-key")
mailmodoListName := cctx.String("mailmodo-list-name")

// Echo
e := echo.New()

// Mailmodo client.
mailmodo := NewMailmodo(mailmodoAPIKey, mailmodoListName)

// create a new session (no auth)
xrpcc := &xrpc.Client{
Client: cliutil.NewHttpClient(),
Expand Down Expand Up @@ -77,9 +69,8 @@ func serve(cctx *cli.Context) error {
// server
//
server := &Server{
echo: e,
mailmodo: mailmodo,
xrpcc: xrpcc,
echo: e,
xrpcc: xrpcc,
}

// Create the HTTP server.
Expand Down Expand Up @@ -221,9 +212,6 @@ func serve(cctx *cli.Context) error {
e.GET("/profile/:handleOrDID/post/:rkey/liked-by", server.WebGeneric)
e.GET("/profile/:handleOrDID/post/:rkey/reposted-by", server.WebGeneric)

// Mailmodo
e.POST("/api/waitlist", server.apiWaitlist)

// Start the server.
log.Infof("starting server address=%s", httpAddress)
go func() {
Expand Down Expand Up @@ -398,36 +386,3 @@ func (srv *Server) WebProfile(c echo.Context) error {
data["requestHost"] = req.Host
return c.Render(http.StatusOK, "profile.html", data)
}

func (srv *Server) apiWaitlist(c echo.Context) error {
type jsonError struct {
Error string `json:"error"`
}

// Read the API request.
type apiRequest struct {
Email string `json:"email"`
}

bodyReader := http.MaxBytesReader(c.Response(), c.Request().Body, 16*1024)
payload, err := ioutil.ReadAll(bodyReader)
if err != nil {
return err
}
var req apiRequest
if err := json.Unmarshal(payload, &req); err != nil {
return c.JSON(http.StatusBadRequest, jsonError{Error: "Invalid API request"})
}

if req.Email == "" {
return c.JSON(http.StatusBadRequest, jsonError{Error: "Please enter a valid email address."})
}

if err := srv.mailmodo.AddToList(c.Request().Context(), req.Email); err != nil {
log.Errorf("adding email to waitlist failed: %s", err)
return c.JSON(http.StatusBadRequest, jsonError{
Error: "Storing email in waitlist failed. Please enter a valid email address.",
})
}
return c.JSON(http.StatusOK, map[string]bool{"success": true})
}

0 comments on commit f17be2e

Please sign in to comment.