diff --git a/src/podcasts/publication.rs b/src/podcasts/publication.rs index a2be2c9..3e3f32a 100644 --- a/src/podcasts/publication.rs +++ b/src/podcasts/publication.rs @@ -46,6 +46,7 @@ use furumi_library::podcasts::{PodcastListFilter, PodcastStore, PodcastSummary}; use music_dht::podcast::{FeedUrl, PodcastId, ShareRecord, SubscriptionRecord, effective_share}; use music_dht::podcast_dht::{ FeedUrlPrivacyWarning, PodcastCardSpec, PodcastDht, PodcastDhtSyncStats, PodcastShareState, + feed_url_privacy_warning, }; use serde::{Deserialize, Serialize}; use tokio::sync::{Notify, watch}; @@ -345,6 +346,11 @@ pub fn confirmations_path(db_path: &Path) -> PathBuf { /// counters from the local catalog (refreshed from the feed), `feed_url` the /// URL this device fetches, `id_feed_url` the origin URL the podcast id was /// derived from. Bounded to the card limits. +/// +/// The artwork and web page URLs are left out when they look private +/// themselves (`feed_url_privacy_warning`) or when the feed URLs do: member +/// feeds serve signed artwork and item links, and the share dialog shows +/// the feed URLs only. fn catalog_card( summary: &PodcastSummary, subscription: &SubscriptionRecord, @@ -356,7 +362,7 @@ fn catalog_card( .clone() .unwrap_or_else(|| derived.feed_url.clone()); let meta = &summary.meta; - let card = PodcastCardSpec { + let mut card = PodcastCardSpec { podcast_id: subscription.podcast_id.clone(), feed_url: meta.feed_url.clone(), id_feed_url: Some(origin), @@ -369,12 +375,25 @@ fn catalog_card( categories: Vec::new(), episode_count: Some(u32::try_from(summary.episode_count).unwrap_or(u32::MAX)), latest_episode_at_ms: summary.latest_published_at_ms, + }; + let private_feed = !card.privacy_warnings().is_empty(); + for url in [&mut card.image_url, &mut card.link] { + if private_feed || url.as_deref().is_some_and(looks_private) { + *url = None; + } } - .bounded(); + let card = card.bounded(); card.validate()?; Ok(card) } +/// An artwork or web page URL that must not be published: it carries what +/// looks like an access key (the feed URL rules), or it is not a plain +/// http(s) URL those rules can check. +fn looks_private(url: &str) -> bool { + FeedUrl::parse(url).map_or(true, |url| feed_url_privacy_warning(&url).is_some()) +} + /// The card [`share_states`] would publish for `podcast_id` (whether or not /// it is shared yet), for the share confirmation. `None` when there is no /// subscription. diff --git a/src/podcasts/publication_tests.rs b/src/podcasts/publication_tests.rs index 698c27d..4729551 100644 --- a/src/podcasts/publication_tests.rs +++ b/src/podcasts/publication_tests.rs @@ -86,9 +86,13 @@ impl Device { link: None, image_url: None, }; + self.subscribe_meta(store, &meta) + } + + fn subscribe_meta(&mut self, store: &PodcastStore, meta: &PodcastMeta) -> PodcastId { let mut id = None; self.act(|stamps| { - let outcome = store.subscribe(stamps, &meta)?; + let outcome = store.subscribe(stamps, meta)?; id = Some(outcome.podcast_id); Ok(outcome.ops) }); @@ -389,6 +393,53 @@ fn a_confirmation_does_not_outlive_a_revocation_on_another_device() { ); } +#[test] +fn cards_leave_out_artwork_and_links_that_look_private() { + let store = PodcastStore::open_in_memory().unwrap(); + let mut device = Device::new("device-a"); + let meta = |feed: &str, image: &str, link: &str| PodcastMeta { + feed_url: FeedUrl::parse(feed).unwrap(), + title: "Art Show".to_string(), + author: None, + description: None, + image_url: Some(image.to_string()), + link: Some(link.to_string()), + }; + // A public feed: plain URLs stay, a signed one is left out. + let show = device.subscribe_meta( + &store, + &meta( + SHOW_URL, + "https://cdn.example.test/art.jpg?token=0123456789abcdef", + "https://rust-radio.example.test/", + ), + ); + let card = share_card(&store, &show).unwrap().unwrap(); + assert_eq!( + card.image_url, None, + "the signed artwork URL is not published" + ); + assert_eq!( + card.link.as_deref(), + Some("https://rust-radio.example.test/") + ); + assert!(card.privacy_warnings().is_empty()); + + // A member feed (its URL needs the dialog): artwork and page are left + // out whatever they look like, the dialog shows the feed URLs only. + let secret = device.subscribe_meta( + &store, + &meta( + SECRET_URL, + "https://cdn.example.test/members-art.jpg", + "https://members.example.test/show", + ), + ); + let card = share_card(&store, &secret).unwrap().unwrap(); + assert!(!card.privacy_warnings().is_empty()); + assert_eq!((card.image_url, card.link), (None, None)); +} + #[test] fn revocations_that_fail_are_reported_without_ids() { let show = PodcastId::from_feed_url(&FeedUrl::parse(SHOW_URL).unwrap());