Remove hard-coded username instances (#9)

This commit is contained in:
Adam Cooper 2022-03-21 09:30:43 -04:00
parent 5bb7fc6eaf
commit 7d00d6f863

View file

@ -141,7 +141,7 @@ async fn get_folder_contents(url_tail: &str, config: &Config) -> Result<String,
);
let response_text = client
.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)
.send()
.await?
@ -151,7 +151,7 @@ async fn get_folder_contents(url_tail: &str, config: &Config) -> Result<String,
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...");
let url = "https://cloud.theadamcooper.com/ocs/v2.php/apps/files_sharing/api/v1/shares";
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);
let response_text = client
.request(method, url)
.basic_auth("adam", Some(password))
.basic_auth(config.credentials.username.as_str(), config.credentials.password.as_ref())
.header("OCS-APIRequest", "true")
.form(&params)
.send()
@ -202,13 +202,13 @@ async fn traverse(mut result: Multistatus, config: &Config) -> Result<bool, Box<
debug!("[traverse] Node...");
if !(&mut result.response[current_index].propstat[0].prop.share_types).contains(&ShareType{ share_type: 3 }) {
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 = username_seg_string.as_str();
let index = &result.response[current_index].href.find(username_seg).unwrap_or(0);
let new_index = index + username.len() + 2;
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 {
debug!("[traverse] it's already public");
}
@ -236,7 +236,7 @@ async fn main() -> std::io::Result<()> {
}
debug!("[main] {:?}", &config);
let full_path = &(String::from("/remote.php/dav/files/") + &config.credentials.username + "/" + &config.paths.target);
let folder_contents: String =
let folder_contents: String =
get_folder_contents(full_path, &config)
.await
.unwrap();