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

feat(torii-erc): add avif support #3011

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
13 changes: 7 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest-4-cores
needs: [fmt, cairofmt]
container:
image: ghcr.io/dojoengine/dojo-dev:v1.1.1
image: ghcr.io/dojoengine/dojo-dev:dav1d
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
Expand All @@ -34,7 +34,7 @@ jobs:
needs: ensure-docker
runs-on: ubuntu-latest-32-cores
container:
image: ghcr.io/dojoengine/dojo-dev:v1.1.1
image: ghcr.io/dojoengine/dojo-dev:dav1d
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
Expand All @@ -60,7 +60,7 @@ jobs:
runs-on: ubuntu-latest
needs: [fmt, cairofmt]
container:
image: ghcr.io/dojoengine/dojo-dev:v1.1.1
image: ghcr.io/dojoengine/dojo-dev:dav1d
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
Expand All @@ -86,6 +86,7 @@ jobs:
uses: ilammy/setup-nasm@v1
with:
version: "2.15.05"
- run: vcpkg install dav1d
- run: cargo build --target x86_64-pc-windows-msvc --bins

# This job is used to ensure the built katana image doesn't depend on any
Expand Down Expand Up @@ -164,7 +165,7 @@ jobs:
runs-on: ubuntu-latest-4-cores
needs: [fmt, cairofmt]
container:
image: ghcr.io/dojoengine/dojo-dev:v1.1.1
image: ghcr.io/dojoengine/dojo-dev:dav1d
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
Expand All @@ -173,7 +174,7 @@ jobs:
fmt:
runs-on: ubuntu-latest
container:
image: ghcr.io/dojoengine/dojo-dev:v1.1.1
image: ghcr.io/dojoengine/dojo-dev:dav1d
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
Expand All @@ -183,7 +184,7 @@ jobs:
runs-on: ubuntu-latest
needs: [fmt, cairofmt]
container:
image: ghcr.io/dojoengine/dojo-dev:v1.1.1
image: ghcr.io/dojoengine/dojo-dev:dav1d
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ jobs:
# See: https://github.com/jemalloc/jemalloc/issues/467
echo "JEMALLOC_SYS_WITH_LG_PAGE=16" >> $GITHUB_ENV

- name: Windows setup
if: ${{ matrix.job.target == 'x86_64-pc-windows-msvc' }}
run: |
vcpkg install dav1d

- name: Build binaries
run: cargo build --release --bins --target ${{ matrix.job.target }}

Expand Down
80 changes: 80 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ hashlink = "0.9.1"
hex = "0.4.3"
hex-literal = "0.4.1"
http = "0.2.9"
image = "0.25.2"
image = { version = "0.25.2", features = [ "avif-native" ] }
indexmap = "2.2.5"
indoc = "1.0.7"
itertools = "0.12.1"
Expand Down
9 changes: 3 additions & 6 deletions crates/torii/graphql/src/object/erc/erc_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,8 @@ impl ResolvableObject for TokenObject {
v.to_string().trim_matches('"').to_string()
});

let contract_address: String =
row.get("contract_address");
let image_path = format!("{}/image", contract_address);
let image_path =
format!("{}/image", id.replace(":", "/"));

(
metadata_str,
Expand Down Expand Up @@ -501,9 +500,7 @@ fn create_token_metadata_from_row(row: &SqliteRow) -> sqlx::Result<ErcTokenType>
let metadata_attributes =
metadata.get("attributes").map(|v| v.to_string().trim_matches('"').to_string());

let contract_address: String = row.get("contract_address");
let image_path = format!("{}/image", contract_address);

let image_path = format!("{}/image", id.replace(":", "/"));
(metadata_str, metadata_name, metadata_description, metadata_attributes, image_path)
};

Expand Down
25 changes: 7 additions & 18 deletions crates/torii/server/src/artifacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ use camino::Utf8PathBuf;
use data_url::mime::Mime;
use data_url::DataUrl;
use image::{DynamicImage, ImageFormat};
use reqwest::Client;
use serde::{Deserialize, Serialize};
use sqlx::{Pool, Sqlite};
use tokio::fs;
use tokio::fs::File;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::sync::broadcast::Receiver;
use torii_sqlite::constants::TOKENS_TABLE;
use torii_sqlite::utils::fetch_content_from_ipfs;
use torii_sqlite::utils::{fetch_content_from_http, fetch_content_from_ipfs};
use tracing::{debug, error, trace};
use warp::http::Response;
use warp::path::Tail;
Expand Down Expand Up @@ -59,10 +58,7 @@ async fn serve_static_file(

let token_id = format!("{}:{}", parts[0], parts[1]);
if !token_image_dir.exists() {
match fetch_and_process_image(&artifacts_dir, &token_id, pool)
.await
.context(format!("Failed to fetch and process image for token_id: {}", token_id))
{
match fetch_and_process_image(&artifacts_dir, &token_id, pool).await {
Ok(path) => path,
Err(e) => {
error!(error = %e, "Failed to fetch and process image for token_id: {}", token_id);
Expand Down Expand Up @@ -177,15 +173,8 @@ async fn fetch_and_process_image(
uri if uri.starts_with("http") || uri.starts_with("https") => {
debug!(image_uri = %uri, "Fetching image from http/https URL");
// Fetch image from HTTP/HTTPS URL
let client = Client::new();
let response = client
.get(uri)
.send()
.await
.context("Failed to fetch image from URL")?
.bytes()
.await
.context("Failed to read image bytes from response")?;
let response =
fetch_content_from_http(&uri).await.context("Failed to fetch image from URL")?;

// svg files typically start with <svg or <?xml
if response.starts_with(b"<svg") || response.starts_with(b"<?xml") {
Expand All @@ -195,7 +184,7 @@ async fn fetch_and_process_image(
format!("Unknown file format for token_id: {}, data: {:?}", token_id, &response)
})?;
ErcImageType::DynamicImage((
image::load_from_memory(&response)
image::load_from_memory_with_format(&response, format)
.context("Failed to load image from bytes")?,
format,
))
Expand All @@ -218,7 +207,7 @@ async fn fetch_and_process_image(
)
})?;
ErcImageType::DynamicImage((
image::load_from_memory(&response)
image::load_from_memory_with_format(&response, format)
.context("Failed to load image from bytes")?,
format,
))
Expand All @@ -239,7 +228,7 @@ async fn fetch_and_process_image(
let format = image::guess_format(&decoded.0)
.with_context(|| format!("Unknown file format for token_id: {}", token_id))?;
ErcImageType::DynamicImage((
image::load_from_memory(&decoded.0)
image::load_from_memory_with_format(&decoded.0, format)
.context("Failed to load image from bytes")?,
format,
))
Expand Down
2 changes: 1 addition & 1 deletion crates/torii/sqlite/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ pub const TOKEN_TRANSFER_TABLE: &str = "token_transfers";
pub const TOKENS_TABLE: &str = "tokens";
pub const WORLD_CONTRACT_TYPE: &str = "WORLD";
pub const SQL_FELT_DELIMITER: &str = "/";
pub const REQ_MAX_RETRIES: u8 = 3;

pub const IPFS_URL: &str = "https://ipfs.io/ipfs/";
pub const IPFS_CLIENT_MAX_RETRY: u8 = 3;

pub const IPFS_CLIENT_URL: &str = "https://ipfs.infura.io:5001";
pub const IPFS_CLIENT_USERNAME: &str = "2EBrzr7ZASQZKH32sl2xWauXPSA";
Expand Down
Loading
Loading