Compare commits
	
		
			3 Commits
		
	
	
		
			4efdc915e6
			...
			a0614435ff
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| a0614435ff | |||
| fe28b7c2ad | |||
| 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(), " ")
 | 
							_, part, ok := strings.Cut(prev.Value(), " ")
 | 
				
			||||||
		if ok {
 | 
							if ok {
 | 
				
			||||||
			uri := f.Twter().URI
 | 
								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
 | 
								part = uri[:strings.LastIndex(uri, "/")+1] + part
 | 
				
			||||||
			childID := urlNS.UUID5(part)
 | 
								childID := urlNS.UUID5(part)
 | 
				
			||||||
 | 
								fmt.Println("found prev", uri, part)
 | 
				
			||||||
			args = append(args,
 | 
								args = append(args,
 | 
				
			||||||
				childID,                // feed_id
 | 
									childID,                // feed_id
 | 
				
			||||||
				feedID,                 // parent_id
 | 
									feedID,                 // parent_id
 | 
				
			||||||
@ -332,7 +339,7 @@ func storeFeed(ctx context.Context, db db, f types.TwtFile) error {
 | 
				
			|||||||
				part,                   // uri
 | 
									part,                   // uri
 | 
				
			||||||
				"once",                 // state
 | 
									"once",                 // state
 | 
				
			||||||
				nil,                    // last_scan_on
 | 
									nil,                    // last_scan_on
 | 
				
			||||||
				refreshRate,            // refresh_rate
 | 
									0,                      // refresh_rate
 | 
				
			||||||
			)
 | 
								)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										53
									
								
								http.go
									
									
									
									
									
								
							
							
						
						
									
										53
									
								
								http.go
									
									
									
									
									
								
							@ -109,24 +109,25 @@ func httpServer(c *console, app *appState) error {
 | 
				
			|||||||
		ctx, span := otel.Span(r.Context())
 | 
							ctx, span := otel.Span(r.Context())
 | 
				
			||||||
		defer span.End()
 | 
							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
 | 
							limit := 100
 | 
				
			||||||
		if v, ok := strconv.Atoi(r.URL.Query().Get("limit")); ok == nil {
 | 
							if v, ok := strconv.Atoi(r.URL.Query().Get("limit")); ok == nil {
 | 
				
			||||||
			limit = v
 | 
								limit = v
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		offset := 0
 | 
							offset := 0
 | 
				
			||||||
		if v, ok := strconv.Atoi(r.URL.Query().Get("offset")); ok == nil {
 | 
							if v, ok := strconv.Atoi(r.URL.Query().Get("offset")); ok == nil {
 | 
				
			||||||
			offset = v
 | 
								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")
 | 
							w.Header().Set("Content-Type", "text/plain; charset=utf-8")
 | 
				
			||||||
		rows, err := db.QueryContext(
 | 
							rows, err := db.QueryContext(
 | 
				
			||||||
			ctx,
 | 
								ctx,
 | 
				
			||||||
@ -145,7 +146,7 @@ func httpServer(c *console, app *appState) error {
 | 
				
			|||||||
							uri
 | 
												uri
 | 
				
			||||||
						FROM feeds
 | 
											FROM feeds
 | 
				
			||||||
						where state not in ('frozen', 'permanantly-dead')
 | 
											where state not in ('frozen', 'permanantly-dead')
 | 
				
			||||||
						`+uriqry+`
 | 
											`+uriarg+`
 | 
				
			||||||
					) using (feed_id)
 | 
										) using (feed_id)
 | 
				
			||||||
					order by ulid desc
 | 
										order by ulid desc
 | 
				
			||||||
					limit ?
 | 
										limit ?
 | 
				
			||||||
@ -180,7 +181,12 @@ func httpServer(c *console, app *appState) error {
 | 
				
			|||||||
			twts = append(twts, twt)
 | 
								twts = append(twts, twt)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		var preamble lextwt.Comments
 | 
							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 := lextwt.NewTwtRegistry(preamble, twts)
 | 
				
			||||||
		reg.WriteTo(w)
 | 
							reg.WriteTo(w)
 | 
				
			||||||
@ -280,3 +286,28 @@ func notAny(s string, chars string) bool {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	return true
 | 
						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