Compare commits
	
		
			2 Commits
		
	
	
		
			a0614435ff
			...
			4efdc915e6
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 4efdc915e6 | |||
| 98b8af64ed | 
							
								
								
									
										11
									
								
								feed.go
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								feed.go
									
									
									
									
									
								
							@ -322,16 +322,9 @@ 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
 | 
			
		||||
@ -339,7 +332,7 @@ func storeFeed(ctx context.Context, db db, f types.TwtFile) error {
 | 
			
		||||
				part,                   // uri
 | 
			
		||||
				"once",                 // state
 | 
			
		||||
				nil,                    // last_scan_on
 | 
			
		||||
				0,                      // refresh_rate
 | 
			
		||||
				refreshRate,            // refresh_rate
 | 
			
		||||
			)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										53
									
								
								http.go
									
									
									
									
									
								
							
							
						
						
									
										53
									
								
								http.go
									
									
									
									
									
								
							@ -109,25 +109,24 @@ 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 != "" {
 | 
			
		||||
			feed_id := urlNS.UUID5(uri)
 | 
			
		||||
			uriarg = "and feed_id = ?"
 | 
			
		||||
			args = append(args, feed_id)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		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 != "" {
 | 
			
		||||
			feed_id := urlNS.UUID5(u)
 | 
			
		||||
			uriqry = "and feed_id = ?"
 | 
			
		||||
			args = append([]any{feed_id}, args...)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		w.Header().Set("Content-Type", "text/plain; charset=utf-8")
 | 
			
		||||
		rows, err := db.QueryContext(
 | 
			
		||||
			ctx,
 | 
			
		||||
@ -146,7 +145,7 @@ func httpServer(c *console, app *appState) error {
 | 
			
		||||
							uri
 | 
			
		||||
						FROM feeds
 | 
			
		||||
						where state not in ('frozen', 'permanantly-dead')
 | 
			
		||||
						`+uriarg+`
 | 
			
		||||
						`+uriqry+`
 | 
			
		||||
					) using (feed_id)
 | 
			
		||||
					order by ulid desc
 | 
			
		||||
					limit ?
 | 
			
		||||
@ -181,12 +180,7 @@ func httpServer(c *console, app *appState) error {
 | 
			
		||||
			twts = append(twts, twt)
 | 
			
		||||
		}
 | 
			
		||||
		var preamble lextwt.Comments
 | 
			
		||||
		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)))
 | 
			
		||||
		}
 | 
			
		||||
		preamble = append(preamble, lextwt.NewComment("# self = /api/plain/twts"))
 | 
			
		||||
 | 
			
		||||
		reg := lextwt.NewTwtRegistry(preamble, twts)
 | 
			
		||||
		reg.WriteTo(w)
 | 
			
		||||
@ -286,28 +280,3 @@ 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