Delete records and stuff
This commit is contained in:
48
data/repo.go
48
data/repo.go
@@ -23,12 +23,10 @@ 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"
|
||||
)
|
||||
|
||||
@@ -66,52 +64,6 @@ func NewRepo() (*Repo, error) {
|
||||
return r, nil
|
||||
}
|
||||
|
||||
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(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)
|
||||
|
||||
Reference in New Issue
Block a user