Release v0.2.3
This commit is contained in:
parent
b31acd3f58
commit
86f3185c59
13 changed files with 1255 additions and 68 deletions
|
|
@ -21,6 +21,7 @@ impl EntryKind {
|
|||
pub struct BrowserEntry {
|
||||
pub uri: String,
|
||||
pub name: String,
|
||||
pub list_name: Option<String>,
|
||||
pub kind: EntryKind,
|
||||
pub size: Option<u64>,
|
||||
pub modified: Option<SystemTime>,
|
||||
|
|
@ -28,6 +29,12 @@ pub struct BrowserEntry {
|
|||
pub etag: Option<String>,
|
||||
}
|
||||
|
||||
impl BrowserEntry {
|
||||
pub fn display_name(&self) -> &str {
|
||||
self.list_name.as_deref().unwrap_or(&self.name)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum SortField {
|
||||
Name,
|
||||
|
|
@ -62,20 +69,28 @@ pub fn sort_entries(
|
|||
|
||||
match field {
|
||||
SortField::Name => apply_direction(
|
||||
natural_cmp_with_case(&left.name, &right.name, case_insensitive),
|
||||
natural_cmp_with_case(left.display_name(), right.display_name(), case_insensitive),
|
||||
direction,
|
||||
),
|
||||
SortField::Modified => compare_optional_time(left.modified, right.modified, direction)
|
||||
.then_with(|| {
|
||||
apply_direction(
|
||||
natural_cmp_with_case(&left.name, &right.name, case_insensitive),
|
||||
natural_cmp_with_case(
|
||||
left.display_name(),
|
||||
right.display_name(),
|
||||
case_insensitive,
|
||||
),
|
||||
direction,
|
||||
)
|
||||
}),
|
||||
SortField::Created => compare_optional_time(left.created, right.created, direction)
|
||||
.then_with(|| {
|
||||
apply_direction(
|
||||
natural_cmp_with_case(&left.name, &right.name, case_insensitive),
|
||||
natural_cmp_with_case(
|
||||
left.display_name(),
|
||||
right.display_name(),
|
||||
case_insensitive,
|
||||
),
|
||||
direction,
|
||||
)
|
||||
}),
|
||||
|
|
@ -212,6 +227,30 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recursive_entries_sort_by_relative_display_path() {
|
||||
let mut entries = ["10권/page.jpg", "2권/page.jpg"].map(|list_name| BrowserEntry {
|
||||
uri: format!("file:///{list_name}"),
|
||||
name: "page.jpg".into(),
|
||||
list_name: Some(list_name.into()),
|
||||
kind: EntryKind::Image,
|
||||
size: None,
|
||||
modified: None,
|
||||
created: None,
|
||||
etag: None,
|
||||
});
|
||||
|
||||
sort_entries(
|
||||
&mut entries,
|
||||
SortField::Name,
|
||||
SortDirection::Ascending,
|
||||
true,
|
||||
);
|
||||
|
||||
assert_eq!(entries[0].display_name(), "2권/page.jpg");
|
||||
assert_eq!(entries[1].display_name(), "10권/page.jpg");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zip_extension_is_case_insensitive() {
|
||||
assert_eq!(classify_file(Path::new("comic.ZIP")), EntryKind::ZipArchive);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue