An atproto PDS written in Go
at main 1.5 kB view raw
1package server 2 3import ( 4 "context" 5 "time" 6 7 "github.com/Azure/go-autorest/autorest/to" 8 "github.com/bluesky-social/indigo/api/atproto" 9 "github.com/bluesky-social/indigo/events" 10 "github.com/bluesky-social/indigo/util" 11 "github.com/haileyok/cocoon/internal/helpers" 12 "github.com/haileyok/cocoon/models" 13 "github.com/labstack/echo/v4" 14) 15 16type ComAtprotoServerDeactivateAccountRequest struct { 17 // NOTE: this implementation will not pay attention to this value 18 DeleteAfter time.Time `json:"deleteAfter"` 19} 20 21func (s *Server) handleServerDeactivateAccount(e echo.Context) error { 22 ctx := e.Request().Context() 23 logger := s.logger.With("name", "handleServerDeactivateAccount") 24 25 var req ComAtprotoServerDeactivateAccountRequest 26 if err := e.Bind(&req); err != nil { 27 logger.Error("error binding", "error", err) 28 return helpers.ServerError(e, nil) 29 } 30 31 urepo := e.Get("repo").(*models.RepoActor) 32 33 if err := s.db.Exec(ctx, "UPDATE repos SET deactivated = ? WHERE did = ?", nil, true, urepo.Repo.Did).Error; err != nil { 34 logger.Error("error updating account status to deactivated", "error", err) 35 return helpers.ServerError(e, nil) 36 } 37 38 s.evtman.AddEvent(context.TODO(), &events.XRPCStreamEvent{ 39 RepoAccount: &atproto.SyncSubscribeRepos_Account{ 40 Active: false, 41 Did: urepo.Repo.Did, 42 Status: to.StringPtr("deactivated"), 43 Seq: time.Now().UnixMicro(), // TODO: bad puppy 44 Time: time.Now().Format(util.ISO8601), 45 }, 46 }) 47 48 return e.NoContent(200) 49}