Some minor cleanups.

This commit is contained in:
Rasmus Kaj 2017-11-09 00:06:12 +01:00
parent ad2703a1d5
commit 328074c0b6
8 changed files with 27 additions and 34 deletions

View File

@ -13,14 +13,13 @@ pub fn crawl(
photos: &PhotosDir,
only_in: &Path,
) -> Result<(), Error> {
photos.find_files(
Ok(photos.find_files(
only_in,
&|path, exif| match save_photo(db, path, exif) {
Ok(()) => debug!("Saved photo {}", path),
Err(e) => warn!("Failed to save photo {}: {:?}", path, e),
},
)?;
Ok(())
)?)
}
fn save_photo(
@ -63,7 +62,7 @@ fn save_photo(
clat,
clong,
lat,
long
long,
)
}
} else {
@ -132,7 +131,7 @@ fn find_date(exif: &ExifData) -> Result<NaiveDateTime, Error> {
debug!(
"Try to parse {:?} (from {:?}) as datetime",
str,
value.tag
value.tag,
);
Ok(NaiveDateTime::parse_from_str(str, "%Y:%m:%d %T")?)
} else {

View File

@ -35,7 +35,7 @@ pub fn precache(db: &PgConnection, pd: &PhotosDir) -> Result<(), Error> {
"Failed to scale #{} ({}): {}",
photo.id,
photo.path,
e
e,
))
})?;
cache.set(key.as_bytes(), &data, 0, no_expire)?;

View File

@ -16,14 +16,14 @@ sql_function!(date_part,
pub fn show_stats(db: &PgConnection) -> Result<(), Error> {
println!(
"There are {} photos in total.",
photos.select(count_star()).first::<i64>(db)?
photos.select(count_star()).first::<i64>(db)?,
);
println!(
"There are {} persons, {} places, and {} tags mentioned.",
people.select(count_star()).first::<i64>(db)?,
places.select(count_star()).first::<i64>(db)?,
tags.select(count_star()).first::<i64>(db)?
tags.select(count_star()).first::<i64>(db)?,
);
// Something like this should be possible, I guess?
@ -47,7 +47,7 @@ pub fn show_stats(db: &PgConnection) -> Result<(), Error> {
.load::<(Option<f64>, i64)>(db)?
.iter()
.map(|&(y, n)| format!("{}: {}", y.unwrap_or(0.0), n))
.collect::<Vec<_>>()
.collect::<Vec<_>>(),
);
Ok(())

View File

@ -12,7 +12,7 @@ pub fn list(db: &PgConnection) -> Result<(), Error> {
use schema::users::dsl::*;
println!(
"Existing users: {:?}.",
users.select(username).load::<String>(db)?
users.select(username).load::<String>(db)?,
);
Ok(())
}
@ -40,7 +40,7 @@ pub fn passwd(db: &PgConnection, uname: &str) -> Result<(), Error> {
"Strange, updated {} passwords for {:?} to {:?}",
n,
uname,
pword
pword,
);
}
};

View File

@ -59,7 +59,7 @@ use std::process::exit;
fn main() {
dotenv().ok();
env_logger::init().unwrap();
let args = App::new("rphotosadm")
let args = App::new("rphotos")
.version(env!("CARGO_PKG_VERSION"))
.about("Command line interface for rphotos")
.subcommand(
@ -102,8 +102,7 @@ fn main() {
.help("Image path to make public"),
)
.after_help(
"The image path(s) are relative to the \
image root.",
"The image path(s) are relative to the image root.",
),
)
.subcommand(
@ -121,20 +120,17 @@ fn main() {
)
.subcommand(
SubCommand::with_name("runserver")
.about("RPhotos web server")
.version(env!("CARGO_PKG_VERSION"))
.arg(
Arg::with_name("PIDFILE")
.long("pidfile")
.takes_value(true)
.help(
"Write (and read, if --replace) a pid file \
with the name given as <PIDFILE>.",
"Write (and read, if --replace) a pid file with \
the name given as <PIDFILE>.",
),
)
.arg(Arg::with_name("REPLACE").long("replace").help(
"Kill old server (identified by pid file) \
before running",
"Kill old server (identified by pid file) before running",
)),
)
.get_matches();

View File

@ -32,7 +32,7 @@ where
.error_handler(error_handler)
.build();
let pool = try!(Pool::new(config, manager));
let pool = Pool::new(config, manager)?;
Ok(DieselMiddleware { pool: Arc::new(pool) })
}

View File

@ -41,13 +41,13 @@ pub fn rotate<'mw>(
res.not_found("")
}
pub fn rotate_params(
req: &mut Request,
) -> Result<(Option<i32>, Option<i16>), (StatusCode, BodyError)> {
let form_data = req.form_body()?;
type QResult<T> = Result<T, (StatusCode, BodyError)>;
fn rotate_params(req: &mut Request) -> QResult<(Option<i32>, Option<i16>)> {
let data = req.form_body()?;
Ok((
form_data.get("image").and_then(|s| s.parse().ok()),
form_data.get("angle").and_then(|s| s.parse().ok()),
data.get("image").and_then(|s| s.parse().ok()),
data.get("angle").and_then(|s| s.parse().ok()),
))
}
@ -93,13 +93,11 @@ pub fn tag<'mw>(
res.not_found("")
}
pub fn tag_params(
req: &mut Request,
) -> Result<(Option<i32>, Option<String>), (StatusCode, BodyError)> {
let form_data = req.form_body()?;
fn tag_params(req: &mut Request) -> QResult<(Option<i32>, Option<String>)> {
let data = req.form_body()?;
Ok((
form_data.get("image").and_then(|s| s.parse().ok()),
form_data.get("tag").map(String::from),
data.get("image").and_then(|s| s.parse().ok()),
data.get("tag").map(String::from),
))
}

View File

@ -151,7 +151,7 @@ fn do_login<'mw>(
}
info!(
"Login failed: Password verification failed for {:?}",
user
user,
);
} else {
info!("Login failed: No hash found for {:?}", user);