From ebe7b5cbc59448a32932713e8497bac82b407042 Mon Sep 17 00:00:00 2001 From: Fries Date: Wed, 28 Jun 2023 15:08:23 -0700 Subject: [PATCH] add a basic implementation of the webring you put your sites url into the url query and it should redirect you to the next or previous site and it will overflow if you're the last or first site in the array. --- .editorconfig | 4 ++++ rustfmt.toml | 1 + src/main.rs | 32 ++++++++++++++++++++++---------- 3 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 .editorconfig create mode 100644 rustfmt.toml 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]) }