chore: add twt help

This commit is contained in:
xuu committed 2025-03-30 12:12:10 -06:00
1 parent 2bb2eec993
commit 6579c50c09
3 files changed
+42 -15

No files matched your search

+30 -13
View File
@@ -20,6 +20,25 @@ import (
)
const iAmTheWatcher = "I am the Watcher. I am your guide through this vast new twtiverse."
const hostname = "https://watcher.sour.is"
var PREAMBLE_DOCS = func() lextwt.Comments {
c := add(nil, iAmTheWatcher)
c = add(c, "")
c = add(c,"Usage:")
c = add(c," %s/api/plain/users View list of users and latest twt date.", hostname)
c = add(c," %s/api/plain/twt View all twts in decending order.", hostname)
c = add(c," %s/api/plain/conv/:hash View all twts for a conversation subject.", hostname)
c = add(c,"")
c = add(c,"Options:")
c = add(c," uri Filter to show a specific users twts.")
c = add(c," offset Start index for quey.")
c = add(c," limit Count of items to return (going back in time).")
return add(c,"")
}()
func httpServer(ctx context.Context, app *appState) error {
ctx, span := otel.Span(ctx)
@@ -41,6 +60,11 @@ func httpServer(ctx context.Context, app *appState) error {
w.Write([]byte("ok"))
})
http.HandleFunc("/api/plain", func(w http.ResponseWriter, r *http.Request) {
reg := lextwt.NewTwtRegistry(PREAMBLE_DOCS, nil)
reg.WriteTo(w)
})
http.HandleFunc("/api/plain/conv/{hash}", func(w http.ResponseWriter, r *http.Request) {
ctx, span := otel.Span(r.Context())
defer span.End()
@@ -102,8 +126,7 @@ func httpServer(ctx context.Context, app *appState) error {
twt, _ := lextwt.ParseLine(o.Text, &twter)
twts = append(twts, twt)
}
var preamble lextwt.Comments
preamble = add(preamble, "self = /conv/%s", hash)
preamble := add(PREAMBLE_DOCS, "self = /conv/%s", hash)
reg := lextwt.NewTwtRegistry(preamble, twts)
reg.WriteTo(w)
@@ -206,16 +229,13 @@ func httpServer(ctx context.Context, app *appState) error {
twt, _ := lextwt.ParseLine(o.Text, &twter)
twts = append(twts, twt)
}
var preamble lextwt.Comments
preamble = add(preamble, iAmTheWatcher)
preamble = add(preamble, "")
preamble = add(preamble, "range = 1 %d", end)
preamble = add(preamble, "self = /api/plain/twt%s", mkqry(uri, limit, offset))
preamble := add(PREAMBLE_DOCS, "twt range = 1 %d", end)
preamble = add(preamble, "self = %s/api/plain/twt%s", hostname, mkqry(uri, limit, offset))
if next := offset + int64(len(twts)); next < end {
preamble = add(preamble, "next = /api/plain/twt%s", mkqry(uri, limit, next))
preamble = add(preamble, "next = %s/api/plain/twt%s", hostname, mkqry(uri, limit, next))
}
if prev := offset - int64(limit); prev > 0 {
preamble = add(preamble, "prev = /api/plain/twt%s", mkqry(uri, limit, prev))
preamble = add(preamble, "prev = %s/api/plain/twt%s", hostname, mkqry(uri, limit, prev))
}
reg := lextwt.NewTwtRegistry(preamble, twts)
@@ -278,10 +298,7 @@ func httpServer(ctx context.Context, app *appState) error {
))
}
var preamble lextwt.Comments
preamble = add(preamble, iAmTheWatcher)
reg := lextwt.NewTwtRegistry(preamble, twts)
reg := lextwt.NewTwtRegistry(PREAMBLE_DOCS, twts)
reg.WriteTo(w)
})