Lasa is a stateless proxy that generates a RSS or an Atom feed from a Standard.site publication. lasa.anhgelus.world
rss atom atprotocol standard-site atproto
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(cli): list documents

+82
+25
client.go
··· 1 1 package lasa 2 2 3 3 import ( 4 + "context" 4 5 "net" 5 6 "net/http" 6 7 "time" 7 8 8 9 "github.com/valkey-io/valkey-go" 10 + site "tangled.org/anhgelus.world/goat-site" 9 11 "tangled.org/anhgelus.world/xrpc" 10 12 "tangled.org/anhgelus.world/xrpc/atproto" 11 13 ) 12 14 13 15 func NewClient(client *http.Client, resolver *net.Resolver, cache valkey.Client, dur time.Duration) xrpc.Client { 16 + client.Timeout = 30 * time.Second 14 17 dir := NewDirectory(atproto.NewDirectory(client, resolver), cache, dur) 15 18 return xrpc.NewClient(client, dir) 16 19 } 20 + 21 + func ListDocuments( 22 + ctx context.Context, 23 + client xrpc.Client, 24 + did *atproto.DID, 25 + pub atproto.RawURI, 26 + ) ([]xrpc.RecordStored[*site.Document], error) { 27 + rawDocs, _, err := xrpc.ListRecords[*site.Document](ctx, client, did, 0, "", false) 28 + if err != nil { 29 + return nil, err 30 + } 31 + var docs []xrpc.RecordStored[*site.Document] 32 + for _, doc := range rawDocs { 33 + if !doc.Value.Site.IsAT() { 34 + continue 35 + } 36 + if doc.Value.Site.AT().String() == pub.String() { 37 + docs = append(docs, doc) 38 + } 39 + } 40 + return docs, nil 41 + }
+49
cmd/internal/print.go
··· 5 5 "flag" 6 6 "fmt" 7 7 "os" 8 + "strings" 8 9 "text/tabwriter" 9 10 10 11 site "tangled.org/anhgelus.world/goat-site" ··· 71 72 panic(err) 72 73 } 73 74 } 75 + 76 + func DisplayDocument( 77 + ctx context.Context, 78 + client xrpc.Client, 79 + did *atproto.DID, 80 + raw atproto.RawURI, 81 + pub *site.Publication, 82 + doc *site.Document, 83 + ) { 84 + uri, err := raw.URI(context.Background(), client.Directory()) 85 + if err != nil { 86 + panic(err) 87 + } 88 + url := pub.URL 89 + url.Path = *doc.Path 90 + w := tabwriter.NewWriter(os.Stdout, 0, 2, 1, ' ', 0) 91 + fmt.Fprintln(w, "Name:\t", pub.Name) 92 + fmt.Fprintln(w, "URL:\t", url.String()) 93 + fmt.Fprintln(w, "AT URL:\t", raw) 94 + fmt.Fprintln(w, "RecordKey:\t", *uri.RecordKey()) 95 + if pub.Description != nil { 96 + fmt.Fprintln(w, "Description:\t", *pub.Description) 97 + } 98 + if len(doc.Tags) > 0 { 99 + fmt.Fprintln(w, "Tags:\t", strings.Join(doc.Tags, " ")) 100 + } 101 + ok, err := doc.Verify(context.Background(), client.HTTP(), url, did, *uri.RecordKey()) 102 + if err != nil { 103 + fmt.Fprintln(w, "Verification:\t error:", err) 104 + return 105 + } else { 106 + fmt.Fprintf(w, "Verification:\t %v\n", ok) 107 + } 108 + fmt.Fprintln(w, "Publicated at:\t", doc.PublishedAt.Format(atproto.TimeFormat)) 109 + if doc.UpdatedAt != nil { 110 + fmt.Fprintln(w, "Updated at:\t", doc.UpdatedAt.Format(atproto.TimeFormat)) 111 + } 112 + if doc.TextContent != "" { 113 + fmt.Fprintln(w) 114 + fmt.Fprintln(w, "=== Content ===") 115 + fmt.Fprintln(w, doc.TextContent) 116 + } 117 + fmt.Fprintln(w) 118 + err = w.Flush() 119 + if err != nil { 120 + panic(err) 121 + } 122 + }
+8
cmd/lasa/publication.go
··· 66 66 panic(err) 67 67 } 68 68 internal.DisplayPublication(context.Background(), client, did, pub.URI, pub.Value) 69 + docs, err := lasa.ListDocuments(context.Background(), client, did, pub.URI) 70 + if err != nil { 71 + panic(err) 72 + } 73 + for _, doc := range docs { 74 + internal.DisplayDocument(context.Background(), client, did, doc.URI, pub.Value, doc.Value) 75 + fmt.Println("-----------------------------") 76 + } 69 77 }