diff --git a/Cargo.lock b/Cargo.lock index 8a877a7..1ae3c80 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,6 +11,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "array_tool" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f8cb5d814eb646a863c4f24978cff2880c4be96ad8cde2c0f0678732902e271" + [[package]] name = "atty" version = "0.2.14" @@ -574,6 +580,7 @@ dependencies = [ name = "publicise-rs" version = "0.1.0" dependencies = [ + "array_tool", "dotenv", "env_logger", "log", diff --git a/Cargo.toml b/Cargo.toml index 0f72641..b015f68 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +array_tool = "1.0.3" dotenv = "0.15.0" env_logger = "0.8.4" log = "0.4.0" diff --git a/src/main.rs b/src/main.rs index 131eb0d..7509146 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,8 +5,11 @@ use log::{debug, error, info, log_enabled, warn}; use reqwest; #[allow(unused)] use std::io::{self, BufReader, Write}; +use std::collections::HashMap; #[allow(unused)] use yaserde_derive::{YaDeserialize, YaSerialize}; +#[allow(unused)] +use array_tool::vec::Shift; #[allow(unused)] fn publicise() {} @@ -83,11 +86,10 @@ pub struct Collection { collection: Option, } -async fn get_folder_contents( - password: String, - url_tail: &str, -) -> Result> { +async fn get_folder_contents(url_tail: &str) -> Result> { debug!("Entering: get_folder_contents()"); + let password = get_password().unwrap().trim().to_string(); + debug!("Received password: {}[END]", password); let root_url = "https://theadamcooper.com"; let method = reqwest::Method::from_bytes(b"PROPFIND").unwrap(); let client = reqwest::Client::new(); @@ -119,6 +121,53 @@ async fn get_folder_contents( Ok(response_text) } +fn traverse(queue: Vec) { + debug!("Entering: traverse()"); + // Initialize the indexed "pointer" + let current_index: usize = 0; + let mut already_visited: bool; + // Initialize the hashmap of visited items (by etag?) + let mut visited_items = HashMap::new(); + match &queue[0].propstat[0].prop { + Some(prop) => { + match &prop.get_etag { + Some(etag) => { + visited_items.insert(etag, true); + () + }, + _ => println!("something's happening"), + } + }, + _ => println!("something's happening"), + } + // Depth first traversal + while !queue.is_empty() { + match &queue[current_index].propstat[0].prop { + Some(prop) => { + match &prop.get_etag { + Some(etag) => { + // If queue[current_index] has not been visited + if !visited_items.contains_key(etag) { + // If item is a collection + + // Get the contents XML + // Parse the contents XML into Multistatus + // Append the NextcloudResponse vector to queue + } + // else + // if item is not public, publicise it. + // Add item to visited items hashmap + // Increment current_index by 1 + () + }, + _ => println!("something's happening"), + } + }, + _ => println!("something's happening"), + } + } +} + fn get_password() -> Result { print!("Nextcloud password: "); io::stdout().flush().unwrap(); @@ -146,16 +195,16 @@ async fn main() -> std::io::Result<()> { .target(Target::Stdout) .init(); println!("Publicise it!"); - let password = get_password().unwrap().trim().to_string(); - debug!("Received password: {}[END]", password); - let folder_contents = - get_folder_contents(password, "/nextcloud/remote.php/dav/files/adam/test_public/2019_test_public") + let folder_contents: String = + get_folder_contents("/nextcloud/remote.php/dav/files/adam/test_public/2019_test_public") .await .unwrap(); debug!("{:?}", folder_contents); let result: Multistatus = from_str(&folder_contents).unwrap(); println!("{:?}", result); + + // traverse(result.response); Ok(()) }