Skip to content

Commit 6d7fd5f

Browse files
committed
fix(media): restore small-file fallback and notify user on HTTP 4xx
- Restore ≤1MB raw-byte fallback when resize_and_compress fails after validate_image_response passes. The body is confirmed valid by magic-byte check, so forwarding original bytes is safe. Prevents regression for formats the image crate can detect but not fully decode (e.g. animated WebP). - Add HttpStatus 4xx match arm in Slack handler to push filename into failed_image_files. HTTP 4xx (401/403) indicates a persistent permission problem (similar root cause to #776) and the user should be notified. 5xx and Network errors remain log-only (transient).
1 parent 4967718 commit 6d7fd5f

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

src/media.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,18 @@ pub async fn download_and_encode_image(
272272
let (output_bytes, output_mime) = match resize_and_compress(&bytes) {
273273
Ok(result) => result,
274274
Err(e) => {
275-
error!(
276-
filename,
277-
error = %e,
278-
size = bytes.len(),
279-
"resize failed after successful validation"
280-
);
281-
return Err(MediaFetchError::ProcessingFailed(e));
275+
if bytes.len() <= 1024 * 1024 {
276+
debug!(filename, error = %e, "resize failed, using validated original");
277+
(bytes.to_vec(), mime.to_string())
278+
} else {
279+
error!(
280+
filename,
281+
error = %e,
282+
size = bytes.len(),
283+
"resize failed after successful validation"
284+
);
285+
return Err(MediaFetchError::ProcessingFailed(e));
286+
}
282287
}
283288
};
284289

src/slack.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,12 @@ async fn handle_message(
10661066
warn!(filename, error = %e, "image post-processing failed");
10671067
failed_image_files.push(filename.to_string());
10681068
}
1069+
Err(media::MediaFetchError::HttpStatus(status))
1070+
if status.is_client_error() =>
1071+
{
1072+
warn!(filename, %status, "image download denied");
1073+
failed_image_files.push(filename.to_string());
1074+
}
10691075
Err(e) => {
10701076
warn!(filename, error = %e, "image download failed");
10711077
}

0 commit comments

Comments
 (0)