tidy-up refactor, add readme
This commit is contained in:
parent
6bde84b7e3
commit
cd48757272
6 changed files with 104 additions and 77 deletions
18
atproto.go
18
atproto.go
|
@ -20,6 +20,7 @@ type (
|
|||
RefreshJwt string `json:"refreshJwt"`
|
||||
Handle string `json:"handle"`
|
||||
Did string `json:"did"`
|
||||
PdsUrl string `json:"-"`
|
||||
}
|
||||
|
||||
AtprotoIdentity struct {
|
||||
|
@ -120,12 +121,13 @@ func CreateSession (pdsUrl string, identifier string, password string) (*Atproto
|
|||
if err != nil {
|
||||
return nil, errors.New(fmt.Sprintf("failed to parse PDS response: %v\n", err))
|
||||
}
|
||||
session.PdsUrl = pdsUrl
|
||||
|
||||
return &session, nil
|
||||
}
|
||||
|
||||
func ResolveAtprotoHandle(session *AtprotoSession, pdsUrl string, handle string) (string, error) {
|
||||
reqUrl, _ := url.Parse(pdsUrl + "/xrpc/com.atproto.identity.resolveHandle")
|
||||
func ResolveAtprotoHandle(session *AtprotoSession, handle string) (string, error) {
|
||||
reqUrl, _ := url.Parse(session.PdsUrl + "/xrpc/com.atproto.identity.resolveHandle")
|
||||
reqUrl.RawQuery = url.Values{
|
||||
"handle": { handle },
|
||||
}.Encode()
|
||||
|
@ -151,7 +153,7 @@ func ResolveAtprotoHandle(session *AtprotoSession, pdsUrl string, handle string)
|
|||
return identity.Did, nil
|
||||
}
|
||||
|
||||
func CreateAtprotoRecord(session *AtprotoSession, pdsUrl string, collection string, record json.RawMessage) (*AtprotoUriCid, error) {
|
||||
func CreateAtprotoRecord(session *AtprotoSession, collection string, record json.RawMessage) (*AtprotoUriCid, error) {
|
||||
reqBody, reqBodyBytes := AtprotoCreateRecord{
|
||||
Repo: session.Did,
|
||||
Collection: collection,
|
||||
|
@ -159,7 +161,7 @@ func CreateAtprotoRecord(session *AtprotoSession, pdsUrl string, collection stri
|
|||
}, new(bytes.Buffer)
|
||||
err := json.NewEncoder(reqBodyBytes).Encode(reqBody)
|
||||
if err != nil { return nil, err }
|
||||
req, _ := http.NewRequest(http.MethodPost, pdsUrl + "/xrpc/com.atproto.repo.createRecord", reqBodyBytes)
|
||||
req, _ := http.NewRequest(http.MethodPost, session.PdsUrl + "/xrpc/com.atproto.repo.createRecord", reqBodyBytes)
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("Authorization", "Bearer " + session.AccessJwt)
|
||||
|
||||
|
@ -175,7 +177,7 @@ func CreateAtprotoRecord(session *AtprotoSession, pdsUrl string, collection stri
|
|||
return &createdRecord, err
|
||||
}
|
||||
|
||||
func PutAtprotoRecord(session *AtprotoSession, pdsUrl string, collection string, record any) (*AtprotoUriCid, error) {
|
||||
func PutAtprotoRecord(session *AtprotoSession, collection string, record any) (*AtprotoUriCid, error) {
|
||||
reqBody, reqBodyBytes := AtprotoPutRecord{
|
||||
Repo: session.Did,
|
||||
Collection: collection,
|
||||
|
@ -185,7 +187,7 @@ func PutAtprotoRecord(session *AtprotoSession, pdsUrl string, collection string,
|
|||
err := json.NewEncoder(reqBodyBytes).Encode(reqBody)
|
||||
|
||||
if err != nil { return nil, err }
|
||||
req, _ := http.NewRequest(http.MethodPost, pdsUrl + "/xrpc/com.atproto.repo.putRecord", reqBodyBytes)
|
||||
req, _ := http.NewRequest(http.MethodPost, session.PdsUrl + "/xrpc/com.atproto.repo.putRecord", reqBodyBytes)
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("Authorization", "Bearer " + session.AccessJwt)
|
||||
|
||||
|
@ -225,8 +227,8 @@ func GetAtprotoBlob(pdsUrl string, did string, cid string) ([]byte, error) {
|
|||
return data, nil
|
||||
}
|
||||
|
||||
func UploadAtprotoBlob(session *AtprotoSession, pdsUrl string, data []byte, mimeType string) (*AtprotoBlob, error) {
|
||||
req, _ := http.NewRequest(http.MethodPost, pdsUrl + "/xrpc/com.atproto.repo.uploadBlob", bytes.NewReader(data))
|
||||
func UploadAtprotoBlob(session *AtprotoSession, data []byte, mimeType string) (*AtprotoBlob, error) {
|
||||
req, _ := http.NewRequest(http.MethodPost, session.PdsUrl + "/xrpc/com.atproto.repo.uploadBlob", bytes.NewReader(data))
|
||||
req.Header.Set("Content-Type", mimeType)
|
||||
req.Header.Set("Authorization", "Bearer " + session.AccessJwt)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue