From c49e2175a1b34ec18dfc2bf4c403445abc099bc8 Mon Sep 17 00:00:00 2001 From: YoursFunny Date: Thu, 24 Sep 2026 04:20:02 +0800 Subject: [PATCH] refactor(site): drop RenderData's url field, source_url already carries it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every adapter built RenderData { url } from the exact value it then moved into Fetched.source_url — a copy of the same canonical URL held in two places, feeding one placeholder. caption_with reads {url} from self.source_url now and the field is gone from the struct (bsky's and twitter's halves of this change landed with their caption commits; their render builders no longer set it either). --- crates/x-media/src/site/bilibili/interface.rs | 1 - crates/x-media/src/site/misskey/interface.rs | 1 - crates/x-media/src/site/mod.rs | 13 +++++++------ crates/x-media/src/site/pixiv/interface.rs | 1 - 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/crates/x-media/src/site/bilibili/interface.rs b/crates/x-media/src/site/bilibili/interface.rs index bd0725c..647a3d0 100644 --- a/crates/x-media/src/site/bilibili/interface.rs +++ b/crates/x-media/src/site/bilibili/interface.rs @@ -289,7 +289,6 @@ impl From for Fetched { sensitive: false, site_id: "bilibili", render_data: Some(RenderData { - url, author: encode_text(&author).into_owned(), author_url, title: encode_text(&title).into_owned(), diff --git a/crates/x-media/src/site/misskey/interface.rs b/crates/x-media/src/site/misskey/interface.rs index 6ff3a85..8811969 100644 --- a/crates/x-media/src/site/misskey/interface.rs +++ b/crates/x-media/src/site/misskey/interface.rs @@ -133,7 +133,6 @@ impl From for Fetched { sensitive, site_id: "misskey", render_data: Some(RenderData { - url, author: encode_text(&author).into_owned(), author_url: author_url.clone(), title: String::new(), diff --git a/crates/x-media/src/site/mod.rs b/crates/x-media/src/site/mod.rs index 1e1f165..9c191d3 100644 --- a/crates/x-media/src/site/mod.rs +++ b/crates/x-media/src/site/mod.rs @@ -69,13 +69,14 @@ pub struct Fetched { /// /// `author`, `title`, `content` and `tags` come from the site API (post /// text, display names, descriptions) and are HTML-escaped at construction. -/// `url` and `author_url` stay raw: they are canonical URLs the adapter -/// builds from numeric ids and API-constrained handles/DIDs, so they carry -/// no escapable character — the bot's `/test` report relies on that when it -/// embeds them. +/// `author_url` stays raw: it is a canonical URL the adapter builds from +/// numeric ids and API-constrained handles/DIDs, so it carries no escapable +/// character — the bot's `/test` report relies on that when it embeds it. +/// `{url}` needs no copy here: [`Fetched::source_url`] is the same canonical +/// URL every adapter would have handed this struct, and `caption_with` reads +/// it from there. #[derive(Debug)] pub(crate) struct RenderData { - pub url: String, pub author: String, pub author_url: String, pub title: String, @@ -125,7 +126,7 @@ impl Fetched { (Some(data), false) => caption_from_fields( format, "", - &data.url, + &self.source_url, &data.author, &data.author_url, &data.title, diff --git a/crates/x-media/src/site/pixiv/interface.rs b/crates/x-media/src/site/pixiv/interface.rs index dba8945..bb3137b 100644 --- a/crates/x-media/src/site/pixiv/interface.rs +++ b/crates/x-media/src/site/pixiv/interface.rs @@ -289,7 +289,6 @@ impl From for Fetched { .collect::>() .join(" "); let render_data = Some(crate::site::RenderData { - url: url.clone(), author: encode_text(&illustration.author).into_owned(), author_url: author_url.clone(), title: encode_text(&illustration.title).into_owned(),