tangled
alpha
login
or
join now
willdot.net
/
tangled-fork
forked from
tangled.org/core
Monorepo for Tangled
0
fork
atom
overview
issues
pulls
pipelines
appview: xrpcclient: init wrapper xrpc client
anirudh.fi
9 months ago
ed9740a1
32a4ec44
verified
This commit was signed with the committer's
known signature
.
anirudh.fi
SSH Key Fingerprint:
SHA256:cz35vdbiWEzCNEfuL9fMC2JVIhtXavXBHrRjv8gxpAk=
+80
1 changed file
expand all
collapse all
unified
split
appview
xrpcclient
xrpc.go
+80
appview/xrpcclient/xrpc.go
···
1
1
+
package xrpcclient
2
2
+
3
3
+
import (
4
4
+
"bytes"
5
5
+
"context"
6
6
+
"io"
7
7
+
8
8
+
"github.com/bluesky-social/indigo/api/atproto"
9
9
+
"github.com/bluesky-social/indigo/xrpc"
10
10
+
oauth "github.com/haileyok/atproto-oauth-golang"
11
11
+
)
12
12
+
13
13
+
type Client struct {
14
14
+
*oauth.XrpcClient
15
15
+
authArgs *oauth.XrpcAuthedRequestArgs
16
16
+
}
17
17
+
18
18
+
func NewClient(client *oauth.XrpcClient, authArgs *oauth.XrpcAuthedRequestArgs) *Client {
19
19
+
return &Client{
20
20
+
XrpcClient: client,
21
21
+
authArgs: authArgs,
22
22
+
}
23
23
+
}
24
24
+
25
25
+
func (c *Client) RepoPutRecord(ctx context.Context, input *atproto.RepoPutRecord_Input) (*atproto.RepoPutRecord_Output, error) {
26
26
+
var out atproto.RepoPutRecord_Output
27
27
+
if err := c.Do(ctx, c.authArgs, xrpc.Procedure, "application/json", "com.atproto.repo.putRecord", nil, input, &out); err != nil {
28
28
+
return nil, err
29
29
+
}
30
30
+
31
31
+
return &out, nil
32
32
+
}
33
33
+
34
34
+
func (c *Client) RepoGetRecord(ctx context.Context, cid string, collection string, repo string, rkey string) (*atproto.RepoGetRecord_Output, error) {
35
35
+
var out atproto.RepoGetRecord_Output
36
36
+
37
37
+
params := map[string]interface{}{
38
38
+
"cid": cid,
39
39
+
"collection": collection,
40
40
+
"repo": repo,
41
41
+
"rkey": rkey,
42
42
+
}
43
43
+
if err := c.Do(ctx, c.authArgs, xrpc.Query, "", "com.atproto.repo.getRecord", params, nil, &out); err != nil {
44
44
+
return nil, err
45
45
+
}
46
46
+
47
47
+
return &out, nil
48
48
+
}
49
49
+
50
50
+
func (c *Client) RepoUploadBlob(ctx context.Context, input io.Reader) (*atproto.RepoUploadBlob_Output, error) {
51
51
+
var out atproto.RepoUploadBlob_Output
52
52
+
if err := c.Do(ctx, c.authArgs, xrpc.Procedure, "*/*", "com.atproto.repo.uploadBlob", nil, input, &out); err != nil {
53
53
+
return nil, err
54
54
+
}
55
55
+
56
56
+
return &out, nil
57
57
+
}
58
58
+
59
59
+
func (c *Client) SyncGetBlob(ctx context.Context, cid string, did string) ([]byte, error) {
60
60
+
buf := new(bytes.Buffer)
61
61
+
62
62
+
params := map[string]interface{}{
63
63
+
"cid": cid,
64
64
+
"did": did,
65
65
+
}
66
66
+
if err := c.Do(ctx, c.authArgs, xrpc.Query, "", "com.atproto.sync.getBlob", params, nil, buf); err != nil {
67
67
+
return nil, err
68
68
+
}
69
69
+
70
70
+
return buf.Bytes(), nil
71
71
+
}
72
72
+
73
73
+
func (c *Client) RepoDeleteRecord(ctx context.Context, input *atproto.RepoDeleteRecord_Input) (*atproto.RepoDeleteRecord_Output, error) {
74
74
+
var out atproto.RepoDeleteRecord_Output
75
75
+
if err := c.Do(ctx, c.authArgs, xrpc.Procedure, "application/json", "com.atproto.repo.deleteRecord", nil, input, &out); err != nil {
76
76
+
return nil, err
77
77
+
}
78
78
+
79
79
+
return &out, nil
80
80
+
}