This commit is contained in:
grimhilt 2023-05-31 16:32:40 +02:00
commit 4150a67a59
4 changed files with 1422 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
target
*.test
.env

1345
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

11
Cargo.toml Normal file
View File

@ -0,0 +1,11 @@
[package]
name = "next-sync"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
reqwest = { version = "0.11", features = ["blocking", "json", "multipart"] }
tokio = { version = "1", features = ["full"] }
dotenv ="0.15.0"

63
src/main.rs Normal file
View File

@ -0,0 +1,63 @@
use reqwest::Client;
use reqwest::header::{HeaderValue, CONTENT_TYPE, HeaderMap};
use std::error::Error;
use std::env;
use dotenv::dotenv;
async fn send_propfind_request() -> Result<(), Box<dyn Error>> {
dotenv().ok();
let mut api_endpoint = env::var("HOST").unwrap().to_owned();
api_endpoint.push_str("/remote.php/dav/files/");
let username = env::var("USERNAME").unwrap();
api_endpoint.push_str(&username);
api_endpoint.push_str("/test");
let password = env::var("PASSWORD").unwrap();
// Create a reqwest client
let client = Client::new();
// Create the XML payload
let xml_payload = r#"<?xml version="1.0" encoding="UTF-8"?>
<d:propfind xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns" xmlns:nc="http://nextcloud.org/ns">
<d:prop>
<d:getlastmodified/>
<d:getcontentlength/>
<d:getcontenttype/>
<oc:permissions/>
<d:resourcetype/>
<d:getetag/>
</d:prop>
</d:propfind>"#;
let mut headers = HeaderMap::new();
headers.insert(CONTENT_TYPE, HeaderValue::from_static("application/xml"));
// Send the request
let response = client
.request(reqwest::Method::from_bytes(b"PROPFIND").unwrap(), api_endpoint)
.basic_auth(username, Some(password))
.headers(headers)
.body(xml_payload)
.send()
.await?;
// Handle the response
if response.status().is_success() {
let body = response.text().await?;
println!("Response body: {}", body);
} else {
println!("Request failed with status code: {}", response.status());
}
Ok(())
}
fn main() {
tokio::runtime::Runtime::new().unwrap().block_on(async {
if let Err(err) = send_propfind_request().await {
eprintln!("Error: {}", err);
}
});
}