feature/shuffle-sort #30
@@ -41,7 +41,7 @@ pub mod test {
|
||||
.run_pending_migrations(DB_MIGRATIONS)
|
||||
.expect("Failure running DB migrations");
|
||||
|
||||
return connection;
|
||||
connection
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
28
src/files.rs
28
src/files.rs
@@ -19,6 +19,7 @@ use log::{debug, error, info, trace};
|
||||
use crate::data::{Claims, FilesRequest, FilterMode, PhotosResponse, SortType};
|
||||
use crate::{create_thumbnails, AppState};
|
||||
|
||||
use crate::data::SortType::{NameAsc};
|
||||
use crate::error::IntoHttpError;
|
||||
use crate::tags::TagDao;
|
||||
use crate::video::StreamActor;
|
||||
@@ -54,7 +55,7 @@ pub async fn list_photos<TagD: TagDao, FS: FileSystemAccess>(
|
||||
let exclude_tag_ids = req
|
||||
.exclude_tag_ids
|
||||
.clone()
|
||||
.unwrap_or(String::new())
|
||||
.unwrap_or_default()
|
||||
.split(',')
|
||||
.filter_map(|t| t.parse().ok())
|
||||
.collect::<Vec<i32>>();
|
||||
@@ -72,17 +73,18 @@ pub async fn list_photos<TagD: TagDao, FS: FileSystemAccess>(
|
||||
.into_iter()
|
||||
.filter(|f| {
|
||||
// When searching at the root, everything matches recursively
|
||||
if search_path.trim() == "" { return true; }
|
||||
if search_path.trim() == "" {
|
||||
return true;
|
||||
}
|
||||
|
||||
f.starts_with(
|
||||
&format!(
|
||||
f.starts_with(&format!(
|
||||
"{}/",
|
||||
search_path.strip_suffix('/').unwrap_or_else(|| search_path)
|
||||
),
|
||||
)
|
||||
))
|
||||
})
|
||||
.collect::<Vec<String>>()
|
||||
})
|
||||
.map(|files| sort(files, req.sort.unwrap_or(NameAsc)))
|
||||
.inspect(|files| debug!("Found {:?} files", files.len()))
|
||||
.map(|tagged_files: Vec<String>| {
|
||||
trace!(
|
||||
@@ -130,7 +132,7 @@ pub async fn list_photos<TagD: TagDao, FS: FileSystemAccess>(
|
||||
let excluded_tag_ids = &req
|
||||
.exclude_tag_ids
|
||||
.clone()
|
||||
.unwrap_or(String::new())
|
||||
.unwrap_or_default()
|
||||
.split(',')
|
||||
.filter_map(|t| t.parse().ok())
|
||||
.collect::<Vec<i32>>();
|
||||
@@ -178,10 +180,10 @@ fn sort(mut files: Vec<String>, sort_type: SortType) -> Vec<String> {
|
||||
match sort_type {
|
||||
SortType::Shuffle => files.shuffle(&mut thread_rng()),
|
||||
SortType::NameAsc => {
|
||||
files.sort_by(|l, r| l.cmp(&r));
|
||||
files.sort();
|
||||
}
|
||||
SortType::NameDesc => {
|
||||
files.sort_by(|l, r| r.cmp(&l));
|
||||
files.sort_by(|l, r| r.cmp(l));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -393,17 +395,15 @@ mod tests {
|
||||
fn get_files_for_path(&self, path: &str) -> anyhow::Result<Vec<PathBuf>> {
|
||||
if self.err {
|
||||
Err(anyhow!("Error for test"))
|
||||
} else {
|
||||
if let Some(files) = self.files.get(path) {
|
||||
} else if let Some(files) = self.files.get(path) {
|
||||
Ok(files
|
||||
.iter()
|
||||
.map(|p| PathBuf::from(p))
|
||||
.map(PathBuf::from)
|
||||
.collect::<Vec<PathBuf>>())
|
||||
} else {
|
||||
Ok(Vec::new())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn move_file<P: AsRef<Path>>(&self, from: P, destination: P) -> anyhow::Result<()> {
|
||||
todo!()
|
||||
@@ -593,7 +593,7 @@ mod tests {
|
||||
],
|
||||
);
|
||||
|
||||
let request: Query<FilesRequest> = Query::from_query(&*format!(
|
||||
let request: Query<FilesRequest> = Query::from_query(&format!(
|
||||
"path=&tag_ids={},{}&tag_filter_mode=All",
|
||||
tag1.id, tag3.id
|
||||
))
|
||||
|
||||
@@ -449,7 +449,7 @@ mod tests {
|
||||
let tag_id = self.tag_count;
|
||||
|
||||
let tag = Tag {
|
||||
id: tag_id as i32,
|
||||
id: tag_id,
|
||||
name: name.to_string(),
|
||||
created_time: Utc::now().timestamp(),
|
||||
};
|
||||
|
||||
@@ -51,8 +51,7 @@ impl UserDao for TestUserDao {
|
||||
self.user_map
|
||||
.borrow()
|
||||
.iter()
|
||||
.find(|&u| u.username == user)
|
||||
.is_some()
|
||||
.any(|u| u.username == user)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@ impl Handler<ScanDirectoryMessage> for VideoPlaylistManager {
|
||||
.into_iter()
|
||||
.filter_map(|e| e.ok())
|
||||
.filter(|e| e.file_type().is_file())
|
||||
.filter(|e| is_video(e))
|
||||
.filter(is_video)
|
||||
.collect::<Vec<DirEntry>>();
|
||||
|
||||
let scan_dir_name = msg.directory.clone();
|
||||
|
||||
Reference in New Issue
Block a user