This commit is contained in:
parent
85fc508aa3
commit
c9cc325ef7
3 changed files with 77 additions and 51 deletions
|
|
@ -10,6 +10,17 @@ import (
|
|||
"github.com/dghubble/sling"
|
||||
)
|
||||
|
||||
const (
|
||||
// URI parsing indices for at:// URIs split by "/"
|
||||
uriRepoIndex = 2
|
||||
uriCollectionIndex = 3
|
||||
uriRkeyIndex = 4
|
||||
|
||||
// Custom collections
|
||||
PostCollection = "blue.zio.bsky2tg.post"
|
||||
AliasCollection = "blue.zio.bsky2tg.alias"
|
||||
)
|
||||
|
||||
type BlueskyConfig struct {
|
||||
PDSURL string `json:"pds-url"`
|
||||
Repo string `json:"repo"`
|
||||
|
|
@ -72,10 +83,11 @@ type Link struct {
|
|||
}
|
||||
|
||||
type Bluesky struct {
|
||||
Cfg *BlueskyConfig
|
||||
HttpClient *http.Client
|
||||
Logger *log.Logger
|
||||
sling *sling.Sling
|
||||
Cfg *BlueskyConfig
|
||||
HttpClient *http.Client
|
||||
Logger *log.Logger
|
||||
sling *sling.Sling
|
||||
publicSling *sling.Sling
|
||||
}
|
||||
|
||||
func (bluesky *Bluesky) CreateSession(cfg *BlueskyConfig) error {
|
||||
|
|
@ -88,14 +100,14 @@ func (bluesky *Bluesky) CreateSession(cfg *BlueskyConfig) error {
|
|||
}
|
||||
resp := new(BSkySessionResponse)
|
||||
|
||||
bluesky.sling.New().Post("/xrpc/com.atproto.server.createSession").BodyJSON(body).ReceiveSuccess(resp)
|
||||
bluesky.sling.New().Client(bluesky.HttpClient).
|
||||
Post("/xrpc/com.atproto.server.createSession").BodyJSON(body).ReceiveSuccess(resp)
|
||||
if resp.AccessJWT != "" {
|
||||
cfg.AccessJWT = resp.AccessJWT
|
||||
cfg.RefreshJWT = resp.RefreshJWT
|
||||
return nil
|
||||
}
|
||||
|
||||
bluesky.sling.New().Set("Authorization", fmt.Sprintf("Bearer %s", bluesky.Cfg.AccessJWT))
|
||||
return errors.New("unable to authenticate, check handle/password")
|
||||
}
|
||||
|
||||
|
|
@ -161,7 +173,7 @@ func (bluesky *Bluesky) CommitTelegramResponse(data *TelegramRecord, rkey string
|
|||
Record TelegramRecord `json:"record"`
|
||||
}{
|
||||
Repo: bluesky.Cfg.DID,
|
||||
Collection: "blue.zio.bsky2tg.post",
|
||||
Collection: PostCollection,
|
||||
RKey: rkey,
|
||||
Record: TelegramRecord{
|
||||
ChannelID: data.ChannelID,
|
||||
|
|
@ -193,7 +205,7 @@ func (bluesky *Bluesky) GetTelegramData(rkey string) (*TelegramRecord, string) {
|
|||
RKey string `url:"rkey"`
|
||||
}{
|
||||
Repo: bluesky.Cfg.DID,
|
||||
Collection: "blue.zio.bsky2tg.post",
|
||||
Collection: PostCollection,
|
||||
RKey: rkey,
|
||||
}
|
||||
|
||||
|
|
@ -215,9 +227,9 @@ func (bluesky *Bluesky) GetPost(uri string) *Post {
|
|||
Repo string `url:"repo"`
|
||||
Collection string `url:"collection"`
|
||||
}{
|
||||
RKey: args[4],
|
||||
Repo: args[2],
|
||||
Collection: args[3],
|
||||
RKey: args[uriRkeyIndex],
|
||||
Repo: args[uriRepoIndex],
|
||||
Collection: args[uriCollectionIndex],
|
||||
}
|
||||
bluesky.sling.New().Get("/xrpc/com.atproto.repo.getRecord").QueryStruct(params).ReceiveSuccess(&post)
|
||||
|
||||
|
|
@ -249,7 +261,7 @@ func (bluesky *Bluesky) FetchAliases() []Records {
|
|||
Collection string `url:"collection"`
|
||||
}{
|
||||
Repo: bluesky.Cfg.DID,
|
||||
Collection: "blue.zio.bsky2tg.alias",
|
||||
Collection: AliasCollection,
|
||||
}
|
||||
|
||||
bluesky.sling.New().Get("/xrpc/com.atproto.repo.listRecords").QueryStruct(¶ms).Receive(resp, resp)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue