Skip to content

Commit 64ee27f

Browse files
authored
Merge pull request #38 from graphprotocol/tmigone/ipfs-url
2 parents 1800a22 + 40b7ac1 commit 64ee27f

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

availability-oracle/src/ipfs.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,11 @@ impl IpfsImpl {
4848
}
4949
}
5050

51-
async fn call(&self, route: &'static str, arg: Cid) -> Result<reqwest::Response, IpfsError> {
51+
async fn call(&self, cid: Cid) -> Result<reqwest::Response, IpfsError> {
5252
let _permit = self.semaphore.acquire().await;
5353

54-
// URL security: We control the endpoint and the route, the `arg` is a CID.
55-
let url = format!(
56-
"{}/api/v0/{}?arg={}",
57-
self.endpoint.trim_end_matches('/'),
58-
route,
59-
arg
60-
);
54+
// Using standard IPFS gateway URL format
55+
let url = format!("{}/ipfs/{}", self.endpoint.trim_end_matches('/'), cid);
6156
self.client
6257
.get(&url)
6358
.timeout(self.timeout)
@@ -67,10 +62,10 @@ impl IpfsImpl {
6762
.and_then(|x| x)
6863
.map_err(|e| match e.status().map(|e| e.as_u16()) {
6964
Some(GATEWAY_TIMEOUT) | Some(CLOUDFLARE_TIMEOUT) => {
70-
IpfsError::GatewayTimeout(arg, e.into())
65+
IpfsError::GatewayTimeout(cid, e.into())
7166
}
72-
_ if e.is_timeout() => IpfsError::ClientTimeout(arg, e.into()),
73-
Some(NOT_FOUND) => IpfsError::NotFound(arg, e.into()),
67+
_ if e.is_timeout() => IpfsError::ClientTimeout(cid, e.into()),
68+
Some(NOT_FOUND) => IpfsError::NotFound(cid, e.into()),
7469
_ => IpfsError::Other(e.into()),
7570
})
7671
}
@@ -97,7 +92,7 @@ impl Ipfs for IpfsImpl {
9792
) -> Result<reqwest::Response, IpfsError> {
9893
let mut last_err = None;
9994
for _ in 0..=retries {
100-
match ipfs.call("cat", cid).await {
95+
match ipfs.call(cid).await {
10196
Ok(res) => return Ok(res),
10297
Err(e) => {
10398
last_err = Some(e);

0 commit comments

Comments
 (0)