1package server
2
3import (
4 "github.com/haileyok/cocoon/models"
5 "github.com/ipfs/go-cid"
6 "github.com/labstack/echo/v4"
7)
8
9type ComAtprotoSyncListReposResponse struct {
10 Cursor *string `json:"cursor,omitempty"`
11 Repos []ComAtprotoSyncListReposRepoItem `json:"repos"`
12}
13
14type ComAtprotoSyncListReposRepoItem struct {
15 Did string `json:"did"`
16 Head string `json:"head"`
17 Rev string `json:"rev"`
18 Active bool `json:"active"`
19 Status *string `json:"status,omitempty"`
20}
21
22// TODO: paginate this bitch
23func (s *Server) handleListRepos(e echo.Context) error {
24 ctx := e.Request().Context()
25
26 var repos []models.Repo
27 if err := s.db.Raw(ctx, "SELECT * FROM repos ORDER BY created_at DESC LIMIT 500", nil).Scan(&repos).Error; err != nil {
28 return err
29 }
30
31 var items []ComAtprotoSyncListReposRepoItem
32 for _, r := range repos {
33 c, err := cid.Cast(r.Root)
34 if err != nil {
35 return err
36 }
37
38 items = append(items, ComAtprotoSyncListReposRepoItem{
39 Did: r.Did,
40 Head: c.String(),
41 Rev: r.Rev,
42 Active: r.Active(),
43 Status: r.Status(),
44 })
45 }
46
47 return e.JSON(200, ComAtprotoSyncListReposResponse{
48 Cursor: nil,
49 Repos: items,
50 })
51}