add "random" endpoint that just redirects you to a random node. #1
1 changed files with 17 additions and 0 deletions
|
@ -12,6 +12,8 @@ pub fn handle_request(req: Request) -> Response {
|
||||||
case wisp.path_segments(req) {
|
case wisp.path_segments(req) {
|
||||||
[] -> home_page(req)
|
[] -> home_page(req)
|
||||||
|
|
||||||
|
["random"] -> handle_random()
|
||||||
|
|
||||||
[hash, "previous"] -> handle_previous(hash)
|
[hash, "previous"] -> handle_previous(hash)
|
||||||
[hash, "next"] -> handle_next(hash)
|
[hash, "next"] -> handle_next(hash)
|
||||||
|
|
||||||
|
@ -55,6 +57,21 @@ fn handle_next(hash) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn handle_random() {
|
||||||
|
let db_path = "members.db"
|
||||||
|
use conn <- sqlight.with_connection(db_path)
|
||||||
|
let next =
|
||||||
nebkor marked this conversation as resolved
Outdated
|
|||||||
|
sqlight.query(
|
||||||
|
"select next from ring order by random() limit 1",
|
||||||
|
on: conn,
|
||||||
|
expecting: dynamic.decode1(Row, dynamic.element(0, dynamic.string)),
|
||||||
|
)
|
||||||
|
case next {
|
||||||
nebkor marked this conversation as resolved
Outdated
erika
commented
And here And here
|
|||||||
|
Ok([Row(next_link)]) -> wisp.redirect(next_link)
|
||||||
nebkor marked this conversation as resolved
Outdated
erika
commented
and here and here
|
|||||||
|
_ -> wisp.not_found()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn home_page(req: Request) -> Response {
|
fn home_page(req: Request) -> Response {
|
||||||
// The home page can only be accessed via GET requests, so this middleware is
|
// The home page can only be accessed via GET requests, so this middleware is
|
||||||
// used to return a 405: Method Not Allowed response for all other methods.
|
// used to return a 405: Method Not Allowed response for all other methods.
|
||||||
|
|
Loading…
Reference in a new issue
can we rename
next
torandom
?