chore: add twt help
This commit is contained in:
parent
2bb2eec993
commit
6579c50c09
10
feed.go
10
feed.go
@ -75,10 +75,12 @@ var (
|
|||||||
refresh_rate
|
refresh_rate
|
||||||
)
|
)
|
||||||
values (?, ?, ?, ?, ?, ?, ?)` + repeat + `
|
values (?, ?, ?, ?, ?, ?, ?)` + repeat + `
|
||||||
ON CONFLICT (feed_id) DO NOTHING`, r * 7
|
ON CONFLICT (feed_id) DO NOTHING
|
||||||
|
`, r * 7
|
||||||
}
|
}
|
||||||
updateFeed = `
|
updateFeed = `
|
||||||
update feeds set
|
update feeds set
|
||||||
|
nick = ?,
|
||||||
state = ?,
|
state = ?,
|
||||||
last_scan_on = ?,
|
last_scan_on = ?,
|
||||||
refresh_rate = ?,
|
refresh_rate = ?,
|
||||||
@ -104,7 +106,10 @@ var (
|
|||||||
tags
|
tags
|
||||||
)
|
)
|
||||||
values (?, ?, ?, ?, ?, ?, ?)` + repeat + `
|
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 = `
|
fetchFeeds = `
|
||||||
@ -155,6 +160,7 @@ func (f *Feed) Save(ctx context.Context, db db) error {
|
|||||||
_, err := db.ExecContext(
|
_, err := db.ExecContext(
|
||||||
ctx,
|
ctx,
|
||||||
updateFeed,
|
updateFeed,
|
||||||
|
f.Nick,
|
||||||
f.State, // state
|
f.State, // state
|
||||||
f.LastScanOn, // last_scan_on
|
f.LastScanOn, // last_scan_on
|
||||||
f.RefreshRate, // refresh_rate
|
f.RefreshRate, // refresh_rate
|
||||||
|
43
http.go
43
http.go
@ -20,6 +20,25 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const iAmTheWatcher = "I am the Watcher. I am your guide through this vast new twtiverse."
|
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 {
|
func httpServer(ctx context.Context, app *appState) error {
|
||||||
ctx, span := otel.Span(ctx)
|
ctx, span := otel.Span(ctx)
|
||||||
@ -41,6 +60,11 @@ func httpServer(ctx context.Context, app *appState) error {
|
|||||||
w.Write([]byte("ok"))
|
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) {
|
http.HandleFunc("/api/plain/conv/{hash}", func(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx, span := otel.Span(r.Context())
|
ctx, span := otel.Span(r.Context())
|
||||||
defer span.End()
|
defer span.End()
|
||||||
@ -102,8 +126,7 @@ func httpServer(ctx context.Context, app *appState) error {
|
|||||||
twt, _ := lextwt.ParseLine(o.Text, &twter)
|
twt, _ := lextwt.ParseLine(o.Text, &twter)
|
||||||
twts = append(twts, twt)
|
twts = append(twts, twt)
|
||||||
}
|
}
|
||||||
var preamble lextwt.Comments
|
preamble := add(PREAMBLE_DOCS, "self = /conv/%s", hash)
|
||||||
preamble = add(preamble, "self = /conv/%s", hash)
|
|
||||||
|
|
||||||
reg := lextwt.NewTwtRegistry(preamble, twts)
|
reg := lextwt.NewTwtRegistry(preamble, twts)
|
||||||
reg.WriteTo(w)
|
reg.WriteTo(w)
|
||||||
@ -206,16 +229,13 @@ func httpServer(ctx context.Context, app *appState) error {
|
|||||||
twt, _ := lextwt.ParseLine(o.Text, &twter)
|
twt, _ := lextwt.ParseLine(o.Text, &twter)
|
||||||
twts = append(twts, twt)
|
twts = append(twts, twt)
|
||||||
}
|
}
|
||||||
var preamble lextwt.Comments
|
preamble := add(PREAMBLE_DOCS, "twt range = 1 %d", end)
|
||||||
preamble = add(preamble, iAmTheWatcher)
|
preamble = add(preamble, "self = %s/api/plain/twt%s", hostname, mkqry(uri, limit, offset))
|
||||||
preamble = add(preamble, "")
|
|
||||||
preamble = add(preamble, "range = 1 %d", end)
|
|
||||||
preamble = add(preamble, "self = /api/plain/twt%s", mkqry(uri, limit, offset))
|
|
||||||
if next := offset + int64(len(twts)); next < end {
|
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 {
|
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)
|
reg := lextwt.NewTwtRegistry(preamble, twts)
|
||||||
@ -278,10 +298,7 @@ func httpServer(ctx context.Context, app *appState) error {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
var preamble lextwt.Comments
|
reg := lextwt.NewTwtRegistry(PREAMBLE_DOCS, twts)
|
||||||
preamble = add(preamble, iAmTheWatcher)
|
|
||||||
|
|
||||||
reg := lextwt.NewTwtRegistry(preamble, twts)
|
|
||||||
reg.WriteTo(w)
|
reg.WriteTo(w)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -208,6 +208,10 @@ func processorLoop(ctx context.Context, db db, fetch *pool[*Feed, *Response]) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if nick := twtfile.Twter().Nick; nick != "" {
|
||||||
|
f.Nick = nick
|
||||||
|
}
|
||||||
|
|
||||||
f.RefreshRate, f.State = checkTemp(twtfile.Twts())
|
f.RefreshRate, f.State = checkTemp(twtfile.Twts())
|
||||||
f.LastError.String = ""
|
f.LastError.String = ""
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user