diff options
-rw-r--r-- | src/client.rs | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/src/client.rs b/src/client.rs index 80faee0..68aa4cd 100644 --- a/src/client.rs +++ b/src/client.rs @@ -92,19 +92,18 @@ impl Client { } pub async fn get_content_text(&self, cid: Cid) -> Result<String> { - let starting_point = ipfs::path::IpfsPath::new(ipfs::path::PathRoot::Ipld(cid)); - - let bytes = self.ipfs - .cat_unixfs(starting_point, None) - .await - .context("cat unixfs")? - .try_concat() - .await - .context("concatenating")?; + struct S(String); + impl TryFrom<ipfs::Ipld> for S { + type Error = anyhow::Error; + fn try_from(ipld: ipfs::Ipld) -> Result<Self> { + match ipld { + ipfs::Ipld::String(s) => Ok(S(s)), + _ => anyhow::bail!("Not a string"), + } + } + } - String::from_utf8(bytes) - .context("parsing UTF8") - .map_err(anyhow::Error::from) + self.get::<S>(cid).await.map(|v| v.0) } } |