diff --git a/crates/x-media/src/site/misskey/interface.rs b/crates/x-media/src/site/misskey/interface.rs index 7c8d9f1..6ff3a85 100644 --- a/crates/x-media/src/site/misskey/interface.rs +++ b/crates/x-media/src/site/misskey/interface.rs @@ -209,7 +209,6 @@ mod tests { cache_key("https://misskey.io/notes/aotihl10lqrs015s"), Some("misskey:aotihl10lqrs015s".to_string()) ); - assert_eq!(crate::site::site_id_from_key("misskey:abc"), "misskey"); } #[test] diff --git a/crates/x-media/src/site/mod.rs b/crates/x-media/src/site/mod.rs index 4511dd7..bf5a5e1 100644 --- a/crates/x-media/src/site/mod.rs +++ b/crates/x-media/src/site/mod.rs @@ -231,19 +231,6 @@ pub fn cache_key(url: &str) -> Option { SITES.iter().find_map(|site| site.cache_key(url)) } -/// The site id carried by a cache key (`"twitter:123"` → `"twitter"`). -/// Unknown prefixes fall back to `"unknown"`. The bot uses this on the -/// link-cache hit path, where no [`Fetched`] is available — the same value -/// a fresh fetch would read from [`Fetched::site_id`]. -pub fn site_id_from_key(key: &str) -> &'static str { - let prefix = key.split(':').next().unwrap_or(""); - SITES - .iter() - .map(|site| site.id()) - .find(|id| *id == prefix) - .unwrap_or("unknown") -} - #[derive(Debug, Error)] pub enum FetchError { #[error("http error: {0}")] @@ -591,16 +578,6 @@ mod tests { assert_eq!(cache_key("https://example.com/not-a-post"), None); } - #[test] - fn site_id_from_key_parses_prefix() { - assert_eq!(site_id_from_key("twitter:123"), "twitter"); - assert_eq!(site_id_from_key("pixiv:123"), "pixiv"); - assert_eq!(site_id_from_key("bsky:handle.example/3lorem"), "bsky"); - assert_eq!(site_id_from_key("bilibili:123"), "bilibili"); - assert_eq!(site_id_from_key("unknown:1"), "unknown"); - assert_eq!(site_id_from_key("no-colon"), "unknown"); - } - #[test] fn registry_lists_all_sites_in_dispatch_order() { assert_eq!( diff --git a/crates/xmedia-bot/src/handlers/urls.rs b/crates/xmedia-bot/src/handlers/urls.rs index 22aec7f..048351f 100644 --- a/crates/xmedia-bot/src/handlers/urls.rs +++ b/crates/xmedia-bot/src/handlers/urls.rs @@ -554,8 +554,10 @@ async fn url_media_inner( log::debug!("link cache hit for {key}"); let chat_data = ctx.chat_store.get(chat_id).await; // Cache keys are prefixed with the site id ("twitter:…"), matching - // the value a fresh fetch would read from Fetched::site_id. - let site = x_media::site::site_id_from_key(&key); + // the value a fresh fetch would read from Fetched::site_id. The key + // came out of cache_key, so its prefix is a registered id by + // construction — splitting it off is the whole lookup. + let site = key.split(':').next().unwrap_or(""); let format = chat_data.format_for(site); // One call for both: `caption_from_fields` returns the truncated // built-in caption itself when the chat has no format for this site.