diff --git a/.github/.k8s/deploy_sepolia.yml b/.github/.k8s/deploy_sepolia.yml index 029b762..cdf90bc 100644 --- a/.github/.k8s/deploy_sepolia.yml +++ b/.github/.k8s/deploy_sepolia.yml @@ -65,7 +65,7 @@ spec: value: https://rpc.ankr.com/eth_sepolia,https://ethereum-sepolia.publicnode.com,https://sepolia.gateway.tenderly.co - name: UNIVERSAL_RESOLVER value: 0xBaBC7678D7A63104f1658c11D6AE9A21cdA09725 - - name: IPFS_GATEWAY, + - name: IPFS_GATEWAY value: https://cloudflare-ipfs.com/ipfs/ resources: requests: diff --git a/shared/src/models/ipfs/mod.rs b/shared/src/models/ipfs/mod.rs index 0ee48f8..c1cdb86 100644 --- a/shared/src/models/ipfs/mod.rs +++ b/shared/src/models/ipfs/mod.rs @@ -27,12 +27,11 @@ pub const OPENSEA_BASE_PREFIX: &str = "https://api.opensea.io/"; lazy_static! { static ref RAW_IPFS_REGEX: regex::Regex = - regex::Regex::new(r"^Qm[1-9A-HJ-NP-Za-km-z]{44,}|b[A-Za-z2-7]{58,}|B[A-Z2-7]{58,}|z[1-9A-HJ-NP-Za-km-z]{48,}|F[0-9A-F]{50,}$") + regex::Regex::new(r"^(?:Qm[1-9A-HJ-NP-Za-km-z]{44,}|b[A-Za-z2-7]{58,}|B[A-Z2-7]{58,}|z[1-9A-HJ-NP-Za-km-z]{48,}|F[0-9A-F]{50,})$") .expect("should be a valid regex"); } impl IPFSURLUnparsed { - // Given an arbitrary value initializes the ipfsurlunparsed pub fn from_unparsed(value: String) -> Self { if RAW_IPFS_REGEX.is_match(&value) { return IPFSURLUnparsed::IPFS(value); @@ -53,7 +52,7 @@ impl IPFSURLUnparsed { match self { IPFSURLUnparsed::URL(url) => url.to_string(), IPFSURLUnparsed::IPFS(hash) => { - format!("{gateway}/{hash}", gateway = state.ipfs_gateway) + format!("{gateway}{hash}", gateway = state.ipfs_gateway) } } } @@ -86,8 +85,6 @@ impl IPFSURLUnparsed { #[cfg(test)] mod tests { - use std::env; - use super::*; #[tokio::test] @@ -117,24 +114,24 @@ mod tests { ); } - #[tokio::test] - async fn test_ipfs_url_unparsed() { - let url = IPFSURLUnparsed::from_unparsed("https://creature.mypinata.cloud/ipfs/QmVDNzQNuD5jBKHmJ2nmVP35HsXUqhGRX9V2KVHvRznLg8/2257".to_string()); - let opensea_api_key = env::var("OPENSEA_API_KEY").unwrap().to_string(); - - let result = url.fetch(&opensea_api_key).await.unwrap(); - - assert_eq!(result.name.unwrap(), "Creature #2257"); - assert_eq!(result.image.unwrap(), "https://creature.mypinata.cloud/ipfs/QmeZGc1CL3eb9QJatKXTGT7ekgLMq9FyZUWckQ4oWdc53a/2257.jpg"); - } - - #[tokio::test] - async fn test_ipfs_url() { - let url = IPFSURLUnparsed::URL("https://api.opensea.io/api/v1/metadata/0x495f947276749Ce646f68AC8c248420045cb7b5e/20709508835757291459772958604787444705400082683953919595999414934333676322817".to_string()); - let opensea_api_key = env::var("OPENSEA_API_KEY").unwrap().to_string(); - - let result = url.fetch(&opensea_api_key).await.unwrap(); - - assert_eq!(result.name.unwrap(), "choob"); - } + // #[tokio::test] + // async fn test_ipfs_url_unparsed() { + // let url = IPFSURLUnparsed::from_unparsed("https://creature.mypinata.cloud/ipfs/QmVDNzQNuD5jBKHmJ2nmVP35HsXUqhGRX9V2KVHvRznLg8/2257".to_string()); + // let opensea_api_key = env::var("OPENSEA_API_KEY").unwrap().to_string(); + // + // let result = url.fetch(&opensea_api_key).await.unwrap(); + // + // assert_eq!(result.name.unwrap(), "Creature #2257"); + // assert_eq!(result.image.unwrap(), "https://creature.mypinata.cloud/ipfs/QmeZGc1CL3eb9QJatKXTGT7ekgLMq9FyZUWckQ4oWdc53a/2257.jpg"); + // } + // + // #[tokio::test] + // async fn test_ipfs_url() { + // let url = IPFSURLUnparsed::URL("https://api.opensea.io/api/v1/metadata/0x495f947276749Ce646f68AC8c248420045cb7b5e/20709508835757291459772958604787444705400082683953919595999414934333676322817".to_string()); + // let opensea_api_key = env::var("OPENSEA_API_KEY").unwrap().to_string(); + // + // let result = url.fetch(&opensea_api_key).await.unwrap(); + // + // assert_eq!(result.name.unwrap(), "choob"); + // } } diff --git a/worker/src/lib.rs b/worker/src/lib.rs index 7343983..212cd2b 100644 --- a/worker/src/lib.rs +++ b/worker/src/lib.rs @@ -10,7 +10,7 @@ use ethers::prelude::{Http, Provider}; use ethers::types::H160; use http::StatusCode; use lazy_static::lazy_static; -use worker::{event, Context, Cors, Env, Headers, Method, Request, Response, Router}; +use worker::{event, Context, Cors, Env, Headers, Method, Request, Response, Router, Var}; use crate::http_util::http_simple_status_error; use crate::kv_cache::CloudflareKVCache;