cleaning clone

This commit is contained in:
grimhilt
2023-06-17 15:36:18 +02:00
parent b16058b4d3
commit 7cfd572ad0
6 changed files with 118 additions and 48 deletions

View File

@@ -1,6 +1,32 @@
use std::path::{PathBuf, Path};
use std::env;
#[derive(Debug)]
pub struct ApiProps {
pub host: String, // nextcloud.example.com
pub username: String,
pub root: String, // /dir/cloned
}
impl Clone for ApiProps {
fn clone(&self) -> Self {
ApiProps {
host: self.host.to_string(),
username: self.username.to_string(),
root: self.root.to_string(),
}
}
}
pub fn get_relative_s(p: String, api_props: &ApiProps) -> String {
let mut final_p = p.clone();
final_p = final_p.strip_prefix("/remote.php/dav/files/").unwrap().to_string();
final_p = final_p.strip_prefix(&api_props.username).unwrap().to_string();
final_p = final_p.strip_prefix(&api_props.root).unwrap().to_string();
final_p = final_p.strip_prefix("/").unwrap().to_string();
final_p
}
pub fn get_local_path(p: String, local_p: PathBuf, username: &str, dist_p: &str) -> PathBuf {
let mut final_p = Path::new(p.as_str());
final_p = final_p.strip_prefix("/remote.php/dav/files/").unwrap();