refactor(x-media): drop Media's write-only title field

Every adapter set title (mostly None) on all three Media variants and
nothing ever read it: the bot's CachedMedia carries kind/file_id/url, and the
one read was misskey's own test. Removing it also drops misskey's
DriveFile.name, which existed only to feed it. Fetched::title (the post's
own headline, which captions do use) is untouched.
This commit is contained in:
2026-09-21 17:15:27 +08:00
parent 9a7cda05c9
commit 4e42855c59
9 changed files with 0 additions and 25 deletions
-3
View File
@@ -37,18 +37,15 @@ impl Media {
#[derive(Debug)] #[derive(Debug)]
pub enum Media { pub enum Media {
Illustration { Illustration {
title: Option<String>,
url: String, url: String,
thumbnail_url: Option<String>, thumbnail_url: Option<String>,
fallback_url: Option<String>, fallback_url: Option<String>,
}, },
Video { Video {
title: Option<String>,
url: String, url: String,
thumbnail_url: String, thumbnail_url: String,
}, },
Animated { Animated {
title: Option<String>,
url: String, url: String,
thumbnail_url: String, thumbnail_url: String,
}, },
@@ -458,7 +458,6 @@ fn image(url: &str) -> Option<Media> {
} }
Some(if url.ends_with(".gif") { Some(if url.ends_with(".gif") {
Media::Animated { Media::Animated {
title: None,
url, url,
// Left empty on purpose: the `@518w.jpg` variant is unverified for // Left empty on purpose: the `@518w.jpg` variant is unverified for
// animated sources, and Telegram generates a frame preview itself. // animated sources, and Telegram generates a frame preview itself.
@@ -466,7 +465,6 @@ fn image(url: &str) -> Option<Media> {
} }
} else { } else {
Media::Illustration { Media::Illustration {
title: None,
// Written before `url` moves so the formatting borrows it. // Written before `url` moves so the formatting borrows it.
thumbnail_url: Some(format!("{url}{THUMB_SUFFIX}")), thumbnail_url: Some(format!("{url}{THUMB_SUFFIX}")),
url, url,
@@ -73,7 +73,6 @@ pub async fn fetch_from_url(url: &str) -> Result<Fetched, FetchError> {
_ => String::new(), _ => String::new(),
}; };
media.push(Media::Video { media.push(Media::Video {
title: None,
url: mp4_path.to_string_lossy().into_owned(), url: mp4_path.to_string_lossy().into_owned(),
thumbnail_url, thumbnail_url,
}); });
@@ -354,7 +353,6 @@ impl Post {
match embed { match embed {
model::Media::Images { images } => { model::Media::Images { images } => {
media.extend(images.into_iter().map(|image| Media::Illustration { media.extend(images.into_iter().map(|image| Media::Illustration {
title: None,
url: image.fullsize, url: image.fullsize,
thumbnail_url: Some(image.thumb), thumbnail_url: Some(image.thumb),
fallback_url: None, fallback_url: None,
@@ -365,7 +363,6 @@ impl Post {
thumbnail, thumbnail,
} => { } => {
media.push(Media::Video { media.push(Media::Video {
title: None,
url: playlist, url: playlist,
thumbnail_url: thumbnail, thumbnail_url: thumbnail,
}); });
@@ -160,21 +160,17 @@ fn caption(url: &str, author_url: &str, author: &str, text: &str) -> String {
/// are skipped (twitter's `_ => {}` precedent). GIF must be matched before /// are skipped (twitter's `_ => {}` precedent). GIF must be matched before
/// the generic image arm. /// the generic image arm.
fn media_from_file(file: &model::DriveFile) -> Option<Media> { fn media_from_file(file: &model::DriveFile) -> Option<Media> {
let title = file.name.clone();
match file.mime_type.as_str() { match file.mime_type.as_str() {
"image/gif" => Some(Media::Animated { "image/gif" => Some(Media::Animated {
title,
url: file.url.clone(), url: file.url.clone(),
thumbnail_url: file.thumbnail_url.clone().unwrap_or_default(), thumbnail_url: file.thumbnail_url.clone().unwrap_or_default(),
}), }),
mime if mime.starts_with("image/") => Some(Media::Illustration { mime if mime.starts_with("image/") => Some(Media::Illustration {
title,
url: file.url.clone(), url: file.url.clone(),
thumbnail_url: file.thumbnail_url.clone(), thumbnail_url: file.thumbnail_url.clone(),
fallback_url: None, fallback_url: None,
}), }),
mime if mime.starts_with("video/") => Some(Media::Video { mime if mime.starts_with("video/") => Some(Media::Video {
title,
url: file.url.clone(), url: file.url.clone(),
thumbnail_url: file.thumbnail_url.clone().unwrap_or_default(), thumbnail_url: file.thumbnail_url.clone().unwrap_or_default(),
}), }),
@@ -253,12 +249,10 @@ mod tests {
assert_eq!(fetched.media.len(), 1); assert_eq!(fetched.media.len(), 1);
match &fetched.media[0] { match &fetched.media[0] {
Media::Illustration { Media::Illustration {
title,
url, url,
thumbnail_url, thumbnail_url,
fallback_url, fallback_url,
} => { } => {
assert_eq!(title.as_deref(), Some("pic.webp"));
assert_eq!(url, "https://media.misskeyusercontent.jp/io/a.webp"); assert_eq!(url, "https://media.misskeyusercontent.jp/io/a.webp");
assert_eq!( assert_eq!(
thumbnail_url.as_deref(), thumbnail_url.as_deref(),
-2
View File
@@ -30,6 +30,4 @@ pub(crate) struct DriveFile {
pub(crate) thumbnail_url: Option<String>, pub(crate) thumbnail_url: Option<String>,
#[serde(default, rename = "isSensitive")] #[serde(default, rename = "isSensitive")]
pub(crate) is_sensitive: bool, pub(crate) is_sensitive: bool,
#[serde(default)]
pub(crate) name: Option<String>,
} }
-1
View File
@@ -149,7 +149,6 @@ impl PixivAPI {
match self.ugoira_video(illust_id).await { match self.ugoira_video(illust_id).await {
Ok(Some((mp4_path, _keep_alive))) => { Ok(Some((mp4_path, _keep_alive))) => {
illustration.media.push(Media::Video { illustration.media.push(Media::Video {
title: None,
url: mp4_path, url: mp4_path,
thumbnail_url: model.image_urls.medium.clone(), thumbnail_url: model.image_urls.medium.clone(),
}); });
@@ -235,7 +235,6 @@ impl Illustration {
.original .original
.clone() .clone()
.map(|original| Media::Illustration { .map(|original| Media::Illustration {
title: None,
url: original, url: original,
thumbnail_url: Some(page.image_urls.medium.clone()), thumbnail_url: Some(page.image_urls.medium.clone()),
fallback_url: Some(page.image_urls.large.clone()), fallback_url: Some(page.image_urls.large.clone()),
@@ -248,7 +247,6 @@ impl Illustration {
.or(model.image_urls.original.clone()) .or(model.image_urls.original.clone())
{ {
media.push(Media::Illustration { media.push(Media::Illustration {
title: None,
url: original, url: original,
thumbnail_url: Some(model.image_urls.medium.clone()), thumbnail_url: Some(model.image_urls.medium.clone()),
fallback_url: Some(model.image_urls.large.clone()), fallback_url: Some(model.image_urls.large.clone()),
@@ -236,7 +236,6 @@ impl Tweet {
for item in json.media_details { for item in json.media_details {
match item.media_type.as_str() { match item.media_type.as_str() {
"photo" => media.push(Media::Illustration { "photo" => media.push(Media::Illustration {
title: None,
url: original_twimg_url(&item.media_url_https), url: original_twimg_url(&item.media_url_https),
thumbnail_url: None, thumbnail_url: None,
// The param-less base URL is a reduced-size variant; // The param-less base URL is a reduced-size variant;
@@ -244,12 +243,10 @@ impl Tweet {
fallback_url: Some(item.media_url_https.clone()), fallback_url: Some(item.media_url_https.clone()),
}), }),
"video" => media.push(Media::Video { "video" => media.push(Media::Video {
title: None,
url: mp4_variant(&item), url: mp4_variant(&item),
thumbnail_url: item.media_url_https, thumbnail_url: item.media_url_https,
}), }),
"animated_gif" => media.push(Media::Animated { "animated_gif" => media.push(Media::Animated {
title: None,
url: mp4_variant(&item), url: mp4_variant(&item),
thumbnail_url: item.media_url_https, thumbnail_url: item.media_url_https,
}), }),
@@ -816,13 +816,11 @@ mod tests {
fn debug_report_renders_fields_and_media() { fn debug_report_renders_fields_and_media() {
let media = vec![ let media = vec![
Media::Illustration { Media::Illustration {
title: None,
url: "https://cdn.example/1.jpg".into(), url: "https://cdn.example/1.jpg".into(),
thumbnail_url: None, thumbnail_url: None,
fallback_url: None, fallback_url: None,
}, },
Media::Video { Media::Video {
title: None,
url: "https://cdn.example/2.mp4".into(), url: "https://cdn.example/2.mp4".into(),
thumbnail_url: "https://cdn.example/2.jpg".into(), thumbnail_url: "https://cdn.example/2.jpg".into(),
}, },
@@ -915,7 +913,6 @@ mod tests {
// 200 media lines ≈ 8 KB, comfortably over the cap. // 200 media lines ≈ 8 KB, comfortably over the cap.
let media: Vec<Media> = (0..200) let media: Vec<Media> = (0..200)
.map(|i| Media::Illustration { .map(|i| Media::Illustration {
title: None,
url: format!("https://cdn.example/{i}.jpg"), url: format!("https://cdn.example/{i}.jpg"),
thumbnail_url: None, thumbnail_url: None,
fallback_url: None, fallback_url: None,