Some minor cleanups.
This commit is contained in:
parent
ad2703a1d5
commit
328074c0b6
@ -13,14 +13,13 @@ pub fn crawl(
|
|||||||
photos: &PhotosDir,
|
photos: &PhotosDir,
|
||||||
only_in: &Path,
|
only_in: &Path,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
photos.find_files(
|
Ok(photos.find_files(
|
||||||
only_in,
|
only_in,
|
||||||
&|path, exif| match save_photo(db, path, exif) {
|
&|path, exif| match save_photo(db, path, exif) {
|
||||||
Ok(()) => debug!("Saved photo {}", path),
|
Ok(()) => debug!("Saved photo {}", path),
|
||||||
Err(e) => warn!("Failed to save photo {}: {:?}", path, e),
|
Err(e) => warn!("Failed to save photo {}: {:?}", path, e),
|
||||||
},
|
},
|
||||||
)?;
|
)?)
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save_photo(
|
fn save_photo(
|
||||||
@ -63,7 +62,7 @@ fn save_photo(
|
|||||||
clat,
|
clat,
|
||||||
clong,
|
clong,
|
||||||
lat,
|
lat,
|
||||||
long
|
long,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -132,7 +131,7 @@ fn find_date(exif: &ExifData) -> Result<NaiveDateTime, Error> {
|
|||||||
debug!(
|
debug!(
|
||||||
"Try to parse {:?} (from {:?}) as datetime",
|
"Try to parse {:?} (from {:?}) as datetime",
|
||||||
str,
|
str,
|
||||||
value.tag
|
value.tag,
|
||||||
);
|
);
|
||||||
Ok(NaiveDateTime::parse_from_str(str, "%Y:%m:%d %T")?)
|
Ok(NaiveDateTime::parse_from_str(str, "%Y:%m:%d %T")?)
|
||||||
} else {
|
} else {
|
||||||
|
@ -35,7 +35,7 @@ pub fn precache(db: &PgConnection, pd: &PhotosDir) -> Result<(), Error> {
|
|||||||
"Failed to scale #{} ({}): {}",
|
"Failed to scale #{} ({}): {}",
|
||||||
photo.id,
|
photo.id,
|
||||||
photo.path,
|
photo.path,
|
||||||
e
|
e,
|
||||||
))
|
))
|
||||||
})?;
|
})?;
|
||||||
cache.set(key.as_bytes(), &data, 0, no_expire)?;
|
cache.set(key.as_bytes(), &data, 0, no_expire)?;
|
||||||
|
@ -16,14 +16,14 @@ sql_function!(date_part,
|
|||||||
pub fn show_stats(db: &PgConnection) -> Result<(), Error> {
|
pub fn show_stats(db: &PgConnection) -> Result<(), Error> {
|
||||||
println!(
|
println!(
|
||||||
"There are {} photos in total.",
|
"There are {} photos in total.",
|
||||||
photos.select(count_star()).first::<i64>(db)?
|
photos.select(count_star()).first::<i64>(db)?,
|
||||||
);
|
);
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"There are {} persons, {} places, and {} tags mentioned.",
|
"There are {} persons, {} places, and {} tags mentioned.",
|
||||||
people.select(count_star()).first::<i64>(db)?,
|
people.select(count_star()).first::<i64>(db)?,
|
||||||
places.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?
|
// 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)?
|
.load::<(Option<f64>, i64)>(db)?
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&(y, n)| format!("{}: {}", y.unwrap_or(0.0), n))
|
.map(|&(y, n)| format!("{}: {}", y.unwrap_or(0.0), n))
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>(),
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -12,7 +12,7 @@ pub fn list(db: &PgConnection) -> Result<(), Error> {
|
|||||||
use schema::users::dsl::*;
|
use schema::users::dsl::*;
|
||||||
println!(
|
println!(
|
||||||
"Existing users: {:?}.",
|
"Existing users: {:?}.",
|
||||||
users.select(username).load::<String>(db)?
|
users.select(username).load::<String>(db)?,
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -40,7 +40,7 @@ pub fn passwd(db: &PgConnection, uname: &str) -> Result<(), Error> {
|
|||||||
"Strange, updated {} passwords for {:?} to {:?}",
|
"Strange, updated {} passwords for {:?} to {:?}",
|
||||||
n,
|
n,
|
||||||
uname,
|
uname,
|
||||||
pword
|
pword,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
14
src/main.rs
14
src/main.rs
@ -59,7 +59,7 @@ use std::process::exit;
|
|||||||
fn main() {
|
fn main() {
|
||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
env_logger::init().unwrap();
|
env_logger::init().unwrap();
|
||||||
let args = App::new("rphotosadm")
|
let args = App::new("rphotos")
|
||||||
.version(env!("CARGO_PKG_VERSION"))
|
.version(env!("CARGO_PKG_VERSION"))
|
||||||
.about("Command line interface for rphotos")
|
.about("Command line interface for rphotos")
|
||||||
.subcommand(
|
.subcommand(
|
||||||
@ -102,8 +102,7 @@ fn main() {
|
|||||||
.help("Image path to make public"),
|
.help("Image path to make public"),
|
||||||
)
|
)
|
||||||
.after_help(
|
.after_help(
|
||||||
"The image path(s) are relative to the \
|
"The image path(s) are relative to the image root.",
|
||||||
image root.",
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
@ -121,20 +120,17 @@ fn main() {
|
|||||||
)
|
)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
SubCommand::with_name("runserver")
|
SubCommand::with_name("runserver")
|
||||||
.about("RPhotos web server")
|
|
||||||
.version(env!("CARGO_PKG_VERSION"))
|
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("PIDFILE")
|
Arg::with_name("PIDFILE")
|
||||||
.long("pidfile")
|
.long("pidfile")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.help(
|
.help(
|
||||||
"Write (and read, if --replace) a pid file \
|
"Write (and read, if --replace) a pid file with \
|
||||||
with the name given as <PIDFILE>.",
|
the name given as <PIDFILE>.",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.arg(Arg::with_name("REPLACE").long("replace").help(
|
.arg(Arg::with_name("REPLACE").long("replace").help(
|
||||||
"Kill old server (identified by pid file) \
|
"Kill old server (identified by pid file) before running",
|
||||||
before running",
|
|
||||||
)),
|
)),
|
||||||
)
|
)
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
@ -32,7 +32,7 @@ where
|
|||||||
.error_handler(error_handler)
|
.error_handler(error_handler)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let pool = try!(Pool::new(config, manager));
|
let pool = Pool::new(config, manager)?;
|
||||||
|
|
||||||
Ok(DieselMiddleware { pool: Arc::new(pool) })
|
Ok(DieselMiddleware { pool: Arc::new(pool) })
|
||||||
}
|
}
|
||||||
|
@ -41,13 +41,13 @@ pub fn rotate<'mw>(
|
|||||||
res.not_found("")
|
res.not_found("")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rotate_params(
|
type QResult<T> = Result<T, (StatusCode, BodyError)>;
|
||||||
req: &mut Request,
|
|
||||||
) -> Result<(Option<i32>, Option<i16>), (StatusCode, BodyError)> {
|
fn rotate_params(req: &mut Request) -> QResult<(Option<i32>, Option<i16>)> {
|
||||||
let form_data = req.form_body()?;
|
let data = req.form_body()?;
|
||||||
Ok((
|
Ok((
|
||||||
form_data.get("image").and_then(|s| s.parse().ok()),
|
data.get("image").and_then(|s| s.parse().ok()),
|
||||||
form_data.get("angle").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("")
|
res.not_found("")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn tag_params(
|
fn tag_params(req: &mut Request) -> QResult<(Option<i32>, Option<String>)> {
|
||||||
req: &mut Request,
|
let data = req.form_body()?;
|
||||||
) -> Result<(Option<i32>, Option<String>), (StatusCode, BodyError)> {
|
|
||||||
let form_data = req.form_body()?;
|
|
||||||
Ok((
|
Ok((
|
||||||
form_data.get("image").and_then(|s| s.parse().ok()),
|
data.get("image").and_then(|s| s.parse().ok()),
|
||||||
form_data.get("tag").map(String::from),
|
data.get("tag").map(String::from),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ fn do_login<'mw>(
|
|||||||
}
|
}
|
||||||
info!(
|
info!(
|
||||||
"Login failed: Password verification failed for {:?}",
|
"Login failed: Password verification failed for {:?}",
|
||||||
user
|
user,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
info!("Login failed: No hash found for {:?}", user);
|
info!("Login failed: No hash found for {:?}", user);
|
||||||
|
Loading…
Reference in New Issue
Block a user