[wip] More debugging statements
Added more debugging statements because maybe tree is not getting fully traversed
This commit is contained in:
parent
d9e0a55a84
commit
cb0173c440
1 changed files with 21 additions and 18 deletions
39
src/main.rs
39
src/main.rs
|
@ -90,12 +90,12 @@ pub struct Collection {
|
|||
}
|
||||
|
||||
async fn get_folder_contents(url_tail: &str, password: &str) -> Result<String, Box<dyn std::error::Error>> {
|
||||
debug!("Entering: get_folder_contents()");
|
||||
debug!("[get_folder_contents] Entering function...");
|
||||
let root_url = Url::parse("https://theadamcooper.com")?;
|
||||
let method = reqwest::Method::from_bytes(b"PROPFIND").unwrap();
|
||||
let client = reqwest::Client::new();
|
||||
let url = root_url.join(url_tail)?;
|
||||
debug!("get_folder_contents: url: {}", url);
|
||||
debug!("[get_folder_contents] url: {}", url);
|
||||
let body = String::from(
|
||||
r#"<?xml version="1.0" encoding="UTF-8"?>
|
||||
<d:propfind xmlns:d="DAV:">
|
||||
|
@ -118,18 +118,18 @@ async fn get_folder_contents(url_tail: &str, password: &str) -> Result<String, B
|
|||
.await?
|
||||
.text()
|
||||
.await?;
|
||||
debug!("get_folder_contents: response_text: {:?}", response_text);
|
||||
debug!("[get_folder_contents] response_text: {:?}", response_text);
|
||||
Ok(response_text)
|
||||
}
|
||||
|
||||
async fn publicise_it(path: &str, password: &str) -> Result<bool, Box<dyn std::error::Error>> {
|
||||
debug!("Entering: publicise()");
|
||||
debug!("[publicise_it] Entering function...");
|
||||
let url = "https://theadamcooper.com/nextcloud/ocs/v2.php/apps/files_sharing/api/v1/shares";
|
||||
let method = reqwest::Method::POST;
|
||||
let client = reqwest::Client::new();
|
||||
let params = [("path", path), ("shareType", "3")];
|
||||
debug!("publicise_it: url: {}", url);
|
||||
debug!("params: {:?}", params);
|
||||
debug!("[publicise_it] url: {}", url);
|
||||
debug!("[publicise_it] params: {:?}", params);
|
||||
let response_text = client
|
||||
.request(method, url)
|
||||
.basic_auth("adam", Some(password))
|
||||
|
@ -139,12 +139,12 @@ async fn publicise_it(path: &str, password: &str) -> Result<bool, Box<dyn std::e
|
|||
.await?
|
||||
.text()
|
||||
.await?;
|
||||
debug!("publicise_it: response_text: {:?}", response_text);
|
||||
debug!("[publicise_it] response_text: {:?}", response_text);
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
async fn traverse(mut result: Multistatus, password: &str) -> Result<bool, Box<dyn std::error::Error>> {
|
||||
debug!("Entering: traverse()");
|
||||
debug!("[traverse] Entering function...");
|
||||
// Initialize the indexed "pointer"
|
||||
let mut current_index: usize = 0;
|
||||
// Initialize the hashmap of visited items (by etag?)
|
||||
|
@ -155,14 +155,15 @@ async fn traverse(mut result: Multistatus, password: &str) -> Result<bool, Box<d
|
|||
|
||||
// Depth first traversal
|
||||
while current_index < (&mut result.response).len() {
|
||||
debug!("current_index: {:?}", current_index);
|
||||
debug!("[traverse] current_index: {:?}", current_index);
|
||||
debug!("[traverse] current href: {}", &result.response[current_index].href);
|
||||
let mut etag = (&mut result.response[current_index].propstat[0].prop.get_etag).clone();
|
||||
// If result.response[current_index] has not been visited
|
||||
if !visited_items.contains_key(&etag) {
|
||||
debug!("Fresh item...");
|
||||
debug!("[traverse] Fresh item...");
|
||||
// if it's a collection
|
||||
if !(&mut result.response[current_index].propstat[0].prop.resource_type.collection).is_empty() {
|
||||
debug!("Collection...");
|
||||
debug!("[traverse] Collection...");
|
||||
// Get the contents XML
|
||||
let folder_contents: String = get_folder_contents(
|
||||
&result.response[current_index].href, // change to mutable borrow if necessary
|
||||
|
@ -173,14 +174,15 @@ async fn traverse(mut result: Multistatus, password: &str) -> Result<bool, Box<d
|
|||
// debug!("{:?}", folder_contents);
|
||||
// Parse the contents XML into Multistatus
|
||||
let mut new_result: Multistatus = from_str(&String::from(folder_contents)).unwrap();
|
||||
debug!("\nParsed:\n{:?}", new_result);
|
||||
debug!("[traverse] Parsed:\n{:?}", new_result);
|
||||
// Append the NextcloudResponse vector to result.response
|
||||
result.response.append(&mut new_result.response);
|
||||
debug!("[traverse] new vector length: {}", &result.response.len());
|
||||
} else {
|
||||
debug!("Node...");
|
||||
debug!("[traverse] Node...");
|
||||
// else it's a node. if it's not public, publicise it.
|
||||
if !(&mut result.response[current_index].propstat[0].prop.share_types).contains(&ShareType{ share_type: 3 }) {
|
||||
println!("it's not public");
|
||||
debug!("[traverse] it's not public");
|
||||
// Search for username and lop.
|
||||
let username = "adam";
|
||||
let username_seg_string = format!("/{}/", username);
|
||||
|
@ -190,10 +192,13 @@ async fn traverse(mut result: Multistatus, password: &str) -> Result<bool, Box<d
|
|||
let new_href = &result.response[current_index].href[new_index..];
|
||||
publicise_it(new_href, password).await.unwrap();
|
||||
} else {
|
||||
println!("it's already public");
|
||||
debug!("[traverse] it's already public");
|
||||
}
|
||||
}
|
||||
visited_items.insert(etag, true);
|
||||
debug!("[traverse] visited items: {:?}", visited_items);
|
||||
} else {
|
||||
debug!("[traverse] Already-visited item.");
|
||||
}
|
||||
current_index += 1;
|
||||
}
|
||||
|
@ -230,14 +235,12 @@ async fn main() -> std::io::Result<()> {
|
|||
|
||||
let password: String = get_password().unwrap().trim().to_string();
|
||||
let folder_contents: String =
|
||||
// get_folder_contents("/nextcloud/remote.php/dav/files/adam/test_public/2019_test_public")
|
||||
get_folder_contents("/nextcloud/remote.php/dav/files/adam/test_public", &password)
|
||||
.await
|
||||
.unwrap();
|
||||
// debug!("{:?}", folder_contents);
|
||||
|
||||
let mut result: Multistatus = from_str(&folder_contents).unwrap();
|
||||
println!("{:?}", result);
|
||||
debug!("{:?}", result);
|
||||
|
||||
let _ = traverse(result, &password).await.unwrap();
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in a new issue