Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Filter Photos file lists by size in the CLI

laurenspriem1e9bef748535
diff --git a/docs/docs/cli/photos.md b/docs/docs/cli/photos.md
index f074f83a51..57fc86c2f4 100644
--- a/docs/docs/cli/photos.md
+++ b/docs/docs/cli/photos.md
@@ -96,12 +96,14 @@ A file selector is a file ID or an exact name; when several files share a name,
ente photos file list --type video --since 2024-01-01 --before 2025-01-01
ente photos file list --search "beach sunset" --no-location
ente photos file list --sort size --limit 20
+ente photos file list --type video --min-size 500MB
```
- `--type` takes `image`, `video` or `livephoto`; repeat it to include several types.
- `--since` and `--before` compare `createdAt`, which includes dates edited in Ente. `--since` includes the given instant and `--before` excludes it. Both accept `YYYY-MM-DD` (midnight UTC) or RFC 3339 with a timezone, such as `2024-06-01T00:00:00+02:00`.
- `--search` finds files where every word occurs in either the name or the caption, ignoring case.
- `--no-location` keeps files without a location.
+- `--min-size` and `--max-size` keep files whose `sizeBytes` is at least or at most the given size. Both accept MB, GB or TB in powers of 1024, such as `500MB` or `1.5GB`. `sizeBytes` is the size of the stored encrypted file, slightly larger than the original. Files with an unknown size are left out.
A file must match every filter you pass. `--sort created` lists the newest files first and `--sort size` the largest first; add `--reverse` for the opposite order. Files with an unknown size sort as the smallest, and ties keep ID order. Without `--sort`, files are listed by ID.
diff --git a/rust/apps/cli/changes/file-list-filters.md b/rust/apps/cli/changes/file-list-filters.md
index 7ca970586f..441119edeb 100644
--- a/rust/apps/cli/changes/file-list-filters.md
+++ b/rust/apps/cli/changes/file-list-filters.md
@@ -1 +1 @@
-- Filter `photos file list` by type, creation date, name or caption words, and missing location, and sort it by creation time or size. Files now show their size.
+- Filter `photos file list` by type, creation date, name or caption words, size, and missing location, and sort it by creation time or size. Files now show their size.
diff --git a/rust/apps/cli/src/admin.rs b/rust/apps/cli/src/admin.rs
index ad3441bb15..8e0ce24e04 100644
--- a/rust/apps/cli/src/admin.rs
+++ b/rust/apps/cli/src/admin.rs
@@ -273,14 +273,14 @@ pub fn parse_size(input: &str) -> Result<i64, String> {
.into_iter()
.find_map(|(unit, multiplier)| input.strip_suffix(unit).map(|number| (number, multiplier)))
.ok_or("use a size such as 500GB or 1.5TB (MB/GB/TB use powers of 1024)")?;
- let value = number.parse::<f64>().map_err(|_| "invalid storage size")?;
+ let value = number.parse::<f64>().map_err(|_| "invalid size")?;
let bytes = value * multiplier as f64;
if !number.chars().all(|c| c.is_ascii_digit() || c == '.')
|| !bytes.is_finite()
|| bytes < 1.0
|| bytes >= i64::MAX as f64
{
- return Err("storage must be positive and fit in a signed 64-bit byte count".into());
+ return Err("size must be positive and fit in a signed 64-bit byte count".into());
}
Ok(bytes as i64)
}
diff --git a/rust/apps/cli/src/args.rs b/rust/apps/cli/src/args.rs
index 80664d71d4..8e775d7653 100644
--- a/rust/apps/cli/src/args.rs
+++ b/rust/apps/cli/src/args.rs
@@ -616,6 +616,22 @@ pub struct FileQuery {
pub search: Option<String>,
#[arg(long, help = "Include only files without a location")]
pub no_location: bool,
+ #[arg(
+ long,
+ value_name = "SIZE",
+ value_parser = file_size,
+ help = "Include files of at least this size, e.g. 100MB",
+ long_help = "Include files whose sizeBytes is at least SIZE. Accepts MB, GB and TB, case-insensitive, using powers of 1024; fractions are allowed, such as 0.5MB. Files with an unknown size are left out."
+ )]
+ pub min_size: Option<u64>,
+ #[arg(
+ long,
+ value_name = "SIZE",
+ value_parser = file_size,
+ help = "Include files of at most this size, e.g. 1.5GB",
+ long_help = "Include files whose sizeBytes is at most SIZE. Accepts MB, GB and TB, case-insensitive, using powers of 1024; fractions are allowed, such as 0.5MB. Files with an unknown size are left out."
+ )]
+ pub max_size: Option<u64>,
#[arg(
long,
value_enum,
@@ -650,6 +666,11 @@ fn nonempty_search(text: &str) -> Result<String, String> {
}
}
+fn file_size(input: &str) -> Result<u64, String> {
+ let bytes = crate::admin::parse_size(input)?;
+ u64::try_from(bytes).map_err(|error| error.to_string())
+}
+
const ACCOUNT_HELP: &str = "Reads accounts stored on this device without network access.
With --json, list returns an array and view returns one object.
Fields: id, name, email, host (strings); apps (string array); selected (boolean).";
diff --git a/rust/apps/cli/src/photos/mod.rs b/rust/apps/cli/src/photos/mod.rs
index 733487a49d..9903d42b19 100644
--- a/rust/apps/cli/src/photos/mod.rs
+++ b/rust/apps/cli/src/photos/mod.rs
@@ -269,6 +269,12 @@ fn matches(query: &FileQuery, file: &File) -> bool {
.before
.is_none_or(|before| file.created_at_micros < before)
&& (!query.no_location || file.location.is_none())
+ && query
+ .min_size
+ .is_none_or(|min| file.size.is_some_and(|size| size >= min))
+ && query
+ .max_size
+ .is_none_or(|max| file.size.is_some_and(|size| size <= max))
&& query
.search
.as_deref()
diff --git a/rust/apps/cli/tests/cli/files.rs b/rust/apps/cli/tests/cli/files.rs
index efbc7bbf59..dc012c6f8b 100644
--- a/rust/apps/cli/tests/cli/files.rs
+++ b/rust/apps/cli/tests/cli/files.rs
@@ -633,7 +633,7 @@ fn file_lists_filter_and_sort_synced_metadata() {
2,
json!({"title": "Clip.mp4", "fileType": 1, "creationTime": 1_717_200_000_000_000i64}),
json!({}),
- Some(5000),
+ Some(5_242_880),
),
file(
3,
@@ -689,6 +689,12 @@ fn file_lists_filter_and_sort_synced_metadata() {
(vec!["--search", "jpg sunset"], vec![1]),
(vec!["--no-location"], vec![2, 4]),
(vec!["--type", "image", "--no-location"], vec![4]),
+ (vec!["--min-size", "5MB"], vec![2]),
+ (vec!["--min-size", "0.5mb"], vec![2]),
+ (vec!["--max-size", "5MB"], vec![1, 2, 4]),
+ (vec!["--max-size", "1MB"], vec![1, 4]),
+ (vec!["--min-size", "1MB", "--max-size", "4MB"], vec![]),
+ (vec!["--max-size", "1MB", "--sort", "created"], vec![4, 1]),
(vec!["--sort", "created"], vec![3, 2, 4, 1]),
(vec!["--sort", "created", "--reverse"], vec![1, 4, 2, 3]),
(vec!["--sort", "size"], vec![2, 1, 4, 3]),
@@ -730,6 +736,8 @@ fn file_lists_filter_and_sort_synced_metadata() {
vec!["--type", "gif"],
vec!["--sort", "name"],
vec!["--reverse"],
+ vec!["--min-size", "100KB"],
+ vec!["--max-size", "0MB"],
] {
let mut command = vec!["--offline", "photos", "file", "list"];
command.extend(&args);
diff --git a/rust/apps/cli/tests/cli/museum.rs b/rust/apps/cli/tests/cli/museum.rs
index 67dff351c1..559425c519 100644
--- a/rust/apps/cli/tests/cli/museum.rs
+++ b/rust/apps/cli/tests/cli/museum.rs
@@ -362,6 +362,19 @@ fn file_lists_filter_and_sort_server_metadata() -> TestResult {
(vec!["--search", "family dinner"], vec![live]),
(vec!["--no-location"], by_id(vec![clip, holiday])),
(vec!["--album", "Family", "--no-location"], vec![holiday]),
+ (vec!["--min-size", "0.0015MB"], by_id(vec![clip, holiday])),
+ (vec!["--max-size", "0.0015MB"], by_id(vec![beach, live])),
+ (
+ vec![
+ "--album",
+ "Trips",
+ "--min-size",
+ "0.0015MB",
+ "--sort",
+ "size",
+ ],
+ vec![clip, holiday],
+ ),
(vec!["--sort", "size"], vec![clip, holiday, live, beach]),
(vec!["--sort", "created"], vec![live, clip, holiday, beach]),
(