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