Skip to content

Commit

Permalink
Merge pull request #62 from xiaods/ipfs
Browse files Browse the repository at this point in the history
fix #60  support transfer file to ipfs
  • Loading branch information
yanganto committed Feb 29, 2020
2 parents 22db86b + 944d0d7 commit 3104716
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ repository = "https://github.com/yanganto/s3rs"
edition = "2018"

[dependencies]
ipfs-api = "0.5.2"
dirs = "2.0"
openssl = { version = "0.10", features = ["vendored"] }
openssl-sys = { version = "0.9.49", features = ["vendored"] }
Expand All @@ -20,7 +21,7 @@ toml = "0.4"
serde = "1.0"
serde_derive = "1.0"
reqwest = "0.9"
hyper = "0.11"
hyper = "0.12"
http = "0.1"
chrono = "0.4"
rust-crypto = "0.2"
Expand Down
21 changes: 19 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ use std::io::stdout;
use std::io::{BufRead, BufReader, Read, Write};
use std::str;
use std::str::FromStr;
use hyper::rt::Future;
use ipfs_api::IpfsClient;
use std::io::Cursor;

static MY_LOGGER: MyLogger = MyLogger;
static S3_FORMAT: &'static str =
Expand Down Expand Up @@ -217,7 +220,7 @@ fn do_command(handler: &mut s3handler::Handler, s3_type: &String, command: &mut
// It is OK to let it works as POC with something hard coded, because the bounties is not large.
// Please take this easy.
// Transfer to IPFS can be a POC start from put file in tmp, then transfer
// } else if command.starts_with("transfer") {
} else if command.starts_with("transfer") {

// Keep this part comment, and you dont really need a S3 account to download something
// match handler.get(
Expand All @@ -231,7 +234,21 @@ fn do_command(handler: &mut s3handler::Handler, s3_type: &String, command: &mut

//
// // TODO: transfer file to IPFS
//


let client = IpfsClient::default();
let data = Cursor::new("Hello World!");

let req = client
.add(data)
.map(|res| {
println!("{}", res.hash);
})
.map_err(|e| eprintln!("{}", e));

hyper::rt::run(req);


// // TODO: print the Qm hex or 0x hex for the user
//
} else if command.starts_with("cat") {
Expand Down

0 comments on commit 3104716

Please sign in to comment.