forked from poz/nixwebr.ing
revert cargo fmt
This commit is contained in:
parent
71ccf335d0
commit
afdd8f3d65
1 changed files with 13 additions and 20 deletions
|
@ -1,11 +1,8 @@
|
|||
use std::fs::{self};
|
||||
|
||||
use ::rand::{thread_rng, Rng};
|
||||
use ntex::{
|
||||
http::{header, Response},
|
||||
web::{self, middleware},
|
||||
};
|
||||
use ntex::{http::{header, Response}, web::{self, middleware}};
|
||||
use ntex_files as nfs;
|
||||
use ::rand::{thread_rng, Rng};
|
||||
use zasa::{parser::Parser, value::normalize, Normalize};
|
||||
|
||||
#[derive(Clone, Normalize)]
|
||||
|
@ -19,11 +16,7 @@ async fn next(
|
|||
members: web::types::State<Vec<WebringMember>>,
|
||||
name: web::types::Path<String>,
|
||||
) -> impl web::Responder {
|
||||
if let Some((i, _)) = members
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find(|(_, member)| member.name == *name)
|
||||
{
|
||||
if let Some((i, _)) = members.iter().enumerate().find(|(_, member)| member.name == *name) {
|
||||
let next_index = (i + 1) % members.len();
|
||||
let next_site = &members[next_index].site;
|
||||
|
||||
|
@ -44,11 +37,7 @@ async fn prev(
|
|||
members: web::types::State<Vec<WebringMember>>,
|
||||
name: web::types::Path<String>,
|
||||
) -> impl web::Responder {
|
||||
if let Some((i, _)) = members
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find(|(_, member)| member.name == *name)
|
||||
{
|
||||
if let Some((i, _)) = members.iter().enumerate().find(|(_, member)| member.name == *name) {
|
||||
let prev_index = if i == 0 { members.len() - 1 } else { i - 1 };
|
||||
let prev_site = &members[prev_index].site;
|
||||
|
||||
|
@ -65,7 +54,9 @@ async fn prev(
|
|||
}
|
||||
|
||||
#[web::get("/rand")]
|
||||
async fn rand(members: web::types::State<Vec<WebringMember>>) -> impl web::Responder {
|
||||
async fn rand(
|
||||
members: web::types::State<Vec<WebringMember>>,
|
||||
) -> impl web::Responder {
|
||||
let rand_index = thread_rng().gen_range(0..members.len());
|
||||
let rand_site = &members[rand_index].site;
|
||||
|
||||
|
@ -79,7 +70,8 @@ async fn rand(members: web::types::State<Vec<WebringMember>>) -> impl web::Respo
|
|||
async fn main() -> std::io::Result<()> {
|
||||
env_logger::init();
|
||||
|
||||
let nix_webring_dir = std::env::var("NIX_WEBRING_DIR").expect("NIX_WEBRING_DIR not found");
|
||||
let nix_webring_dir = std::env::var("NIX_WEBRING_DIR")
|
||||
.expect("NIX_WEBRING_DIR not found");
|
||||
|
||||
let nix_webring_port = std::env::var("NIX_WEBRING_PORT")
|
||||
.expect("NIX_WEBRING_PORT not found")
|
||||
|
@ -88,7 +80,8 @@ async fn main() -> std::io::Result<()> {
|
|||
|
||||
web::server(move || {
|
||||
let path = format!("{nix_webring_dir}/webring.json");
|
||||
let json = fs::read_to_string(&path).expect(&format!("couldn't open {path}"));
|
||||
let json = fs::read_to_string(&path)
|
||||
.expect(&format!("couldn't open {path}"));
|
||||
|
||||
let members: Vec<WebringMember> = normalize(Parser::new(json.chars()).parse().unwrap())
|
||||
.expect(&format!("failed deserializing webring members: {json}"));
|
||||
|
@ -104,8 +97,8 @@ async fn main() -> std::io::Result<()> {
|
|||
.service(
|
||||
nfs::Files::new("/", nix_webring_dir.clone())
|
||||
.index_file("index.html")
|
||||
.redirect_to_slash_directory(),
|
||||
),
|
||||
.redirect_to_slash_directory()
|
||||
)
|
||||
)
|
||||
})
|
||||
.bind(("127.0.0.1", nix_webring_port))?
|
||||
|
|
Loading…
Reference in a new issue