Working on Posting

This commit is contained in:
2026-02-04 22:06:36 -06:00
parent 4ed5d821da
commit 687e64e701
4 changed files with 79 additions and 14 deletions

View File

@@ -22,10 +22,13 @@ THE SOFTWARE.
package data
import (
"context"
"fmt"
"log/slog"
"time"
"git.bullercodeworks.com/brian/expds/data/models"
"github.com/bluesky-social/indigo/atproto/syntax"
"github.com/spf13/viper"
)
@@ -37,6 +40,8 @@ type Repo struct {
handler *AppLogHandler
logFunc func(string, ...any)
context context.Context
}
func NewRepo() (*Repo, error) {
@@ -44,6 +49,7 @@ func NewRepo() (*Repo, error) {
LoadedPDSs: make(map[string]*models.Pds),
BestBy: time.Minute * 15,
handler: NewAppLogHandler(nil),
context: context.Background(),
}
if viper.GetBool(KeyDebug) {
r.handler.SetLevel(slog.LevelDebug)
@@ -70,6 +76,32 @@ func (r *Repo) GetPDS(atId string) (*models.Pds, error) {
return p, nil
}
func (r *Repo) SendToPDS() error {
session, err := r.Auth.GetSession()
if err != nil {
return err
}
c := session.APIClient()
body := map[string]any{
"repo": c.AccountDID.String(),
"collection": "com.bullercodeworks.expds.status",
"record": map[string]any{
"$type": "com.bullercodeworks.expds.status",
"text": "writeable",
"createdAt": syntax.DatetimeNow(),
},
}
var resp struct {
Uri syntax.ATURI `json:"uri"`
}
slog.Debug("posting expds status...")
if err := c.Post(r.context, "com.atproto.repo.CreateRecord", body, &resp); err != nil {
return err
}
slog.Debug(fmt.Sprintf("posted: %s :: %s", resp.Uri.Authority(), resp.Uri.RecordKey()))
return nil
}
func (r *Repo) SetLogFunc(l func(string, ...any)) {
r.logFunc = l
r.handler = NewAppLogHandler(r.logFunc)