From 6579c50c098ce959e24a8452a7a5901b528f36a6 Mon Sep 17 00:00:00 2001 From: xuu Date: Sun, 30 Mar 2025 12:12:10 -0600 Subject: [PATCH] chore: add twt help --- feed.go | 10 ++++++++-- http.go | 43 ++++++++++++++++++++++++++++++------------- refresh-loop.go | 4 ++++ 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/feed.go b/feed.go index 71118eb..1b10db2 100644 --- a/feed.go +++ b/feed.go @@ -75,10 +75,12 @@ var ( refresh_rate ) values (?, ?, ?, ?, ?, ?, ?)` + repeat + ` - ON CONFLICT (feed_id) DO NOTHING`, r * 7 + ON CONFLICT (feed_id) DO NOTHING + `, r * 7 } updateFeed = ` update feeds set + nick = ?, state = ?, last_scan_on = ?, refresh_rate = ?, @@ -104,7 +106,10 @@ var ( tags ) values (?, ?, ?, ?, ?, ?, ?)` + repeat + ` - ON CONFLICT (feed_id, ulid) DO NOTHING`, r * 7 + ON CONFLICT (feed_id, ulid) DO UPDATE SET + conv = excluded.conv, + hash = excluded.hash + `, r * 7 } fetchFeeds = ` @@ -155,6 +160,7 @@ func (f *Feed) Save(ctx context.Context, db db) error { _, err := db.ExecContext( ctx, updateFeed, + f.Nick, f.State, // state f.LastScanOn, // last_scan_on f.RefreshRate, // refresh_rate diff --git a/http.go b/http.go index 6377a00..809aea1 100644 --- a/http.go +++ b/http.go @@ -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) }) diff --git a/refresh-loop.go b/refresh-loop.go index e59a099..f510762 100644 --- a/refresh-loop.go +++ b/refresh-loop.go @@ -208,6 +208,10 @@ func processorLoop(ctx context.Context, db db, fetch *pool[*Feed, *Response]) { continue } + if nick := twtfile.Twter().Nick; nick != "" { + f.Nick = nick + } + f.RefreshRate, f.State = checkTemp(twtfile.Twts()) f.LastError.String = ""