login to bsky for each write
This commit is contained in:
@@ -17,7 +17,6 @@ import (
|
||||
type blueskyoutput struct {
|
||||
identifier string
|
||||
password string
|
||||
client *xrpc.Client
|
||||
}
|
||||
|
||||
func BlueskyOutput(identifier string, password string) *blueskyoutput {
|
||||
@@ -26,13 +25,17 @@ func BlueskyOutput(identifier string, password string) *blueskyoutput {
|
||||
password: password,
|
||||
}
|
||||
|
||||
return blueskyoutput
|
||||
}
|
||||
|
||||
func (bo *blueskyoutput) Write(str string) error {
|
||||
cli := &xrpc.Client{
|
||||
Host: "https://bsky.social",
|
||||
}
|
||||
|
||||
input := &atproto.ServerCreateSession_Input{
|
||||
Identifier: blueskyoutput.identifier,
|
||||
Password: blueskyoutput.password,
|
||||
Identifier: bo.identifier,
|
||||
Password: bo.password,
|
||||
}
|
||||
|
||||
output, err := atproto.ServerCreateSession(context.TODO(), cli, input)
|
||||
@@ -46,22 +49,16 @@ func BlueskyOutput(identifier string, password string) *blueskyoutput {
|
||||
Did: output.Did,
|
||||
}
|
||||
|
||||
blueskyoutput.client = cli
|
||||
|
||||
return blueskyoutput
|
||||
}
|
||||
|
||||
func (bo *blueskyoutput) Write(str string) error {
|
||||
Recordinput := &atproto.RepoCreateRecord_Input{
|
||||
Collection: "app.bsky.feed.post",
|
||||
Repo: bo.client.Auth.Did, // "matope.bsky.social" のDID
|
||||
Repo: cli.Auth.Did, // "matope.bsky.social" のDID
|
||||
Record: &lexutil.LexiconTypeDecoder{&bsky.FeedPost{
|
||||
Text: str,
|
||||
CreatedAt: time.Now().Format(util.ISO8601),
|
||||
Langs: []string{"ja"},
|
||||
}},
|
||||
}
|
||||
_, recerr := atproto.RepoCreateRecord(context.TODO(), bo.client, Recordinput)
|
||||
_, recerr := atproto.RepoCreateRecord(context.TODO(), cli, Recordinput)
|
||||
|
||||
if recerr != nil {
|
||||
fmt.Fprint(os.Stderr, "bsky err: ")
|
||||
|
||||
Reference in New Issue
Block a user