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.
This commit is contained in:
Fries 2023-06-28 15:08:23 -07:00
parent 3e054fc7f0
commit ebe7b5cbc5
3 changed files with 27 additions and 10 deletions

4
.editorconfig Normal file
View file

@ -0,0 +1,4 @@
[*]
indent_style = tab
end_of_line = lf
insert_final_newline = true

1
rustfmt.toml Normal file
View file

@ -0,0 +1 @@
hard_tabs = true

View file

@ -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!"
}
#[get("/next")]
fn next() -> Redirect {
Redirect::to(uri!("https://mossfet.xyz"))
#[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")]
fn prev -> Redirect {
Redirect::to(uri!("https://fries.gay"))
#[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])
rocket::build().mount("/", routes![index, next, prev])
}