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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions .github/workflows/utility/validate_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ def checkChains():
if "images" in asset:
for image in asset["images"]:
if "png" in image:
validateRawGithubContent(image["png"])
validateRawGithubContent(image["png"], True)
if "svg" in image:
validateRawGithubContent(image["svg"])
validateRawGithubContent(image["svg"], True)
if "logo_URIs" in asset:
if "png" in asset["logo_URIs"]:
validateRawGithubContent(asset["logo_URIs"]["png"])
validateRawGithubContent(asset["logo_URIs"]["png"], True)
if "svg" in asset["logo_URIs"]:
validateRawGithubContent(asset["logo_URIs"]["svg"])
validateRawGithubContent(asset["logo_URIs"]["svg"], True)

if "base" in asset and "traces" in asset:
validateTraces(asset["traces"], asset["base"])
Expand All @@ -66,29 +66,36 @@ def checkChains():
if "images" in chainSchema:
for image in chainSchema["images"]:
if "png" in image:
validateRawGithubContent(image["png"])
validateRawGithubContent(image["png"], True)
if "svg" in image:
validateRawGithubContent(image["svg"])
validateRawGithubContent(image["svg"], True)

if "logo_URIs" in chainSchema:
if "png" in chainSchema["logo_URIs"]:
validateRawGithubContent(chainSchema["logo_URIs"]["png"])
validateRawGithubContent(chainSchema["logo_URIs"]["png"], True)
if "svg" in chainSchema["logo_URIs"]:
validateRawGithubContent(chainSchema["logo_URIs"]["svg"])
validateRawGithubContent(chainSchema["logo_URIs"]["svg"], True)



print("Done")

# check the file exists
def validateRawGithubContent(uri: str):
def validateRawGithubContent(uri: str, isImage: bool):
prefix = "https://raw.githubusercontent.com/initia-labs/initia-registry/main/"
# check only if initia-registry main branch
if not uri.startswith(prefix):
return
path = uri[len(prefix):]
if not os.path.exists(path):
raise Exception("file(" + path + ") doesn't exists")
# check imgae size
if isImage:
sizeLimit = 20 * 1024 if uri.endswith('.svg') else 100 * 1024
size = os.path.getsize(path)
if size > sizeLimit:
raise Exception("image(" + path + ") size exceeds limit")


# check trace
def validateTraces(traces, denom: str):
Expand Down
2 changes: 1 addition & 1 deletion _api/src/optimizeImages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { optimize } from "svgo"
import { getFilePathsInDirectory, getFileSize, isDirectory } from "./utils"

// Constants for image size limits
const SVG_SIZE_LIMIT = 10 * 1024 // 10KB
const SVG_SIZE_LIMIT = 20 * 1024 // 20KB
const PNG_SIZE_LIMIT = 100 * 1024 // 100KB
const PNG_MAX_HEIGHT = 256 // 256px

Expand Down
10 changes: 5 additions & 5 deletions testnets/civitia/images/civitia.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified testnets/milkyway/images/milkINIT.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading