fork of indigo with slightly nicer lexgen

add GET /admin/repo/takedowns

authored by Brian Olson and committed by Brian Olson af0f2ad4 fd270fbc

Changed files
+46
bgs
+45
bgs/admin.go
··· 116 116 return nil 117 117 } 118 118 119 + type ListTakedownsResponse struct { 120 + Dids []string `json:"dids"` 121 + Cursor int64 `json:"cursor,omitempty"` 122 + } 123 + 124 + func (bgs *BGS) handleAdminListRepoTakeDowns(e echo.Context) error { 125 + ctx := e.Request().Context() 126 + haveMinId := false 127 + minId := int64(-1) 128 + qmin := e.QueryParam("cursor") 129 + if qmin != "" { 130 + tmin, err := strconv.ParseInt(qmin, 10, 64) 131 + if err != nil { 132 + return &echo.HTTPError{Code: 400, Message: "bad cursor"} 133 + } 134 + minId = tmin 135 + haveMinId = true 136 + } 137 + limit := 1000 138 + wat := bgs.db.Model(User{}).WithContext(ctx).Select("id", "did").Where("taken_down = TRUE") 139 + if haveMinId { 140 + wat = wat.Where("id > ?", minId) 141 + } 142 + //var users []User 143 + rows, err := wat.Order("id").Limit(limit).Rows() 144 + if err != nil { 145 + return echo.NewHTTPError(http.StatusInternalServerError, "oops").WithInternal(err) 146 + } 147 + var out ListTakedownsResponse 148 + for rows.Next() { 149 + var id int64 150 + var did string 151 + err := rows.Scan(&id, &did) 152 + if err != nil { 153 + return echo.NewHTTPError(http.StatusInternalServerError, "oops").WithInternal(err) 154 + } 155 + out.Dids = append(out.Dids, did) 156 + out.Cursor = id 157 + } 158 + if len(out.Dids) < limit { 159 + out.Cursor = 0 160 + } 161 + return e.JSON(200, out) 162 + } 163 + 119 164 func (bgs *BGS) handleAdminGetUpstreamConns(e echo.Context) error { 120 165 return e.JSON(200, bgs.slurper.GetActiveList()) 121 166 }
+1
bgs/bgs.go
··· 395 395 // Repo-related Admin API 396 396 admin.POST("/repo/takeDown", bgs.handleAdminTakeDownRepo) 397 397 admin.POST("/repo/reverseTakedown", bgs.handleAdminReverseTakedown) 398 + admin.GET("/repo/takedowns", bgs.handleAdminListRepoTakeDowns) 398 399 admin.POST("/repo/compact", bgs.handleAdminCompactRepo) 399 400 admin.POST("/repo/compactAll", bgs.handleAdminCompactAllRepos) 400 401 admin.POST("/repo/reset", bgs.handleAdminResetRepo)