Skip to content

Commit

Permalink
cli command to trigger reset repo
Browse files Browse the repository at this point in the history
  • Loading branch information
whyrusleeping committed Sep 29, 2023
1 parent 61c8c55 commit 9cd7059
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions cmd/gosky/bgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var bgsAdminCmd = &cli.Command{
bgsSetNewSubsEnabledCmd,
bgsCompactRepo,
bgsCompactAll,
bgsResetRepo,
},
}

Expand Down Expand Up @@ -381,3 +382,44 @@ var bgsCompactAll = &cli.Command{
return nil
},
}

var bgsResetRepo = &cli.Command{
Name: "reset-repo",
Action: func(cctx *cli.Context) error {
url := cctx.String("bgs") + "/admin/repo/reset"

did := cctx.Args().First()
url += fmt.Sprintf("?did=%s", did)

req, err := http.NewRequest("POST", url, nil)
if err != nil {
return err
}

auth := cctx.String("key")
req.Header.Set("Authorization", "Bearer "+auth)

resp, err := http.DefaultClient.Do(req)
if err != nil {
return err
}

if resp.StatusCode != 200 {
var e xrpc.XRPCError
if err := json.NewDecoder(resp.Body).Decode(&e); err != nil {
return err
}

return &e
}

var out map[string]any
if err := json.NewDecoder(resp.Body).Decode(&out); err != nil {
return err
}

fmt.Println(out)

return nil
},
}

0 comments on commit 9cd7059

Please sign in to comment.