chore: changes to feed
This commit is contained in:
parent
5c97bfb182
commit
b34c9bc99f
11
feed.go
11
feed.go
@ -322,9 +322,16 @@ func storeFeed(ctx context.Context, db db, f types.TwtFile) error {
|
||||
_, part, ok := strings.Cut(prev.Value(), " ")
|
||||
if ok {
|
||||
uri:= f.Twter().URI
|
||||
if u, ok := f.Info().GetN("url", 0); ok {
|
||||
uri = u.Value()
|
||||
}
|
||||
if u, ok := f.Info().GetN("uri", 0); ok {
|
||||
uri = u.Value()
|
||||
}
|
||||
|
||||
part = uri[:strings.LastIndex(uri, "/")+1] + part
|
||||
childID := urlNS.UUID5(part)
|
||||
|
||||
fmt.Println("found prev", uri, part)
|
||||
args = append(args,
|
||||
childID, // feed_id
|
||||
feedID, // parent_id
|
||||
@ -332,7 +339,7 @@ func storeFeed(ctx context.Context, db db, f types.TwtFile) error {
|
||||
part, // uri
|
||||
"once", // state
|
||||
nil, // last_scan_on
|
||||
refreshRate, // refresh_rate
|
||||
0, // refresh_rate
|
||||
)
|
||||
}
|
||||
}
|
||||
|
62
http.go
62
http.go
@ -109,34 +109,36 @@ func httpServer(c *console, app *appState) error {
|
||||
ctx, span := otel.Span(r.Context())
|
||||
defer span.End()
|
||||
|
||||
args := make([]any, 0, 3)
|
||||
uriarg := ""
|
||||
uri := r.URL.Query().Get("uri")
|
||||
if uri != "" {
|
||||
uriarg = "and uri = ?"
|
||||
args = append(args, uri)
|
||||
}
|
||||
|
||||
limit := 100
|
||||
if v, ok := strconv.Atoi(r.URL.Query().Get("limit")); ok == nil {
|
||||
limit = v
|
||||
}
|
||||
|
||||
offset := 0
|
||||
if v, ok := strconv.Atoi(r.URL.Query().Get("offset")); ok == nil {
|
||||
offset = v
|
||||
}
|
||||
|
||||
args := []any{limit, offset}
|
||||
|
||||
uriqry := ""
|
||||
if u := r.URL.Query().Get("uri"); u != "" {
|
||||
uriqry = "and uri = ?"
|
||||
args = append([]any{u}, args...)
|
||||
}
|
||||
args = append(args, limit, offset)
|
||||
|
||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||
rows, err := db.QueryContext(
|
||||
ctx,
|
||||
`SELECT
|
||||
feed_id,
|
||||
hash,
|
||||
conv,
|
||||
`SELECT
|
||||
feed_id,
|
||||
hash,
|
||||
conv,
|
||||
nick,
|
||||
uri,
|
||||
text
|
||||
FROM twts
|
||||
FROM twts
|
||||
JOIN (
|
||||
SELECT
|
||||
feed_id,
|
||||
@ -144,7 +146,7 @@ func httpServer(c *console, app *appState) error {
|
||||
uri
|
||||
FROM feeds
|
||||
where state not in ('frozen', 'permanantly-dead')
|
||||
`+uriqry+`
|
||||
`+uriarg+`
|
||||
) using (feed_id)
|
||||
order by ulid desc
|
||||
limit ?
|
||||
@ -179,7 +181,12 @@ func httpServer(c *console, app *appState) error {
|
||||
twts = append(twts, twt)
|
||||
}
|
||||
var preamble lextwt.Comments
|
||||
preamble = append(preamble, lextwt.NewComment("# self = /api/plain/twts"))
|
||||
preamble = append(preamble, lextwt.NewComment("# I am the Watcher. I am your guide through this vast new twtiverse."))
|
||||
preamble = append(preamble, lextwt.NewComment("# self = /api/plain/twts"+mkqry(uri, limit, offset)))
|
||||
preamble = append(preamble, lextwt.NewComment("# next = /api/plain/twts"+mkqry(uri, limit, offset+len(twts))))
|
||||
if offset > 0 {
|
||||
preamble = append(preamble, lextwt.NewComment("# prev = /api/plain/twts"+mkqry(uri, limit, offset-limit)))
|
||||
}
|
||||
|
||||
reg := lextwt.NewTwtRegistry(preamble, twts)
|
||||
reg.WriteTo(w)
|
||||
@ -271,3 +278,28 @@ func notAny(s string, chars string) bool {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
func mkqry(uri string, limit, offset int) string {
|
||||
qry := make([]string, 0, 3)
|
||||
|
||||
if uri != "" {
|
||||
qry = append(qry, "uri=" + uri)
|
||||
}
|
||||
|
||||
limit = min(100, max(1, limit))
|
||||
if limit != 100 {
|
||||
qry = append(qry, fmt.Sprint("limit=", limit))
|
||||
}
|
||||
|
||||
offset = max(0, offset)
|
||||
if offset != 0 {
|
||||
qry = append(qry, fmt.Sprint("offset=", offset))
|
||||
}
|
||||
|
||||
if len(qry) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
return "?" + strings.Join(qry, "&")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user