diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..c2e08b7 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,4 @@ +[*] +indent_style = tab +end_of_line = lf +insert_final_newline = true diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..218e203 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1 @@ +hard_tabs = true diff --git a/src/main.rs b/src/main.rs index 321c6c6..da72255 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,22 +1,34 @@ -#[macro_use] extern crate rocket; -use rocket::response::Redirict; +#[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!" + "Like, this is a webring, meow!" } -#[get("/next")] -fn next() -> Redirect { - Redirect::to(uri!("https://mossfet.xyz")) +#[get("/next?")] +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")] -fn prev -> Redirect { - Redirect::to(uri!("https://fries.gay")) +#[get("/prev?")] +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]) + rocket::build().mount("/", routes![index, next, prev]) }