mirror of
https://github.com/TheFunny/TelegramTwitterMediaBot.git
synced 2026-09-23 23:32:05 +00:00
Replace display_text_range slicing with FxEmbed-style content matching: expand mapped t.co links to their real URLs (dropping internal x.com/i/web/status pages), then strip every leftover t.co short link (appended media link, unmapped links). The old code cut by display_text_range, whose index unit differs per endpoint (UTF-16 on the syndication endpoint, code points in the GraphQL fallback), so slicing by either unit left a partial "https://t." caption tail on the other path. Content matching is unit-agnostic and also keeps user-posted/quote links at the end of the text that the trailing cut previously dropped.
59 lines
1.4 KiB
Rust
59 lines
1.4 KiB
Rust
use serde::Deserialize;
|
|
|
|
/// Response shape of the syndication endpoint
|
|
/// (`cdn.syndication.twimg.com/tweet-result`).
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct SyndicationTweet {
|
|
pub id_str: String,
|
|
pub text: String,
|
|
pub user: SyndicationUser,
|
|
#[serde(default)]
|
|
pub possibly_sensitive: Option<bool>,
|
|
#[serde(default)]
|
|
pub entities: SyndicationEntities,
|
|
#[serde(default, rename = "mediaDetails")]
|
|
pub media_details: Vec<SyndicationMedia>,
|
|
}
|
|
|
|
#[derive(Deserialize, Debug, Default)]
|
|
pub struct SyndicationEntities {
|
|
#[serde(default)]
|
|
pub urls: Vec<SyndicationEntityUrl>,
|
|
}
|
|
|
|
/// A URL entity: `url` is the t.co short link as it appears in the text,
|
|
/// `expanded_url` the real destination.
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct SyndicationEntityUrl {
|
|
pub url: String,
|
|
#[serde(default)]
|
|
pub expanded_url: Option<String>,
|
|
}
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct SyndicationUser {
|
|
pub name: String,
|
|
pub screen_name: String,
|
|
}
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct SyndicationMedia {
|
|
#[serde(rename = "type")]
|
|
pub media_type: String,
|
|
pub media_url_https: String,
|
|
#[serde(default)]
|
|
pub video_info: Option<SyndicationVideoInfo>,
|
|
}
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct SyndicationVideoInfo {
|
|
#[serde(default)]
|
|
pub variants: Vec<SyndicationVariant>,
|
|
}
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct SyndicationVariant {
|
|
pub content_type: String,
|
|
pub url: String,
|
|
}
|