package data import ( "time" "git.bullercodeworks.com/brian/expds/data/models" "github.com/bluesky-social/indigo/atproto/syntax" ) func (r *Repo) fetchPds(atId string) (*models.Pds, error) { p, err := models.NewPdsFromDid(atId) if err != nil { return nil, err } r.LoadedPDSs[atId] = p return p, nil } func (r *Repo) ReloadPds(atId string) (*models.Pds, error) { return r.fetchPds(atId) } func (r *Repo) GetPDS(atId string) (*models.Pds, error) { if p, ok := r.LoadedPDSs[atId]; ok && time.Since(p.RefreshTime) < r.BestBy { return p, nil } return r.fetchPds(atId) } func (r *Repo) SendToPDS(did syntax.DID) error { session, err := r.Auth.GetSession(did) 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"` } r.Logger.Debug("posting expds status...") if err := c.Post(r.context, "com.atproto.repo.createRecord", body, &resp); err != nil { return err } r.Logger.Debug("posted: %s :: %s", resp.Uri.Authority(), resp.Uri.RecordKey()) return nil } func (r *Repo) DeleteRecord(did syntax.DID, collection syntax.NSID, rkey string) error { session, err := r.Auth.GetSession(did) if err != nil { return err } c := session.APIClient() body := map[string]any{ "repo": c.AccountDID, "collection": collection, "rkey": rkey, } var resp struct { Cid syntax.CID `json:"cid"` Rev syntax.TID `json:"rev"` } r.Logger.Debug("deleting record (%s)", rkey) if err := c.Post(r.context, "com.atproto.repo.deleteRecord", body, &resp); err != nil { return err } r.Logger.Debug("posted: %s :: %s", resp.Cid.String(), resp.Rev.String()) return nil }