From a8796b27281b98deb42ac268a1d7fa1ce3c11e20 Mon Sep 17 00:00:00 2001 From: Marc Plano-Lesay Date: Tue, 5 Nov 2024 09:23:34 +1100 Subject: [PATCH] Add utilities around albums and assets --- src/utils/albums.rs | 21 ++++++++++++++ src/utils/assets.rs | 68 +++++++++++++++++++++++++++++++++++++++++++++ src/utils/mod.rs | 2 ++ 3 files changed, 91 insertions(+) create mode 100644 src/utils/albums.rs create mode 100644 src/utils/assets.rs diff --git a/src/utils/albums.rs b/src/utils/albums.rs new file mode 100644 index 0000000..f892063 --- /dev/null +++ b/src/utils/albums.rs @@ -0,0 +1,21 @@ +use crate::{ + types::{AlbumResponseDto, AssetResponseDto}, + Client, +}; +use color_eyre::eyre::Result; +use uuid::Uuid; + +pub async fn fetch_all_albums(client: &Client) -> Result> { + Ok(client.get_all_albums(None, None).await?.to_vec()) +} + +pub async fn fetch_album_assets( + album_uuid: &Uuid, + client: &Client, +) -> Result> { + Ok(client + .get_album_info(album_uuid, None, Some(false)) + .await? + .assets + .clone()) +} diff --git a/src/utils/assets.rs b/src/utils/assets.rs new file mode 100644 index 0000000..a1b62eb --- /dev/null +++ b/src/utils/assets.rs @@ -0,0 +1,68 @@ +use crate::{ + types::{AssetResponseDto, MetadataSearchDto}, + Client, +}; +use color_eyre::eyre::Result; + +pub async fn fetch_all_assets(client: &Client) -> Result> { + let mut all_assets = Vec::new(); + let mut page_number = None; + let mut has_next_page = true; + + while has_next_page { + let fetched = client + .search_metadata(&MetadataSearchDto { + checksum: None, + city: None, + country: None, + created_after: None, + created_before: None, + device_asset_id: None, + device_id: None, + encoded_video_path: None, + id: None, + is_archived: None, + is_encoded: None, + is_favorite: None, + is_motion: None, + is_not_in_album: None, + is_offline: None, + is_visible: None, + lens_model: None, + library_id: None, + make: None, + model: None, + order: None, + original_file_name: None, + original_path: None, + page: page_number, + person_ids: vec![], + preview_path: None, + size: None, + state: None, + taken_after: None, + taken_before: None, + thumbnail_path: None, + trashed_after: None, + trashed_before: None, + type_: None, + updated_after: None, + updated_before: None, + with_archived: true, + with_deleted: None, + with_exif: None, + with_people: None, + with_stacked: None, + }) + .await?; + all_assets.extend(fetched.assets.items.clone()); + has_next_page = fetched.assets.next_page.is_some(); + page_number = fetched + .assets + .next_page + .clone() + .map(|page| page.parse::().unwrap()); + } + + Ok(all_assets) +} diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 24eb2de..e53cd62 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1 +1,3 @@ +pub mod albums; +pub mod assets; pub mod people;