add deletion of file

This commit is contained in:
grimhilt
2023-06-15 17:33:12 +02:00
parent 35adfab983
commit 49d83c2900
5 changed files with 93 additions and 65 deletions

View File

@@ -1,50 +0,0 @@
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(())
}

View File

@@ -1,7 +1,7 @@
use crate::services::api::{ApiBuilder, ApiError};
use xml::reader::{EventReader, XmlEvent};
use std::io::{self, Cursor};
use reqwest::{Method, IntoUrl, Response, Error};
use std::io::Cursor;
use reqwest::{Method, Response, Error};
pub struct ReqProps {
api_builder: ApiBuilder,

View File

@@ -1,9 +1,8 @@
use xml::reader::{EventReader, XmlEvent};
use std::fs::File;
use crate::services::api::{ApiBuilder, ApiError};
use std::path::PathBuf;
use std::io::{self, Read};
use reqwest::{Method, IntoUrl, Response, Error};
use std::io::{Read};
use reqwest::{Method, Response, Error};
pub struct UploadFile {
api_builder: ApiBuilder,