add support for links as posts

This commit is contained in:
Astra 2025-07-01 07:08:46 +01:00
parent 2bb3946237
commit bfa829d8c7
4 changed files with 240 additions and 33 deletions

View file

@ -28,7 +28,7 @@ func NewBSky() *BSky {
}
}
func (b *BSky) getPDS() error {
func (b *BSky) ResolveHandle(handle string) (string, error) {
httpClient := &http.Client{Timeout: 3 * time.Second}
resp := new(BSkySessionResponse)
errResp := &struct {
@ -38,23 +38,29 @@ func (b *BSky) getPDS() error {
params := struct {
Handle string `url:"handle"`
}{
Handle: b.Bluesky.Cfg.Handle,
Handle: handle,
}
sling.New().Base("https://public.api.bsky.app/").Client(httpClient).
Get("/xrpc/com.atproto.identity.resolveHandle").QueryStruct(params).
Receive(resp, errResp)
if errResp.Error != "" {
return errors.New(errResp.Message)
return "", errors.New(errResp.Message)
}
return resp.DID, nil
}
func (b *BSky) getPDS() error {
did, _ := b.ResolveHandle(b.Bluesky.Cfg.Handle)
var didURL url.URL
if strings.HasPrefix(resp.DID, "did:web:") {
didURL.Host = "https://" + resp.DID[8:]
if strings.HasPrefix(did, "did:web:") {
didURL.Host = "https://" + did[8:]
didURL.Path = "/.well-known/did.json"
} else if strings.HasPrefix(resp.DID, "did:plc:") {
} else if strings.HasPrefix(did, "did:plc:") {
didURL.Host = "https://plc.directory"
didURL.Path = "/" + resp.DID
didURL.Path = "/" + did
} else {
return errors.New("DID is not supported")
}
@ -104,7 +110,7 @@ func (b *BSky) Auth(authData []string) error {
b.Bluesky.Cfg.AppPassword = authData[1]
err = b.Bluesky.CreateSession(b.Bluesky.Cfg)
if err != nil {
return errors.New(fmt.Sprintf("unable to auth: %s", err))
return fmt.Errorf("unable to auth: %s", err)
}
b.Bluesky.Cfg.AppPassword = "" // we don't need to save this
PersistAuthSession(b.Bluesky.Cfg)