mirror of https://github.com/raftario/filite.git
Fix clippy warnings
This commit is contained in:
parent
8b32ffa032
commit
08c86c892e
|
@ -47,10 +47,11 @@ macro_rules! common_select {
|
|||
$q = $q.limit(limit);
|
||||
}
|
||||
|
||||
match $f.asc {
|
||||
false => $q = $q.order(created.desc()),
|
||||
true => $q = $q.order(created.asc()),
|
||||
}
|
||||
$q = if $f.asc {
|
||||
$q.order(created.asc())
|
||||
} else {
|
||||
$q.order(created.desc())
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -55,17 +55,18 @@ fn auth(
|
|||
Err(_) => return Err(HttpResponse::BadRequest().body("Invalid Authorization header")),
|
||||
};
|
||||
|
||||
match setup::hash(password).as_slice() == password_hash {
|
||||
true => match String::from_utf8(user.to_vec()) {
|
||||
if setup::hash(password).as_slice() == password_hash {
|
||||
match String::from_utf8(user.to_vec()) {
|
||||
Ok(u) => {
|
||||
identity.remember(u);
|
||||
Ok(())
|
||||
}
|
||||
Err(_) => Err(HttpResponse::BadRequest().body("Invalid Authorization header")),
|
||||
},
|
||||
false => Err(HttpResponse::Unauthorized()
|
||||
}
|
||||
} else {
|
||||
Err(HttpResponse::Unauthorized()
|
||||
.header("WWW-Authenticate", "Basic realm=\"filite\"")
|
||||
.body("Unauthorized")),
|
||||
.body("Unauthorized"))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -97,7 +98,7 @@ fn match_find_error<T>(error: BlockingError<diesel::result::Error>) -> Result<T,
|
|||
/// Formats a timestamp to the "Last-Modified" header format
|
||||
fn timestamp_to_last_modified(timestamp: i32) -> String {
|
||||
let datetime =
|
||||
DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(timestamp as i64, 0), Utc);
|
||||
DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(i64::from(timestamp), 0), Utc);
|
||||
datetime.format("%a, %d %b %Y %H:%M:%S GMT").to_string()
|
||||
}
|
||||
|
||||
|
@ -233,14 +234,13 @@ pub fn get_config(
|
|||
|
||||
/// Logout route
|
||||
pub fn logout(identity: Identity) -> impl Responder {
|
||||
match identity.identity().is_some() {
|
||||
true => {
|
||||
identity.forget();
|
||||
HttpResponse::Ok().body("Logged out")
|
||||
}
|
||||
false => HttpResponse::Unauthorized()
|
||||
if identity.identity().is_some() {
|
||||
identity.forget();
|
||||
HttpResponse::Ok().body("Logged out")
|
||||
} else {
|
||||
HttpResponse::Unauthorized()
|
||||
.header("WWW-Authenticate", "Basic realm=\"filite\"")
|
||||
.body("Unauthorized"),
|
||||
.body("Unauthorized")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -402,7 +402,7 @@ pub mod links {
|
|||
.and_then(move |_| future::result(parse_id(&path)))
|
||||
.and_then(move |id| {
|
||||
web::block(move || queries::links::replace(id, &body.forward, pool))
|
||||
.then(|result| match_replace_result(result))
|
||||
.then(match_replace_result)
|
||||
})
|
||||
.from_err()
|
||||
}
|
||||
|
@ -460,7 +460,7 @@ pub mod texts {
|
|||
.and_then(move |_| future::result(parse_id(&path)))
|
||||
.and_then(move |id| {
|
||||
web::block(move || queries::texts::replace(id, &body.contents, pool))
|
||||
.then(|result| match_replace_result(result))
|
||||
.then(match_replace_result)
|
||||
})
|
||||
.from_err()
|
||||
}
|
||||
|
|
14
src/setup.rs
14
src/setup.rs
|
@ -99,13 +99,7 @@ impl Default for Config {
|
|||
.expect("Can't convert database path to string")
|
||||
.to_owned()
|
||||
};
|
||||
let pool_size = {
|
||||
let n = num_cpus::get() as u32 / 2;
|
||||
match n < 1 {
|
||||
true => 1,
|
||||
false => n,
|
||||
}
|
||||
};
|
||||
let pool_size = std::cmp::max(1, num_cpus::get() as u32 / 2);
|
||||
let files_dir = {
|
||||
let mut path = get_data_dir();
|
||||
path.push("files");
|
||||
|
@ -141,7 +135,7 @@ impl Config {
|
|||
let mut result: Config = result.unwrap();
|
||||
|
||||
if result.files_dir.is_absolute() {
|
||||
if let Err(_) = fs::create_dir_all(&result.files_dir) {
|
||||
if fs::create_dir_all(&result.files_dir).is_err() {
|
||||
return Err("Can't create files_dir.");
|
||||
}
|
||||
|
||||
|
@ -153,7 +147,7 @@ impl Config {
|
|||
let mut data_dir = get_data_dir();
|
||||
data_dir.push(&result.files_dir);
|
||||
|
||||
if let Err(_) = fs::create_dir_all(&data_dir) {
|
||||
if fs::create_dir_all(&data_dir).is_err() {
|
||||
return Err("Can't create files_dir.");
|
||||
}
|
||||
|
||||
|
@ -279,7 +273,7 @@ pub fn init() -> Config {
|
|||
process::exit(1);
|
||||
});
|
||||
|
||||
let mut config_path = data_dir.clone();
|
||||
let mut config_path = data_dir;
|
||||
config_path.push("config.toml");
|
||||
eprintln!(
|
||||
"Almost ready. To get started, edit the config file at {} and restart.",
|
||||
|
|
Loading…
Reference in New Issue