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