From 27069656be40081303b7e3888b37b5c23231c5df Mon Sep 17 00:00:00 2001 From: Julius Michaelis Date: Thu, 9 Jul 2020 17:33:12 +0900 Subject: add ipfs files chcid --- ipfs-api/src/client/internal.rs | 24 ++++++++++++++++++++++++ ipfs-api/src/request/files.rs | 16 ++++++++++++++++ ipfs-api/src/response/files.rs | 2 ++ 3 files changed, 42 insertions(+) diff --git a/ipfs-api/src/client/internal.rs b/ipfs-api/src/client/internal.rs index ef4e9f2..6c646cc 100644 --- a/ipfs-api/src/client/internal.rs +++ b/ipfs-api/src/client/internal.rs @@ -1257,6 +1257,30 @@ impl IpfsClient { .await } + /// Change the cid version or hash function of the root node of a given path. + /// + /// ```no_run + /// use ipfs_api::IpfsClient; + /// use std::fs::File; + /// + /// let client = IpfsClient::default(); + /// let res = client.files_chcid("/test/", 1, Some("sha3-512")); + /// ``` + /// + /// Not specifying a byte `count` writes the entire input. + /// + #[inline] + pub async fn files_chcid( + &self, + path: &str, + cid_version: i32, + hash: Option<&str>, + ) -> Result + { + self.request_empty(request::FilesChcid { path, cid_version, hash }, None) + .await + } + /// List blocks that are both in the filestore and standard block storage. /// /// ```no_run diff --git a/ipfs-api/src/request/files.rs b/ipfs-api/src/request/files.rs index 564bd6c..6525a11 100644 --- a/ipfs-api/src/request/files.rs +++ b/ipfs-api/src/request/files.rs @@ -124,3 +124,19 @@ pub struct FilesWrite<'a> { impl<'a> ApiRequest for FilesWrite<'a> { const PATH: &'static str = "/files/write"; } + +#[derive(Serialize)] +pub struct FilesChcid<'a> { + #[serde(rename = "arg")] + pub path: &'a str, + + #[serde(skip_serializing_if = "Option::is_none")] + pub hash: Option<&'a str>, + + #[serde(rename = "cid-version")] + pub cid_version: i32, +} + +impl<'a> ApiRequest for FilesChcid<'a> { + const PATH: &'static str = "/files/chcid"; +} diff --git a/ipfs-api/src/response/files.rs b/ipfs-api/src/response/files.rs index 069ba32..76dc4a1 100644 --- a/ipfs-api/src/response/files.rs +++ b/ipfs-api/src/response/files.rs @@ -54,6 +54,8 @@ pub struct FilesStatResponse { pub type FilesWriteResponse = (); +pub type FilesChcidResponse = (); + #[cfg(test)] mod tests { deserialize_test!(v0_files_ls_0, FilesLsResponse); -- cgit v1.2.3