From dbaf48c30c36afcc858150f036f67a6cce6f5011 Mon Sep 17 00:00:00 2001 From: Brian Olson Date: Wed, 15 Jan 2025 07:47:08 -0500 Subject: [PATCH] add GET /admin/repo/takedowns --- bgs/admin.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ bgs/bgs.go | 1 + 2 files changed, 46 insertions(+) diff --git a/bgs/admin.go b/bgs/admin.go index 1d415d66a..2bf45c703 100644 --- a/bgs/admin.go +++ b/bgs/admin.go @@ -116,6 +116,51 @@ func (bgs *BGS) handleAdminReverseTakedown(e echo.Context) error { return nil } +type ListTakedownsResponse struct { + Dids []string `json:"dids"` + Cursor int64 `json:"cursor,omitempty"` +} + +func (bgs *BGS) handleAdminListRepoTakeDowns(e echo.Context) error { + ctx := e.Request().Context() + haveMinId := false + minId := int64(-1) + qmin := e.QueryParam("cursor") + if qmin != "" { + tmin, err := strconv.ParseInt(qmin, 10, 64) + if err != nil { + return &echo.HTTPError{Code: 400, Message: "bad cursor"} + } + minId = tmin + haveMinId = true + } + limit := 1000 + wat := bgs.db.Model(User{}).WithContext(ctx).Select("id", "did").Where("taken_down = TRUE") + if haveMinId { + wat = wat.Where("id > ?", minId) + } + //var users []User + rows, err := wat.Order("id").Limit(limit).Rows() + if err != nil { + return echo.NewHTTPError(http.StatusInternalServerError, "oops").WithInternal(err) + } + var out ListTakedownsResponse + for rows.Next() { + var id int64 + var did string + err := rows.Scan(&id, &did) + if err != nil { + return echo.NewHTTPError(http.StatusInternalServerError, "oops").WithInternal(err) + } + out.Dids = append(out.Dids, did) + out.Cursor = id + } + if len(out.Dids) < limit { + out.Cursor = 0 + } + return e.JSON(200, out) +} + func (bgs *BGS) handleAdminGetUpstreamConns(e echo.Context) error { return e.JSON(200, bgs.slurper.GetActiveList()) } diff --git a/bgs/bgs.go b/bgs/bgs.go index 9f14492b5..2e626d840 100644 --- a/bgs/bgs.go +++ b/bgs/bgs.go @@ -395,6 +395,7 @@ func (bgs *BGS) StartWithListener(listen net.Listener) error { // Repo-related Admin API admin.POST("/repo/takeDown", bgs.handleAdminTakeDownRepo) admin.POST("/repo/reverseTakedown", bgs.handleAdminReverseTakedown) + admin.GET("/repo/takedowns", bgs.handleAdminListRepoTakeDowns) admin.POST("/repo/compact", bgs.handleAdminCompactRepo) admin.POST("/repo/compactAll", bgs.handleAdminCompactAllRepos) admin.POST("/repo/reset", bgs.handleAdminResetRepo)