mirror of
https://github.com/TheFunny/TelegramTwitterMediaBot.git
synced 2026-09-23 23:32:05 +00:00
chore: clippy and rustfmt cleanup on new code
This commit is contained in:
@@ -92,12 +92,12 @@ async fn resolve_bsky_video(
|
||||
.and_then(|(_, rest)| rest.split(|c: char| !c.is_ascii_digit()).next())
|
||||
.and_then(|n| n.parse::<u64>().ok())
|
||||
.unwrap_or(0);
|
||||
if let Some(uri) = lines.next().filter(|u| !u.starts_with('#')) {
|
||||
if bandwidth >= best.as_ref().map(|(b, _)| *b).unwrap_or(0) {
|
||||
if let Some(uri) = lines.next().filter(|u| !u.starts_with('#'))
|
||||
&& bandwidth >= best.as_ref().map(|(b, _)| *b).unwrap_or(0)
|
||||
{
|
||||
best = Some((bandwidth, uri.to_string()));
|
||||
}
|
||||
}
|
||||
}
|
||||
let Some((_, uri)) = best else {
|
||||
return Err("bsky video master playlist has no variants".to_string());
|
||||
};
|
||||
@@ -199,7 +199,7 @@ pub async fn fetch(handle: &str, rkey: &str) -> Result<Post, FetchError> {
|
||||
};
|
||||
}
|
||||
let text = response.text().await?;
|
||||
Ok(Post::from_json(&text, rkey.to_string())?)
|
||||
Post::from_json(&text, rkey.to_string())
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
||||
@@ -318,10 +318,7 @@ pub async fn media_size(url: &str) -> Result<Option<u64>, FetchError> {
|
||||
/// download aborts with [`FetchError::TooLarge`] the moment the cap is
|
||||
/// crossed (or when a declared Content-Length already exceeds it). Keeps the
|
||||
/// bot from buffering arbitrarily large bodies into memory.
|
||||
pub async fn download_media_limited(
|
||||
url: &str,
|
||||
max_bytes: u64,
|
||||
) -> Result<bytes::Bytes, FetchError> {
|
||||
pub async fn download_media_limited(url: &str, max_bytes: u64) -> Result<bytes::Bytes, FetchError> {
|
||||
let mut request = CLIENT.get(url);
|
||||
let lower = url.to_ascii_lowercase();
|
||||
if lower.contains("pximg.net") {
|
||||
|
||||
@@ -137,10 +137,7 @@ impl PixivAPI {
|
||||
.send()
|
||||
.await?;
|
||||
if !response.status().is_success() {
|
||||
return Err(PixivError::Api(format!(
|
||||
"status {}",
|
||||
response.status()
|
||||
)));
|
||||
return Err(PixivError::Api(format!("status {}", response.status())));
|
||||
}
|
||||
let json: serde_json::Value = serde_json::from_str(&response.text().await?)?;
|
||||
if json.get("error").is_some() {
|
||||
@@ -193,10 +190,7 @@ impl PixivAPI {
|
||||
.send()
|
||||
.await?;
|
||||
if !response.status().is_success() {
|
||||
return Err(PixivError::Api(format!(
|
||||
"status {}",
|
||||
response.status()
|
||||
)));
|
||||
return Err(PixivError::Api(format!("status {}", response.status())));
|
||||
}
|
||||
let json: serde_json::Value = serde_json::from_str(&response.text().await?)?;
|
||||
if json.get("error").is_some() {
|
||||
@@ -250,7 +244,7 @@ impl PixivAPI {
|
||||
// frames are uniformly jpg or png per artwork.
|
||||
let mut archive = zip::ZipArchive::new(Cursor::new(zip_bytes))
|
||||
.map_err(|e| format!("unzip: {e}"))?;
|
||||
if archive.len() == 0 {
|
||||
if archive.is_empty() {
|
||||
return Err("empty frame zip".to_string());
|
||||
}
|
||||
// Uniform jpg or png per artwork; sniff the first entry's
|
||||
|
||||
@@ -132,7 +132,9 @@ pub async fn fetch(id: &str) -> Result<Tweet, FetchError> {
|
||||
log::warn!("twitter auth fetch {id}: HTTP {status}");
|
||||
return match status.as_u16() {
|
||||
404 | 410 => Err(FetchError::NotFound),
|
||||
_ => Err(FetchError::Transient(format!("twitter auth status {status}"))),
|
||||
_ => Err(FetchError::Transient(format!(
|
||||
"twitter auth status {status}"
|
||||
))),
|
||||
};
|
||||
}
|
||||
let text = response.text().await?;
|
||||
|
||||
@@ -24,8 +24,7 @@ type UrlJob = (Bot, Message, String);
|
||||
static URL_JOBS: LazyLock<parking_lot::Mutex<Option<tokio::sync::mpsc::Sender<UrlJob>>>> =
|
||||
LazyLock::new(|| parking_lot::Mutex::new(None));
|
||||
/// Set by main's shutdown sequence; workers stop pulling new jobs.
|
||||
static URL_STOP: std::sync::atomic::AtomicBool =
|
||||
std::sync::atomic::AtomicBool::new(false);
|
||||
static URL_STOP: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
|
||||
|
||||
/// Worker count draining URL jobs; keeps the old 8-permit concurrency cap
|
||||
/// while bounding how many jobs can be queued at all.
|
||||
|
||||
@@ -641,7 +641,12 @@ async fn send_batch_via_upload(
|
||||
.map_err(|message| FallbackError::Permanent { message })?
|
||||
}
|
||||
PhotoPrep::UseFallback => match item.fallback_url() {
|
||||
Some(url) => match media_from_url(item, url, item_caption, item.thumbnail_url()) {
|
||||
Some(url) => match media_from_url(
|
||||
item,
|
||||
url,
|
||||
item_caption,
|
||||
item.thumbnail_url(),
|
||||
) {
|
||||
Ok(media) => media,
|
||||
Err(message) => {
|
||||
return Err(FallbackError::Permanent { message });
|
||||
@@ -664,12 +669,14 @@ async fn send_batch_via_upload(
|
||||
}
|
||||
}
|
||||
Err(FallbackError::MediaTooLarge) => match item.fallback_url() {
|
||||
Some(url) => match media_from_url(item, url, item_caption, item.thumbnail_url()) {
|
||||
Some(url) => {
|
||||
match media_from_url(item, url, item_caption, item.thumbnail_url()) {
|
||||
Ok(media) => media,
|
||||
Err(message) => {
|
||||
return Err(FallbackError::Permanent { message });
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
None => {
|
||||
return Err(FallbackError::Permanent {
|
||||
message: "media too large".into(),
|
||||
|
||||
Reference in New Issue
Block a user