Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check image size limit #251

Merged
merged 4 commits into from
Jan 15, 2025
Merged

fix: check image size limit #251

merged 4 commits into from
Jan 15, 2025

Conversation

ALPAC-4
Copy link
Collaborator

@ALPAC-4 ALPAC-4 commented Jan 15, 2025

On _api/src/optimizeImages.ts, there is a image size limit. So add image size validation

Summary by CodeRabbit

  • New Features
    • Enhanced image validation with size checks for SVG and other image file types.
    • Increased size limit for SVG files from 10 KB to 20 KB, allowing for larger SVG retention after optimization.
    • Added size limit enforcement for image files (20 KB for SVG, 100 KB for other images).

Copy link

coderabbitai bot commented Jan 15, 2025

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (2)
  • testnets/civitia/images/civitia.svg is excluded by !**/*.svg
  • testnets/milkyway/images/milkINIT.png is excluded by !**/*.png

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The pull request introduces a new boolean parameter isImage to the validateRawGithubContent function in the GitHub workflow utility script, allowing for image size validation. The function now checks the file size of images, with specific limits set at 20 KB for SVG files and 100 KB for other image types. Additionally, all calls to validateRawGithubContent for image and logo URIs in the checkChains function have been updated to include this new parameter, ensuring consistent application of the image size validation.

Changes

File Change Summary
.github/workflows/utility/validate_data.py - Added isImage parameter to validateRawGithubContent function
- Implemented image size validation logic for SVG (20 KB) and other images (100 KB)
- Updated checkChains function calls to include True for image URIs
_api/src/optimizeImages.ts - Updated SVG_SIZE_LIMIT constant from 10 KB to 20 KB, altering conditions for deleting oversized SVG files

Possibly related PRs

Poem

🐰 Validation Hop! 🖼️
A rabbit's eye on images so bright,
Checking sizes with pixel-perfect might.
Twenty kilobytes for SVGs, crisp and clean,
Hundred for others, keeping the dream.
Workflow magic, byte by byte!


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
.github/workflows/utility/validate_data.py (2)

84-84: Add type hint for the isImage parameter.

For consistency and better type safety, add a type hint for the new parameter.

-def validateRawGithubContent(uri: str, isImage: bool):
+def validateRawGithubContent(uri: str, isImage: bool) -> None:

92-92: Fix typo in comment.

Correct the spelling of "image" in the comment.

-  # check imgae size
+  # check image size
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8e6e8fe and 7395615.

📒 Files selected for processing (1)
  • .github/workflows/utility/validate_data.py (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Cloudflare Pages: registry-initiation-1
🔇 Additional comments (2)
.github/workflows/utility/validate_data.py (2)

45-45: LGTM! Consistent updates to image validation calls.

All image-related function calls have been correctly updated to include the new isImage parameter, ensuring consistent size validation for both chain and asset images.

Also applies to: 47-47, 50-50, 52-52, 69-69, 71-71, 75-75, 77-77


84-98: Verify image size limits match frontend requirements.

The implemented size limits (10KB for SVG, 100KB for other images) should be verified against the limits defined in _api/src/optimizeImages.ts as mentioned in the PR description.

✅ Verification successful

Size limits are correctly synchronized

The image size limits in validate_data.py perfectly match those defined in _api/src/optimizeImages.ts:

  • SVG files: 10KB (10 * 1024 bytes)
  • PNG/other images: 100KB (100 * 1024 bytes)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for image size limits in the frontend code
rg -i "size.*limit|maxSize" _api/src/optimizeImages.ts

Length of output: 283

.github/workflows/utility/validate_data.py Outdated Show resolved Hide resolved
Copy link

cloudflare-workers-and-pages bot commented Jan 15, 2025

Deploying registry-initiation-1 with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6b4fcd4
Status: ✅  Deploy successful!
Preview URL: https://b5072d5b.registry-initiation-1.pages.dev
Branch Preview URL: https://feat-image-size-validation.registry-initiation-1.pages.dev

View logs

Copy link

cloudflare-workers-and-pages bot commented Jan 15, 2025

Deploying registry-testnet with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6b4fcd4
Status: ✅  Deploy successful!
Preview URL: https://a0cc40ee.initia-registry-testnets.pages.dev
Branch Preview URL: https://feat-image-size-validation.initia-registry-testnets.pages.dev

View logs

Copy link

cloudflare-workers-and-pages bot commented Jan 15, 2025

Deploying registry-devnet with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6b4fcd4
Status: ✅  Deploy successful!
Preview URL: https://131fcf53.registry-devnet.pages.dev
Branch Preview URL: https://feat-image-size-validation.registry-devnet.pages.dev

View logs

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
.github/workflows/utility/validate_data.py (1)

92-98: 🛠️ Refactor suggestion

Enhance image size validation implementation.

The current implementation needs several improvements:

  1. Extract magic numbers into named constants
  2. Add file extension validation
  3. Include path normalization
  4. Enhance error message with actual and limit sizes

Previous review suggestions for these improvements are still valid and should be implemented.

🧹 Nitpick comments (1)
.github/workflows/utility/validate_data.py (1)

84-84: Consider making isImage parameter optional with a default value.

The new isImage parameter could have a default value of False to maintain backward compatibility with any existing calls.

-def validateRawGithubContent(uri: str, isImage: bool):
+def validateRawGithubContent(uri: str, isImage: bool = False):
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7395615 and 67cbd7f.

📒 Files selected for processing (2)
  • .github/workflows/utility/validate_data.py (2 hunks)
  • _api/src/optimizeImages.ts (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: PR Workflow
.github/workflows/utility/validate_data.py

[error] 71-71: Pipeline execution failed during chain validation

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Cloudflare Pages: registry-initiation-1
🔇 Additional comments (2)
_api/src/optimizeImages.ts (1)

10-10: Verify SVG size limit consistency across files.

The SVG size limit has been increased from 10KB to 20KB. This change must be synchronized with the validation logic in validate_data.py to maintain consistent size checks.

Run this script to verify size limit consistency:

.github/workflows/utility/validate_data.py (1)

71-71: ⚠️ Potential issue

Investigate chain validation pipeline failure.

The pipeline failed during chain validation at this line. This could be due to:

  1. An oversized SVG file
  2. A missing file
  3. An invalid file path

Run this script to investigate the failure:

🧰 Tools
🪛 GitHub Actions: PR Workflow

[error] 71-71: Pipeline execution failed during chain validation

@ALPAC-4 ALPAC-4 merged commit 431e72a into main Jan 15, 2025
11 checks passed
@ALPAC-4 ALPAC-4 deleted the feat/image-size-validation branch January 15, 2025 07:22
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.

2 participants