Add CreatePost
This commit is contained in:
parent
84535cb5a7
commit
b4151aeee9
4 changed files with 512 additions and 32 deletions
28
bluesky.go
28
bluesky.go
|
|
@ -8,6 +8,8 @@ import (
|
|||
|
||||
"github.com/charmbracelet/log"
|
||||
"github.com/dghubble/sling"
|
||||
|
||||
appbsky "github.com/bluesky-social/indigo/api/bsky"
|
||||
)
|
||||
|
||||
type BlueskyConfig struct {
|
||||
|
|
@ -154,6 +156,24 @@ func (bluesky *Bluesky) GetPost(uri string) *Post {
|
|||
return post.Value
|
||||
}
|
||||
|
||||
func (bluesky *Bluesky) CreateRecord(post *appbsky.FeedPost) *CommitResponse {
|
||||
bluesky.CheckSessionValid()
|
||||
|
||||
resp := new(CommitResponse)
|
||||
params := struct {
|
||||
Repo string `json:"repo"`
|
||||
Collection string `json:"collection"`
|
||||
Record *appbsky.FeedPost `json:"record"`
|
||||
}{
|
||||
Repo: bluesky.Cfg.DID,
|
||||
Collection: "app.bsky.feed.post",
|
||||
Record: post,
|
||||
}
|
||||
bluesky.sling.New().Set("Authorization", fmt.Sprintf("Bearer %s", bluesky.Cfg.AccessJWT)).
|
||||
Post("/xrpc/com.atproto.repo.createRecord").BodyJSON(params).Receive(resp, resp)
|
||||
return resp
|
||||
}
|
||||
|
||||
func (bluesky *Bluesky) DeleteRecord(args []string) *CommitResponse {
|
||||
bluesky.CheckSessionValid()
|
||||
|
||||
|
|
@ -172,9 +192,11 @@ func (bluesky *Bluesky) DeleteRecord(args []string) *CommitResponse {
|
|||
return resp
|
||||
}
|
||||
|
||||
func (bluesky *Bluesky) FetchPost(did string, rkey string) *[]FetchedPost {
|
||||
func (bluesky *Bluesky) FetchPost(did string, rkey string) (*[]FetchedPost, string) {
|
||||
resp := &struct {
|
||||
Posts []FetchedPost `json:"posts"`
|
||||
Posts []FetchedPost `json:"posts,omitempty"`
|
||||
Error string `json:"error"`
|
||||
Message string `json:"message"`
|
||||
}{}
|
||||
params := struct {
|
||||
URIs string `url:"uris"`
|
||||
|
|
@ -183,5 +205,5 @@ func (bluesky *Bluesky) FetchPost(did string, rkey string) *[]FetchedPost {
|
|||
}
|
||||
bluesky.sling.New().Base("https://public.api.bsky.app").
|
||||
Get("/xrpc/app.bsky.feed.getPosts").QueryStruct(¶ms).Receive(resp, resp)
|
||||
return &resp.Posts
|
||||
return &resp.Posts, resp.Message
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue