Skip to content

Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.

Files in an app library can be downloaded

Yashwanth Kamireddi44e846df8884
diff --git a/crates/quince-icloud/src/drive.rs b/crates/quince-icloud/src/drive.rs
index 32d0f85..6692d63 100644
--- a/crates/quince-icloud/src/drive.rs
+++ b/crates/quince-icloud/src/drive.rs
@@ -109,9 +109,14 @@ pub async fn download_url(
params: Vec<(String, String)>,
item: &DriveItem,
) -> Result<String> {
+ // The zone in the path is the file's own. An app library — Keynote's, Shortcuts', a
+ // third party's — is a zone of its own, and asking for one of its files under the
+ // ordinary Drive zone gets "Could not find document" rather than the file. Every file
+ // in every app library was undownloadable while this said com.apple.CloudDocs.
let url = format!(
- "{}/ws/com.apple.CloudDocs/download/by_id",
- docws_root.trim_end_matches('/')
+ "{}/ws/{}/download/by_id",
+ docws_root.trim_end_matches('/'),
+ zone_of(&item.drivewsid).unwrap_or(DOCUMENTS_ZONE)
);
let mut query = params;
query.push((
@@ -1286,3 +1291,61 @@ mod app_library_tests {
std::fs::remove_file(&file).ok();
}
}
+
+#[cfg(test)]
+mod download_zone_tests {
+ use super::*;
+ use wiremock::matchers::{method, path};
+ use wiremock::{Mock, MockServer, ResponseTemplate};
+
+ fn file(drivewsid: &str) -> DriveItem {
+ DriveItem {
+ drivewsid: drivewsid.into(),
+ parent_id: None,
+ name: "Morning".into(),
+ extension: Some("shortcut".into()),
+ kind: "FILE".into(),
+ size: Some(10),
+ child_count: None,
+ created_at: None,
+ modified_at: None,
+ etag: None,
+ }
+ }
+
+ /// A file in an app library is asked for under that library's zone. Under the ordinary
+ /// Drive zone Apple answers "Could not find document" — measured against a Shortcuts file.
+ #[tokio::test]
+ async fn a_download_asks_for_the_file_under_its_own_zone() {
+ let server = MockServer::start().await;
+ for zone in ["iCloud.is.workflow.my.workflows", "com.apple.CloudDocs"] {
+ Mock::given(method("GET"))
+ .and(path(format!("/ws/{zone}/download/by_id")))
+ .respond_with(ResponseTemplate::new(200).set_body_json(
+ serde_json::json!({ "data_token": { "url": format!("https://x/{zone}") } }),
+ ))
+ .mount(&server)
+ .await;
+ }
+ let http = reqwest::Client::new();
+ let got = download_url(
+ &http,
+ &server.uri(),
+ vec![],
+ &file("FILE::iCloud.is.workflow.my.workflows::ABC"),
+ )
+ .await
+ .unwrap();
+ assert!(got.ends_with("iCloud.is.workflow.my.workflows"), "{got}");
+
+ let ordinary = download_url(
+ &http,
+ &server.uri(),
+ vec![],
+ &file("FILE::com.apple.CloudDocs::XYZ"),
+ )
+ .await
+ .unwrap();
+ assert!(ordinary.ends_with("com.apple.CloudDocs"), "{ordinary}");
+ }
+}
diff --git a/probe/examples/sections.rs b/probe/examples/sections.rs
deleted file mode 100644
index 4baa107..0000000
--- a/probe/examples/sections.rs
+++ /dev/null
@@ -1,42 +0,0 @@
-//! Throwaway: sync reminders the way the app does and show what landed in each section.
-use anyhow::{anyhow, Result};
-
-#[tokio::main]
-async fn main() -> Result<()> {
- let dir = std::path::PathBuf::from(std::env::var("HOME")?).join(".local/share/quince-probe");
- let mut client = quince_auth::Client::new(&dir)?;
- if !client.resume().await? {
- return Err(anyhow!("no session"));
- }
- let root = client
- .session()
- .service_url("ckdatabasews")
- .ok_or_else(|| anyhow!("no ck"))?;
- let http = client.http().clone();
- let store = std::env::temp_dir().join(format!("quince-{}", uuid::Uuid::new_v4()));
- std::fs::create_dir_all(&store)?;
- let mut lib = quince_core::Library::open(&store)?;
- quince_icloud::reminders::sync_cloudkit(&http, &root, client.service_params(), &mut lib, None)
- .await?;
- for list in lib.reminder_lists()? {
- let sections = lib.reminder_sections(&list.guid)?;
- if sections.is_empty() {
- continue;
- }
- let items = lib.reminders_in(&list.guid, false)?;
- println!("{}:", list.title);
- for s in &sections {
- let under: Vec<_> = items
- .iter()
- .filter(|r| r.section_guid.as_deref() == Some(s.guid.as_str()))
- .map(|r| r.title.clone())
- .collect();
- println!(" [{}] {} reminder(s): {:?}", s.title, under.len(), under);
- }
- println!(
- " (outside any section) {}",
- items.iter().filter(|r| r.section_guid.is_none()).count()
- );
- }
- Ok(())
-}