Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add GET /admin/repo/takedowns #908

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions bgs/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we omit the cursor from the response when it's empty? Not sure if it makes sense to return a cursor 0 since that's still valid.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel super strogly; it would take a bit of rework from 'greater than previous last id' to 'greater-equal 0 or (last id plus one)'

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay omitempty makes that work

}
return e.JSON(200, out)
}

func (bgs *BGS) handleAdminGetUpstreamConns(e echo.Context) error {
return e.JSON(200, bgs.slurper.GetActiveList())
}
Expand Down
1 change: 1 addition & 0 deletions bgs/bgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading