From 49cf2a5506707e6288d65643a3f3de39f0704a72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Thu, 4 May 2023 17:39:05 +0200 Subject: [PATCH] feat(cli): insert entities for files with =, urls --- cli/src/main.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cli/src/main.rs b/cli/src/main.rs index faccf13..6a33597 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -10,6 +10,7 @@ use rand::{thread_rng, Rng}; use reqwest::Url; use serde_json::json; use std::net::SocketAddr; +use std::path::Path; use std::path::PathBuf; use std::sync::Arc; use tracing::trace; @@ -204,6 +205,19 @@ fn main() -> Result<()> { return Err(anyhow!("Invalid entry value.")); } + let entity = match entity { + entity if entity.starts_with('=') => { + let filepath = Path::new(&entity[1..]); + debug!("Hashing {:?}...", filepath); + let fbuffer = FileBuffer::open(&filepath)?; + let digest = hash(&fbuffer); + trace!("Finished hashing {:?}...", &filepath); + Address::Hash(digest).to_string() + } + entity if entity.starts_with("http") => Address::Url(entity).to_string(), + _ => entity, + }; + let body = json!({ "entity": entity, "attribute": attribute,