Skip to content

feat(fetcher): add random_cat — random cat picture from cataas.com - #191

Merged
unhappychoice merged 1 commit into
mainfrom
feat/random-cat-fetcher
Apr 29, 2026
Merged

unhappychoice merged 1 commit into
mainfrom
feat/random-cat-fetcher

Conversation

@unhappychoice

@unhappychoice unhappychoice commented Apr 29, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Image-only fetcher that downloads a random cat from cataas.com each refresh cycle and exposes it as Body::Image. Caches to $SPLASHBOARD_HOME/cache/cats/<key>.<ext>.
  • Safety::Safe: host hardcoded to cataas.com (config can't redirect traffic), no auth (no token to leak). Mirrors the github_avatar fixed-host stance from project_trust_model.md.
  • Optional tag option for cataas.com tag filtering (cute / orange / kitten / cute,fat AND-join). Empty / whitespace falls through to "any cat".
  • Ticks the random_cat checkbox on meta: fetcher roadmap - Social & Media #67.

Reference

Kind Safety Shapes
cached Safe image

Options

Option Type Required Default Description
tag string no — cataas.com tag filter (e.g. cute, orange, kitten). Omit for any cat.

Compatible renderers

Shape Renderers
image animated_boot, animated_postfx, animated_scanlines, animated_splitflap, animated_wave, media_image

Implementation notes

  • Magic-byte format detection (PNG / JPEG / GIF / WebP) — cataas occasionally returns GIFs, and image::ImageReader::open decodes by extension hint, so the cached file's suffix must match the actual format.
  • Stale-extension cleanup: format-changing refreshes (PNG → JPG) remove the prior <key>.<ext> siblings before the new write so a stale file with a different suffix can't mislead the renderer.
  • 5 MB body cap to bound memory if the upstream returns something pathological.
  • Tag is percent-encoded (preserves , for multi-tag AND).

Test plan

  • cargo fmt --all -- --check
  • cargo clippy --all-targets -- -D warnings
  • cargo test (1227+ green)
  • cargo xtask regenerates docs-site/src/content/docs/reference/fetchers/random/random_cat.md cleanly
  • Smoke-tested locally with media_image (default tag, cute, orange) — three cats render side by side
  • Live test (downloads a real cat): cargo test -- --ignored fetcher::random_cat::tests::live --nocapture

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features
    • Added a new fetcher that retrieves random cat images from an external service and caches them locally. Users can filter images with optional tags, and the fetcher automatically detects and supports multiple image formats including PNG, JPG, GIF, and WebP. Cached images are reused for faster access on repeat requests.

Image-only fetcher, Safety::Safe (host hardcoded to cataas.com so config
can't redirect traffic). Each refresh downloads a fresh cat to
`$SPLASHBOARD_HOME/cache/cats/<key>.<ext>` (PNG / JPEG / GIF / WebP via
magic-byte detection). Optional `tag` filter for cataas.com tags.

Ticks `random_cat` box on #67.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Apr 29, 2026 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: db77f4ba-5cc2-422f-84c9-43bf6c0ae23d

📥 Commits

Reviewing files that changed from the base of the PR and between 4267d01 and 567fcad.

📒 Files selected for processing (2)
  • src/fetcher/mod.rs
  • src/fetcher/random_cat.rs

📝 Walkthrough

Walkthrough

A new RandomCatFetcher has been added to download random cat images from cataas.com with optional tag filtering. The fetcher includes image type detection, 5MB size capping, automatic caching with stale file cleanup, and is registered in the built-in fetcher registry.

Changes

Cohort / File(s) Summary
Random Cat Fetcher Implementation
src/fetcher/random_cat.rs
New fetcher module that downloads cat images from external API, detects image type (PNG/JPG/GIF/WebP), validates options, encodes tag parameters for URLs, manages cache storage with stale file cleanup, enforces 5MB size limits, and includes comprehensive unit tests.
Fetcher Registry
src/fetcher/mod.rs
Added module export for random_cat and registered RandomCatFetcher in Registry::with_builtins() alongside other built-in fetchers.

Possibly related PRs

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A fluffy new friend hops into the frame,
From cataas.com, a feline comes to claim fame,
With tags and caching, it bounces with glee,
Random cat images for all to see! ✨🐱

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/random-cat-fetcher

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

@unhappychoice
unhappychoice merged commit 6796bae into main Apr 29, 2026
5 checks passed
@unhappychoice
unhappychoice deleted the feat/random-cat-fetcher branch April 29, 2026 12:21
@codecov

codecov Bot commented Apr 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 62.74510% with 76 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.79%. Comparing base (8650cc6) to head (567fcad).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/fetcher/random_cat.rs 62.56% 76 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #191      +/-   ##
==========================================
- Coverage   81.92%   81.79%   -0.13%     
==========================================
  Files         139      140       +1     
  Lines       29486    29690     +204     
==========================================
+ Hits        24157    24286     +129     
- Misses       5329     5404      +75     
Files with missing lines Coverage Δ
src/fetcher/mod.rs 85.01% <100.00%> (+0.04%) ⬆️
src/fetcher/random_cat.rs 62.56% <62.56%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant