0.3.4: add dir option to specify dir to lookup files

Signed-off-by: Ivan Bushchik <ivabus@ivabus.dev>
This commit is contained in:
Ivan Bushchik 2023-12-20 18:28:42 +03:00
parent 9122166285
commit 1f3896bb76
No known key found for this signature in database
GPG key ID: 2F16FBF3262E090C
2 changed files with 9 additions and 2 deletions

View file

@ -1,6 +1,6 @@
[package]
name = "urouter"
version = "0.3.3"
version = "0.3.4"
edition = "2021"
license = "MIT"
repository = "https://github.com/ivabus/urouter"

View file

@ -47,6 +47,10 @@ struct Args {
#[arg(long, default_value = "./alias.json")]
alias_file: PathBuf,
/// Dir to lookup file alias
#[arg(long, default_value = ".")]
dir: PathBuf,
#[arg(short, long, default_value = "127.0.0.1")]
address: IpAddr,
@ -87,10 +91,13 @@ impl<'r> FromRequest<'r> for UserAgent {
}
fn get_return(alias: &Alias) -> Response {
let args = Args::parse();
let mut dir = args.dir.clone();
return match alias.is_url {
Some(true) => Response::Redirect(Redirect::to(alias.alias.clone())),
_ => {
Response::Text(RawText(smurf::io::read_file_str(&PathBuf::from(&alias.alias)).unwrap()))
dir.push(&PathBuf::from(&alias.alias));
Response::Text(RawText(smurf::io::read_file_str(&dir).unwrap()))
}
};
}