add "random" endpoint that just redirects you to a random node. #1

Merged
erika merged 2 commits from :random into main 2024-03-31 18:23:12 +00:00
Showing only changes of commit b2b1a6bab6 - Show all commits

View file

@ -60,14 +60,14 @@ fn handle_next(hash) {
fn handle_random() { fn handle_random() {
let db_path = "members.db" let db_path = "members.db"
use conn <- sqlight.with_connection(db_path) use conn <- sqlight.with_connection(db_path)
let next = let random =
sqlight.query( sqlight.query(
"select next from ring order by random() limit 1", "select next from ring order by random() limit 1",
on: conn, on: conn,
expecting: dynamic.decode1(Row, dynamic.element(0, dynamic.string)), expecting: dynamic.decode1(Row, dynamic.element(0, dynamic.string)),
) )
case next { case random {
Ok([Row(next_link)]) -> wisp.redirect(next_link) Ok([Row(random_link)]) -> wisp.redirect(random_link)
_ -> wisp.not_found() _ -> wisp.not_found()
} }
} }