summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-10-21 14:25:25 +0200
committerMatthias Beyer <mail@beyermatthias.de>2018-10-21 14:54:29 +0200
commit2b6e3fb20f8069a1853873467a4c864997343603 (patch)
treef8e4eb7076eb4c6ba21989bc6b2bae5c16d02ee7
parentb87da505fae69294fbcb8efe405cfaa30d03ac6b (diff)
Implement publishing
-rw-r--r--src/cli_ui.rs19
-rw-r--r--src/main.rs33
-rw-r--r--src/repository/client.rs25
-rw-r--r--src/repository/mod.rs8
4 files changed, 69 insertions, 16 deletions
diff --git a/src/cli_ui.rs b/src/cli_ui.rs
index 994dc30..4a89285 100644
--- a/src/cli_ui.rs
+++ b/src/cli_ui.rs
@@ -410,6 +410,25 @@ pub fn build_ui<'a>() -> App<'a, 'a> {
)
)
+ .subcommand(SubCommand::with_name("publish")
+ .about("Publish a block as latest block")
+ .version("0.1.0")
+ .arg(Arg::with_name("profile_name")
+ .index(1)
+ .required(true)
+ .takes_value(true)
+ .multiple(false)
+ .help("Name of the Profile (IPFS Key)")
+ )
+ .arg(Arg::with_name("blockhash")
+ .index(2)
+ .required(true)
+ .takes_value(true)
+ .multiple(false)
+ .help("Block to publish")
+ )
+ )
+
}
diff --git a/src/main.rs b/src/main.rs
index ed2393f..c5776b9 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -821,6 +821,39 @@ fn main() {
});
},
+ ("publish", Some(mtch)) => {
+ use repository::ProfileName;
+
+ debug!("Calling: publish");
+ let (config, repo) = boot();
+ let repo = Arc::new(repo);
+ let publish_key_name = mtch
+ .value_of("profile_name")
+ .map(String::from)
+ .map(ProfileName::from)
+ .unwrap(); // safe by clap
+ let blockhash = mtch
+ .value_of("blockhash")
+ .map(String::from)
+ .map(IPFSHash::from)
+ .unwrap(); // safe by clap
+
+ let repo2 = repo.clone();
+
+ hyper::rt::run({
+ repo.clone()
+ .get_key_id_from_key_name(publish_key_name)
+ .and_then(move |publish_key_id| {
+ repo.announce_block(publish_key_id, &blockhash, None, None)
+ })
+ .map_err(|e| {
+ error!("Error running: {:?}", e);
+ print_error_details(e);
+ exit(1)
+ })
+ });
+ },
+
(other, _mtch) => {
error!("Unknown command: {}", other);
exit(1)
diff --git a/src/repository/client.rs b/src/repository/client.rs
index 6ddf3a8..103066c 100644
--- a/src/repository/client.rs
+++ b/src/repository/client.rs
@@ -147,18 +147,18 @@ pub fn resolve_content_profile(client: Arc<IpfsClient>, hash: &IPFSHash)
})
}
-pub fn announce_profile(client: Arc<IpfsClient>,
- key: ProfileKey,
- state: &IPFSHash,
- lifetime: Option<String>,
- ttl: Option<String>)
+pub fn announce_block(client: Arc<IpfsClient>,
+ key: ProfileKey,
+ state: &IPFSHash,
+ lifetime: Option<String>,
+ ttl: Option<String>)
-> impl Future<Item = (), Error = Error>
{
let name = format!("/ipfs/{}", state);
- resolve_content_profile(client.clone(), state)
+ resolve_block(client.clone(), state)
.and_then(move |_| {
- debug!("Publishing profile.");
+ debug!("Publishing block.");
client.name_publish(&name,
false,
lifetime.as_ref().map(String::deref),
@@ -169,6 +169,7 @@ pub fn announce_profile(client: Arc<IpfsClient>,
})
}
+
pub fn put_plain(client: Arc<IpfsClient>, data: Vec<u8>)
-> impl Future<Item = IPFSHash, Error = Error>
{
@@ -290,11 +291,11 @@ pub fn new_text_post(client: Arc<IpfsClient>,
put_block(client4, &block)
})
.and_then(move |block_hash| {
- announce_profile(client5,
- publish_key_id,
- &block_hash,
- None, // IPFS default
- None) // IPFS default
+ ::repository::client::announce_block(client5,
+ publish_key_id,
+ &block_hash,
+ None, // IPFS default
+ None) // IPFS default
})
}
diff --git a/src/repository/mod.rs b/src/repository/mod.rs
index fa782c9..84937ce 100644
--- a/src/repository/mod.rs
+++ b/src/repository/mod.rs
@@ -196,14 +196,14 @@ impl Repository {
"10m"
}
- /// Announce a profile as current
+ /// Announce a block as current
///
- /// Profile identified by IPFS hash.
+ /// Block identified by IPFS hash.
///
/// Lifetime and TTL are _not_ set to the default in the implementation of this function, but
/// the IPFS defaults apply (set by the IPFS daemon)
///
- pub fn announce_profile<'a>(&'a self,
+ pub fn announce_block<'a>(&'a self,
key: ProfileKey,
state: &IPFSHash,
lifetime: Option<String>,
@@ -212,7 +212,7 @@ impl Repository {
{
debug!("Announcing profile: key: {key:?}, state: {state:?}, lifetime: {lifetime:?}, ttl: {ttl:?}",
key = key, state = state, lifetime = lifetime, ttl = ttl);
- ::repository::client::announce_profile(self.client.clone(), key, state, lifetime, ttl)
+ ::repository::client::announce_block(self.client.clone(), key, state, lifetime, ttl)
}
pub fn new_profile<'a>(&'a self,