Remove hard-coded username instances (#9)
This commit is contained in:
parent
5bb7fc6eaf
commit
7d00d6f863
1 changed files with 6 additions and 6 deletions
10
src/main.rs
10
src/main.rs
|
@ -141,7 +141,7 @@ async fn get_folder_contents(url_tail: &str, config: &Config) -> Result<String,
|
||||||
);
|
);
|
||||||
let response_text = client
|
let response_text = client
|
||||||
.request(method, url)
|
.request(method, url)
|
||||||
.basic_auth("adam", config.credentials.password.as_ref())
|
.basic_auth(config.credentials.username.as_str(), config.credentials.password.as_ref())
|
||||||
.body(body)
|
.body(body)
|
||||||
.send()
|
.send()
|
||||||
.await?
|
.await?
|
||||||
|
@ -151,7 +151,7 @@ async fn get_folder_contents(url_tail: &str, config: &Config) -> Result<String,
|
||||||
Ok(response_text)
|
Ok(response_text)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn publicise_it(path: &str, password: &str) -> Result<bool, Box<dyn std::error::Error>> {
|
async fn publicise_it(path: &str, config: &Config) -> Result<bool, Box<dyn std::error::Error>> {
|
||||||
debug!("[publicise_it] Entering function...");
|
debug!("[publicise_it] Entering function...");
|
||||||
let url = "https://cloud.theadamcooper.com/ocs/v2.php/apps/files_sharing/api/v1/shares";
|
let url = "https://cloud.theadamcooper.com/ocs/v2.php/apps/files_sharing/api/v1/shares";
|
||||||
let method = reqwest::Method::POST;
|
let method = reqwest::Method::POST;
|
||||||
|
@ -161,7 +161,7 @@ async fn publicise_it(path: &str, password: &str) -> Result<bool, Box<dyn std::e
|
||||||
debug!("[publicise_it] params: {:?}", params);
|
debug!("[publicise_it] params: {:?}", params);
|
||||||
let response_text = client
|
let response_text = client
|
||||||
.request(method, url)
|
.request(method, url)
|
||||||
.basic_auth("adam", Some(password))
|
.basic_auth(config.credentials.username.as_str(), config.credentials.password.as_ref())
|
||||||
.header("OCS-APIRequest", "true")
|
.header("OCS-APIRequest", "true")
|
||||||
.form(¶ms)
|
.form(¶ms)
|
||||||
.send()
|
.send()
|
||||||
|
@ -202,13 +202,13 @@ async fn traverse(mut result: Multistatus, config: &Config) -> Result<bool, Box<
|
||||||
debug!("[traverse] Node...");
|
debug!("[traverse] Node...");
|
||||||
if !(&mut result.response[current_index].propstat[0].prop.share_types).contains(&ShareType{ share_type: 3 }) {
|
if !(&mut result.response[current_index].propstat[0].prop.share_types).contains(&ShareType{ share_type: 3 }) {
|
||||||
debug!("[traverse] it's not public");
|
debug!("[traverse] it's not public");
|
||||||
let username = "adam";
|
let username = config.credentials.username.as_str();
|
||||||
let username_seg_string = format!("/{}/", username);
|
let username_seg_string = format!("/{}/", username);
|
||||||
let username_seg = username_seg_string.as_str();
|
let username_seg = username_seg_string.as_str();
|
||||||
let index = &result.response[current_index].href.find(username_seg).unwrap_or(0);
|
let index = &result.response[current_index].href.find(username_seg).unwrap_or(0);
|
||||||
let new_index = index + username.len() + 2;
|
let new_index = index + username.len() + 2;
|
||||||
let new_href = &result.response[current_index].href[new_index..];
|
let new_href = &result.response[current_index].href[new_index..];
|
||||||
publicise_it(new_href, config.credentials.password.as_ref().unwrap()).await.unwrap();
|
publicise_it(new_href, config).await.unwrap();
|
||||||
} else {
|
} else {
|
||||||
debug!("[traverse] it's already public");
|
debug!("[traverse] it's already public");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue