Skip to content

feat: Actions 下载增加图片压缩功能 - #559

Merged
hect0x7 merged 4 commits into
masterfrom
dev
Aug 6, 2026
Merged

feat: Actions 下载增加图片压缩功能#559
hect0x7 merged 4 commits into
masterfrom
dev

Conversation

@hect0x7

@hect0x7 hect0x7 commented Aug 5, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features
    • Added configurable image compression for downloads.
    • Workflow runs accept an optional image-quality setting from 1–100, defaulting to maximum quality.
    • PNG and WEBP images can be converted to JPEG when configured.
    • Added compression summaries showing processed image counts and size savings.
  • Bug Fixes
    • Invalid image-quality values are rejected with a clear error.
    • Animated WEBP files are preserved when JPEG conversion is enabled.
    • Compressed images are retained only when they reduce file size, while preserving supported metadata.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9e921c13-7788-495a-b360-7856078d1ada

📥 Commits

Reviewing files that changed from the base of the PR and between 432e6be and b891995.

📒 Files selected for processing (1)
  • tests/test_jmcomic/test_workflow_download.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/test_jmcomic/test_workflow_download.py

📝 Walkthrough

Walkthrough

The workflow adds an IMAGE_QUALITY input and passes it to the crawler. The crawler validates the value, optionally compresses downloaded images, records compression statistics, and logs a post-download summary. PNG and WEBP images can be converted to JPEG.

Changes

Image compression workflow

Layer / File(s) Summary
Quality input and configuration
.github/workflows/download_dispatch.yml, usage/workflow_download.py
The workflow accepts IMAGE_QUALITY, defaults it to 100, and passes it to the crawler. The crawler validates values from 1–100, derives JPEG conversion from PDF_OPTION, and enables compression and summary plugins below 100.
Image compression execution
usage/workflow_download.py
The compression plugin processes supported images through temporary files, preserves metadata, handles transparency and multi-frame formats, records per-image statistics, and updates image.save_path when conversion changes the extension.
Compression statistics and validation
usage/workflow_download.py, tests/test_jmcomic/test_workflow_download.py
Thread-safe statistics track image counts and original/final sizes. The summary plugin logs aggregate metrics after downloads. Tests cover concurrent updates, log output, and animated WebP preservation.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant WorkflowDispatch
  participant CrawlerJob
  participant WorkflowImageCompressPlugin
  participant compress_image_in_place
  participant WorkflowCompressionStats
  participant WorkflowImageCompressSummaryPlugin
  WorkflowDispatch->>CrawlerJob: pass IMAGE_QUALITY
  CrawlerJob->>WorkflowImageCompressPlugin: process downloaded image
  WorkflowImageCompressPlugin->>compress_image_in_place: compress image
  compress_image_in_place-->>WorkflowImageCompressPlugin: return output format and sizes
  WorkflowImageCompressPlugin->>WorkflowCompressionStats: record compression statistics
  CrawlerJob->>WorkflowImageCompressSummaryPlugin: report after downloads
  WorkflowImageCompressSummaryPlugin->>WorkflowCompressionStats: read aggregate snapshot
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding image compression to Actions downloads.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev

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

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@usage/workflow_download.py`:
- Around line 92-93: Update the action assignment in the result-handling flow to
replace the ambiguous fullwidth comma in the Chinese message with an ASCII
comma, resolving Ruff RUF001 without changing the surrounding compression
behavior.
- Around line 47-70: The compress_image_in_place function must not truncate
multi-frame images. Before image.save, detect when getattr(image, 'n_frames', 1)
is greater than 1 and skip compression for those files, preserving the existing
single-frame compression behavior.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: baf93ef3-ac3e-4575-8c70-5d3087e3d1ed

📥 Commits

Reviewing files that changed from the base of the PR and between c17b5d1 and f36e921.

📒 Files selected for processing (2)
  • .github/workflows/download_dispatch.yml
  • usage/workflow_download.py

Comment thread usage/workflow_download.py Outdated
Comment thread usage/workflow_download.py Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@usage/workflow_download.py`:
- Around line 91-93: Update the conversion flow around os.replace in
WorkflowImageCompressPlugin so download_success_dict’s stored (path, image)
tuple uses the new target_path whenever conversion changes the path, or defer
recording until after after_image plugins complete. Ensure after_zip receives
the converted path and does not delete it before reading the archive.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 4cd1def0-0d88-4cc3-b2d5-c1e8ad4dabc1

📥 Commits

Reviewing files that changed from the base of the PR and between f36e921 and 412826b.

📒 Files selected for processing (2)
  • .github/workflows/download_dispatch.yml
  • usage/workflow_download.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/download_dispatch.yml

Comment thread usage/workflow_download.py

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
tests/test_jmcomic/test_workflow_download.py (1)

52-74: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Test a successful single-frame conversion.

The direct image test only covers the multi-frame skip path. Add a test that creates a single-frame PNG or WebP, enables convert_to_jpeg, and verifies the JPEG format, new path, and removal of the original file.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_jmcomic/test_workflow_download.py` around lines 52 - 74, Add a
test alongside test_multi_frame_webp_is_preserved that creates a single-frame
PNG or WebP, calls compress_image_in_place with convert_to_jpeg enabled, and
verifies successful conversion by checking the JPEG result/format, returned new
path, and deletion of the original image.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/test_jmcomic/test_workflow_download.py`:
- Around line 52-74: Add a test alongside test_multi_frame_webp_is_preserved
that creates a single-frame PNG or WebP, calls compress_image_in_place with
convert_to_jpeg enabled, and verifies successful conversion by checking the JPEG
result/format, returned new path, and deletion of the original image.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 4d53a773-b36a-4ad3-b574-ad06d398c962

📥 Commits

Reviewing files that changed from the base of the PR and between 412826b and 432e6be.

📒 Files selected for processing (2)
  • tests/test_jmcomic/test_workflow_download.py
  • usage/workflow_download.py

@hect0x7
hect0x7 merged commit e3c7e40 into master Aug 6, 2026
5 checks passed
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