From c8a32d49c9d3b5f9005fcaee56b4cf55980c7684 Mon Sep 17 00:00:00 2001 From: YoursFunny Date: Mon, 21 Sep 2026 17:16:21 +0800 Subject: [PATCH] refactor(x-media): read Fetched::site_id instead of the site_name alias site_name() only returned the public site_id field; the five callers (the /debug report, the caption-format lookup on both fetch paths, the per-site override in urls.rs) read the field now. --- crates/x-media/src/site/mod.rs | 9 +-------- crates/x-media/src/site/pixiv/interface.rs | 2 +- crates/xmedia-bot/src/handlers/commands.rs | 4 ++-- crates/xmedia-bot/src/handlers/urls.rs | 4 ++-- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/crates/x-media/src/site/mod.rs b/crates/x-media/src/site/mod.rs index ed96eac..b288397 100644 --- a/crates/x-media/src/site/mod.rs +++ b/crates/x-media/src/site/mod.rs @@ -92,13 +92,6 @@ pub fn compose_text(title: &str, content: &str) -> String { } impl Fetched { - /// The site this post came from (used for per-site format overrides). - /// A thin alias over [`Fetched::site_id`] kept for callers that read the - /// site off a fetched post. - pub fn site_name(&self) -> &'static str { - self.site_id - } - /// Renders a user-supplied caption format. The format string is /// HTML-escaped in full, then the (already-escaped) placeholder values /// are substituted — users can structure text but never inject raw HTML @@ -586,7 +579,7 @@ async fn fetch_with_attempts(url: &str, attempts: u32) -> Result log::debug!( "fetched [key={}]: site {} returned {} media in {}ms", cache_key(url).unwrap_or_else(|| "?".into()), - fetched.site_name(), + fetched.site_id, fetched.media.len(), started.elapsed().as_millis() ); diff --git a/crates/x-media/src/site/pixiv/interface.rs b/crates/x-media/src/site/pixiv/interface.rs index b81afd7..01f3bec 100644 --- a/crates/x-media/src/site/pixiv/interface.rs +++ b/crates/x-media/src/site/pixiv/interface.rs @@ -602,7 +602,7 @@ mod tests { ); // Empty format falls back to the built-in caption. assert_eq!(fetched.caption_with(""), fetched.caption); - assert_eq!(fetched.site_name(), "pixiv"); + assert_eq!(fetched.site_id, "pixiv"); } #[test] diff --git a/crates/xmedia-bot/src/handlers/commands.rs b/crates/xmedia-bot/src/handlers/commands.rs index 89bc751..3e43cc6 100644 --- a/crates/xmedia-bot/src/handlers/commands.rs +++ b/crates/xmedia-bot/src/handlers/commands.rs @@ -627,7 +627,7 @@ pub(crate) async fn execute_command( .get(message.chat.id.0) .await .message_format - .get(fetched.site_name()) + .get(fetched.site_id) .cloned() .unwrap_or_default(); let caption = preview_caption( @@ -639,7 +639,7 @@ pub(crate) async fn execute_command( ); let report = debug_report( url, - fetched.site_name(), + fetched.site_id, &fetched.source_url, &fetched.title, &fetched.content, diff --git a/crates/xmedia-bot/src/handlers/urls.rs b/crates/xmedia-bot/src/handlers/urls.rs index ca81d0d..0c97897 100644 --- a/crates/xmedia-bot/src/handlers/urls.rs +++ b/crates/xmedia-bot/src/handlers/urls.rs @@ -715,7 +715,7 @@ async fn url_media_inner( // Per-site caption format override (empty -> built-in caption). let format = chat_data .message_format - .get(fetched.site_name()) + .get(fetched.site_id) .cloned() .unwrap_or_default(); let caption = fetched.caption_with(&format); @@ -864,7 +864,7 @@ async fn refetch( let chat_data = ctx.chat_store.get(chat_id).await; let format = chat_data .message_format - .get(fetched.site_name()) + .get(fetched.site_id) .cloned() .unwrap_or_default(); let caption = fetched.caption_with(&format);