Added ability to pick albums for motivation
+ clippy + fmt
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use crate::album_manager::Album;
|
||||
use crate::error::Error;
|
||||
use j_db::database::Database;
|
||||
use j_db::error::JDbError;
|
||||
use j_db::model::JdbModel;
|
||||
use rand::prelude::{IteratorRandom, SliceRandom};
|
||||
use rand::thread_rng;
|
||||
@@ -80,17 +81,28 @@ impl MotivationConfig {
|
||||
db: &Database,
|
||||
base_path: &Path,
|
||||
border_color: &str,
|
||||
album_name: Option<String>,
|
||||
) -> Result<Motivation, Error> {
|
||||
let motivation = Self::get_motivation_config(db)?;
|
||||
|
||||
let mut images = Vec::new();
|
||||
|
||||
for album in motivation.album {
|
||||
let album = db.get::<Album>(album);
|
||||
if let Some(album_name) = album_name {
|
||||
let album = Album::find_album_by_name_or_alias(db, &album_name)?;
|
||||
|
||||
if let Ok(album) = album {
|
||||
let mut album_images = album.images.clone();
|
||||
images.append(&mut album_images);
|
||||
if let Some(mut album) = album {
|
||||
images.append(&mut album.images)
|
||||
} else {
|
||||
return Err(Error::from(JDbError::NotFound));
|
||||
}
|
||||
} else {
|
||||
for album in motivation.album {
|
||||
let album = db.get::<Album>(album);
|
||||
|
||||
if let Ok(album) = album {
|
||||
let mut album_images = album.images.clone();
|
||||
images.append(&mut album_images);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user