summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFerris Tseng <ferristseng@fastmail.fm>2017-11-26 16:16:23 -0500
committerFerris Tseng <ferristseng@fastmail.fm>2017-11-26 16:16:23 -0500
commit1b8dfb4097998e7b76355a0ee07cbaf9f7ea7193 (patch)
tree929b2759872244e25a9009510ec2f6d6a50cd686
parenta84e726ab0a3e70accbb84afed65ad584af67b0d (diff)
add filestore calls
-rw-r--r--ipfs-api/src/client.rs14
-rw-r--r--ipfs-api/src/request/filestore.rs20
-rw-r--r--ipfs-api/src/response/filestore.rs16
-rw-r--r--ipfs-cli/src/command/filestore.rs83
-rw-r--r--ipfs-cli/src/command/mod.rs1
-rw-r--r--ipfs-cli/src/main.rs2
6 files changed, 113 insertions, 23 deletions
diff --git a/ipfs-api/src/client.rs b/ipfs-api/src/client.rs
index 8a928ce..4de71ff 100644
--- a/ipfs-api/src/client.rs
+++ b/ipfs-api/src/client.rs
@@ -699,15 +699,21 @@ impl IpfsClient {
/// List objects in filestore.
///
#[inline]
- pub fn filestore_ls(&self) -> AsyncStreamResponse<response::FilestoreLsResponse> {
- self.request_stream(&request::FilestoreLs, None)
+ pub fn filestore_ls(
+ &self,
+ cid: &Option<&str>,
+ ) -> AsyncStreamResponse<response::FilestoreLsResponse> {
+ self.request_stream(&request::FilestoreLs { cid }, None)
}
/// Verify objects in filestore.
///
#[inline]
- pub fn filestore_verify(&self) -> AsyncStreamResponse<response::FilestoreVerifyResponse> {
- self.request_stream(&request::FilestoreVerify, None)
+ pub fn filestore_verify(
+ &self,
+ cid: &Option<&str>,
+ ) -> AsyncStreamResponse<response::FilestoreVerifyResponse> {
+ self.request_stream(&request::FilestoreVerify { cid }, None)
}
/// Download Ipfs object.
diff --git a/ipfs-api/src/request/filestore.rs b/ipfs-api/src/request/filestore.rs
index 8e9fa58..93554f9 100644
--- a/ipfs-api/src/request/filestore.rs
+++ b/ipfs-api/src/request/filestore.rs
@@ -21,11 +21,13 @@ impl ApiRequest for FilestoreDups {
}
-pub struct FilestoreLs;
-
-impl_skip_serialize!(FilestoreLs);
+#[derive(Serialize)]
+pub struct FilestoreLs<'a> {
+ #[serde(rename = "arg")]
+ pub cid: &'a Option<&'a str>,
+}
-impl ApiRequest for FilestoreLs {
+impl<'a> ApiRequest for FilestoreLs<'a> {
#[inline]
fn path() -> &'static str {
"/filestore/ls"
@@ -33,11 +35,13 @@ impl ApiRequest for FilestoreLs {
}
-pub struct FilestoreVerify;
-
-impl_skip_serialize!(FilestoreVerify);
+#[derive(Serialize)]
+pub struct FilestoreVerify<'a> {
+ #[serde(rename = "arg")]
+ pub cid: &'a Option<&'a str>,
+}
-impl ApiRequest for FilestoreVerify {
+impl<'a> ApiRequest for FilestoreVerify<'a> {
#[inline]
fn path() -> &'static str {
"/filestore/verify"
diff --git a/ipfs-api/src/response/filestore.rs b/ipfs-api/src/response/filestore.rs
index 06bf455..f2f62e5 100644
--- a/ipfs-api/src/response/filestore.rs
+++ b/ipfs-api/src/response/filestore.rs
@@ -18,7 +18,7 @@ pub struct FilestoreDupsResponse {
#[derive(Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
-pub struct FilestoreLsResponse {
+pub struct FilestoreObject {
pub status: i32,
pub error_msg: String,
pub key: String,
@@ -28,13 +28,7 @@ pub struct FilestoreLsResponse {
}
-#[derive(Debug, Deserialize)]
-#[serde(rename_all = "PascalCase")]
-pub struct FilestoreVerifyResponse {
- pub status: i32,
- pub error_msg: String,
- pub key: String,
- pub file_path: String,
- pub offset: u64,
- pub size: u64,
-}
+pub type FilestoreLsResponse = FilestoreObject;
+
+
+pub type FilestoreVerifyResponse = FilestoreObject;
diff --git a/ipfs-cli/src/command/filestore.rs b/ipfs-cli/src/command/filestore.rs
new file mode 100644
index 0000000..b24da2c
--- /dev/null
+++ b/ipfs-cli/src/command/filestore.rs
@@ -0,0 +1,83 @@
+// Copyright 2017 rust-ipfs-api Developers
+//
+// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
+// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
+// http://opensource.org/licenses/MIT>, at your option. This file may not be
+// copied, modified, or distributed except according to those terms.
+//
+
+use clap::{App, ArgMatches};
+use command::EXPECTED_API;
+use futures::stream::Stream;
+use ipfs_api::{response, IpfsClient};
+use tokio_core::reactor::Core;
+
+
+pub fn signature<'a, 'b>() -> App<'a, 'b> {
+ clap_app!(
+ @subcommand filestore =>
+ (@setting SubcommandRequiredElseHelp)
+ (@subcommand dups =>
+ (about: "List blocks that are both in the filestore and standard block storage")
+ )
+ (@subcommand ls =>
+ (about: "List objects in the filestore")
+ (@arg CID: "Cid of the object to list")
+ )
+ (@subcommand verify =>
+ (about: "Verify objects in the filestore")
+ (@arg CID: "Cid of the object to verify")
+ )
+ )
+}
+
+
+fn print_filestore_object<E>(obj: response::FilestoreObject) -> Result<(), E> {
+ println!(" status : {}", obj.status);
+ println!(" error_msg : {}", obj.error_msg);
+ println!(" key : {}", obj.key);
+ println!(" file_path : {}", obj.file_path);
+ println!(" offset : {}", obj.offset);
+ println!(" size : {}", obj.size);
+ println!("");
+
+ Ok(())
+}
+
+
+pub fn handle(core: &mut Core, client: &IpfsClient, args: &ArgMatches) {
+ match args.subcommand() {
+ ("dups", _) => {
+ let req = client.filestore_dups().for_each(|dup| {
+ println!(" ref : {}", dup.reference);
+ println!(" err : {}", dup.err);
+ println!("");
+
+ Ok(())
+ });
+
+ println!("");
+ core.run(req).expect(EXPECTED_API);
+ println!("");
+ }
+ ("ls", Some(args)) => {
+ let cid = args.value_of("CID");
+ let req = client.filestore_ls(&cid).for_each(print_filestore_object);
+
+ println!("");
+ core.run(req).expect(EXPECTED_API);
+ println!("");
+ }
+ ("verify", Some(args)) => {
+ let cid = args.value_of("CID");
+ let req = client.filestore_verify(&cid).for_each(
+ print_filestore_object,
+ );
+
+ println!("");
+ core.run(req).expect(EXPECTED_API);
+ println!("");
+ }
+ _ => unreachable!(),
+ }
+}
diff --git a/ipfs-cli/src/command/mod.rs b/ipfs-cli/src/command/mod.rs
index a14adf1..b260902 100644
--- a/ipfs-cli/src/command/mod.rs
+++ b/ipfs-cli/src/command/mod.rs
@@ -38,4 +38,5 @@ pub mod diag;
pub mod dns;
pub mod file;
pub mod files;
+pub mod filestore;
pub mod version;
diff --git a/ipfs-cli/src/main.rs b/ipfs-cli/src/main.rs
index 8eb18dc..e373910 100644
--- a/ipfs-cli/src/main.rs
+++ b/ipfs-cli/src/main.rs
@@ -38,6 +38,7 @@ fn main() {
(subcommand: command::dns::signature())
(subcommand: command::file::signature())
(subcommand: command::files::signature())
+ (subcommand: command::filestore::signature())
(subcommand: command::version::signature())
).get_matches();
@@ -58,6 +59,7 @@ fn main() {
("dns", Some(args)) => command::dns::handle(&mut core, &client, &args),
("file", Some(args)) => command::file::handle(&mut core, &client, &args),
("files", Some(args)) => command::files::handle(&mut core, &client, &args),
+ ("filestore", Some(args)) => command::filestore::handle(&mut core, &client, &args),
("version", _) => command::version::handle(&mut core, &client),
_ => unreachable!(),
}