-
Notifications
You must be signed in to change notification settings - Fork 162
/
Copy pathhandlers.go
178 lines (143 loc) · 4.2 KB
/
handlers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package bgs
import (
"bytes"
"context"
"fmt"
"io"
"net/http"
"strings"
atproto "github.com/bluesky-social/indigo/api/atproto"
comatprototypes "github.com/bluesky-social/indigo/api/atproto"
"github.com/bluesky-social/indigo/util"
"github.com/bluesky-social/indigo/xrpc"
"github.com/ipfs/go-cid"
"github.com/labstack/echo/v4"
)
func (s *BGS) handleComAtprotoSyncGetCheckout(ctx context.Context, commit string, did string) (io.Reader, error) {
/*
u, err := s.Index.LookupUserByDid(ctx, did)
if err != nil {
return nil, err
}
c, err := cid.Decode(commit)
if err != nil {
return nil, err
}
// TODO: need to enable a 'write to' interface for codegenned things...
buf := new(bytes.Buffer)
if err := s.repoman.GetCheckout(ctx, u.Uid, c, buf); err != nil {
return nil, err
}
return buf, nil
*/
return nil, fmt.Errorf("nyi")
}
func (s *BGS) handleComAtprotoSyncGetCommitPath(ctx context.Context, did string, earliest string, latest string) (*comatprototypes.SyncGetCommitPath_Output, error) {
return nil, fmt.Errorf("nyi")
}
func (s *BGS) handleComAtprotoSyncGetHead(ctx context.Context, did string) (*comatprototypes.SyncGetHead_Output, error) {
u, err := s.Index.LookupUserByDid(ctx, did)
if err != nil {
return nil, err
}
root, err := s.repoman.GetRepoRoot(ctx, u.Uid)
if err != nil {
return nil, err
}
return &comatprototypes.SyncGetHead_Output{
Root: root.String(),
}, nil
}
func (s *BGS) handleComAtprotoSyncGetRecord(ctx context.Context, collection string, commit string, did string, rkey string) (io.Reader, error) {
return nil, fmt.Errorf("nyi")
}
func (s *BGS) handleComAtprotoSyncGetRepo(ctx context.Context, did string, earliest string, latest string) (io.Reader, error) {
u, err := s.Index.LookupUserByDid(ctx, did)
if err != nil {
return nil, err
}
var earlyCid, lateCid cid.Cid
if earliest != "" {
c, err := cid.Decode(earliest)
if err != nil {
return nil, err
}
earlyCid = c
}
if latest != "" {
c, err := cid.Decode(latest)
if err != nil {
return nil, err
}
lateCid = c
}
// TODO: stream the response
buf := new(bytes.Buffer)
if err := s.repoman.ReadRepo(ctx, u.Uid, earlyCid, lateCid, buf); err != nil {
return nil, err
}
return buf, nil
}
func (s *BGS) handleComAtprotoSyncGetBlocks(ctx context.Context, cids []string, did string) (io.Reader, error) {
return nil, fmt.Errorf("NYI")
}
func (s *BGS) handleComAtprotoSyncRequestCrawl(ctx context.Context, host string) error {
if host == "" {
return fmt.Errorf("must pass valid hostname")
}
if strings.HasPrefix(host, "https://") || strings.HasPrefix(host, "http://") {
return &echo.HTTPError{
Code: 400,
Message: "must pass domain without protocol scheme",
}
}
norm, err := util.NormalizeHostname(host)
if err != nil {
return err
}
banned, err := s.domainIsBanned(ctx, host)
if banned {
return &echo.HTTPError{
Code: 401,
Message: "domain is banned",
}
}
log.Warnf("TODO: better host validation for crawl requests")
c := &xrpc.Client{
Host: "https://" + host,
Client: http.DefaultClient, // not using the client that auto-retries
}
if !s.ssl {
c.Host = "http://" + host
}
desc, err := atproto.ServerDescribeServer(ctx, c)
if err != nil {
return &echo.HTTPError{
Code: 401,
Message: fmt.Sprintf("given host failed to respond to ping: %s", err),
}
}
// Maybe we could do something with this response later
_ = desc
return s.slurper.SubscribeToPds(ctx, norm, true)
}
func (s *BGS) handleComAtprotoSyncNotifyOfUpdate(ctx context.Context, hostname string) error {
// TODO:
return nil
}
func (s *BGS) handleComAtprotoSyncGetBlob(ctx context.Context, cid string, did string) (io.Reader, error) {
if s.blobs == nil {
return nil, fmt.Errorf("blob store disabled")
}
b, err := s.blobs.GetBlob(ctx, cid, did)
if err != nil {
return nil, err
}
return bytes.NewReader(b), nil
}
func (s *BGS) handleComAtprotoSyncListBlobs(ctx context.Context, did string, earliest string, latest string) (*comatprototypes.SyncListBlobs_Output, error) {
return nil, fmt.Errorf("NYI")
}
func (s *BGS) handleComAtprotoSyncListRepos(ctx context.Context, cursor string, limit int) (*comatprototypes.SyncListRepos_Output, error) {
return nil, fmt.Errorf("NYI")
}