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.
This commit is contained in:
2026-09-21 17:16:21 +08:00
parent 4e42855c59
commit c8a32d49c9
4 changed files with 6 additions and 13 deletions
+1 -8
View File
@@ -92,13 +92,6 @@ pub fn compose_text(title: &str, content: &str) -> String {
} }
impl Fetched { 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 /// Renders a user-supplied caption format. The format string is
/// HTML-escaped in full, then the (already-escaped) placeholder values /// HTML-escaped in full, then the (already-escaped) placeholder values
/// are substituted — users can structure text but never inject raw HTML /// 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<Option<Fetched>
log::debug!( log::debug!(
"fetched [key={}]: site {} returned {} media in {}ms", "fetched [key={}]: site {} returned {} media in {}ms",
cache_key(url).unwrap_or_else(|| "?".into()), cache_key(url).unwrap_or_else(|| "?".into()),
fetched.site_name(), fetched.site_id,
fetched.media.len(), fetched.media.len(),
started.elapsed().as_millis() started.elapsed().as_millis()
); );
+1 -1
View File
@@ -602,7 +602,7 @@ mod tests {
); );
// Empty format falls back to the built-in caption. // Empty format falls back to the built-in caption.
assert_eq!(fetched.caption_with(""), fetched.caption); assert_eq!(fetched.caption_with(""), fetched.caption);
assert_eq!(fetched.site_name(), "pixiv"); assert_eq!(fetched.site_id, "pixiv");
} }
#[test] #[test]
+2 -2
View File
@@ -627,7 +627,7 @@ pub(crate) async fn execute_command(
.get(message.chat.id.0) .get(message.chat.id.0)
.await .await
.message_format .message_format
.get(fetched.site_name()) .get(fetched.site_id)
.cloned() .cloned()
.unwrap_or_default(); .unwrap_or_default();
let caption = preview_caption( let caption = preview_caption(
@@ -639,7 +639,7 @@ pub(crate) async fn execute_command(
); );
let report = debug_report( let report = debug_report(
url, url,
fetched.site_name(), fetched.site_id,
&fetched.source_url, &fetched.source_url,
&fetched.title, &fetched.title,
&fetched.content, &fetched.content,
+2 -2
View File
@@ -715,7 +715,7 @@ async fn url_media_inner(
// Per-site caption format override (empty -> built-in caption). // Per-site caption format override (empty -> built-in caption).
let format = chat_data let format = chat_data
.message_format .message_format
.get(fetched.site_name()) .get(fetched.site_id)
.cloned() .cloned()
.unwrap_or_default(); .unwrap_or_default();
let caption = fetched.caption_with(&format); let caption = fetched.caption_with(&format);
@@ -864,7 +864,7 @@ async fn refetch(
let chat_data = ctx.chat_store.get(chat_id).await; let chat_data = ctx.chat_store.get(chat_id).await;
let format = chat_data let format = chat_data
.message_format .message_format
.get(fetched.site_name()) .get(fetched.site_id)
.cloned() .cloned()
.unwrap_or_default(); .unwrap_or_default();
let caption = fetched.caption_with(&format); let caption = fetched.caption_with(&format);