diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2021-12-06 14:24:16 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2021-12-06 16:18:25 +0100 |
commit | e72bcd96663f67c0bf4378cd9bbc47d6358aae8f (patch) | |
tree | b5184286a5d0a8274ff31ccae2e6ad131358b2dd /src | |
parent | ec995f8d670339819180920d9d315e9a3d349d64 (diff) |
Rewrite Client::get_content_text() to meet requirements
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src')
-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) } } |