meowy-webring/src/main.rs

35 lines
951 B
Rust

#[macro_use]
extern crate rocket;
use rocket::response::Redirect;
static NAMES: [&str; 2] = ["mossfet.xyz", "fries.gay"];
#[get("/")]
fn index() -> &'static str {
"Like, this is a webring, meow!"
}
#[get("/next?<source_url>")]
fn next(source_url: &str) -> Redirect {
// this is gay
match NAMES.iter().position(|&r| r == source_url) {
Some(index) if index == NAMES.len() - 1 => Redirect::to(format!("https://{}", NAMES[0])),
Some(index) => Redirect::to(format!("https://{}", NAMES[index + 1])),
None => Redirect::to(uri!("/404.html")),
}
}
#[get("/prev?<source_url>")]
fn prev(source_url: &str) -> Redirect {
match NAMES.iter().position(|&r| r == source_url) {
Some(index) if index == 0 => Redirect::to(format!("https://{}", NAMES[NAMES.len() - 1])),
Some(index) => Redirect::to(format!("https://{}", NAMES[index - 1])),
None => todo!(),
}
}
#[launch]
fn rocket() -> _ {
rocket::build().mount("/", routes![index, next, prev])
}