This commit is contained in:
Bianca Fürstenau 2025-02-11 14:57:40 +01:00
parent bd40e5c8d8
commit 51828ef351
3 changed files with 48 additions and 27 deletions

View file

@ -19,55 +19,60 @@ impl easy::Handler for Collector {
fn read(&mut self, data: &mut [u8]) -> Result<usize, easy::ReadError> {
let p = self.2;
let src: &[u8] = self.1.as_ref();
let n = usize::min(src.len()-p, data.len());
data[..n].copy_from_slice(&src[p..(p+n)]);
self.2 = n+p;
let n = usize::min(src.len() - p, data.len());
data[..n].copy_from_slice(&src[p..(p + n)]);
self.2 = n + p;
Ok(n)
}
fn seek(&mut self, whence: std::io::SeekFrom) -> easy::SeekResult {
use std::io::SeekFrom::{Start, End, Current};
use std::io::SeekFrom::{Current, End, Start};
match whence {
Start(p) => {
self.2 = p as usize;
easy::SeekResult::Ok
},
}
End(d) => {
let p = self.1.len() as i64;
if p+d < 0 {
if p + d < 0 {
easy::SeekResult::Fail
} else {
self.2 = (p+d) as usize;
self.2 = (p + d) as usize;
easy::SeekResult::Ok
}
},
}
Current(d) => {
let p = self.2 as i64;
if p+d < 0 {
if p + d < 0 {
easy::SeekResult::Fail
} else {
self.2 = (p+d) as usize;
self.2 = (p + d) as usize;
easy::SeekResult::Ok
}
},
}
}
}
}
pub fn data_client(file: &str) -> Result<Easy2<Collector>, ()> {
let mut client = Easy2::new(Collector(Vec::new(), Vec::new(), 0));
let url = format!("https://cloud.seebruecke.org/public.php/webdav/data/{}", file);
client.url(&url)
.map_err(|_| ())?;
let url = format!(
"https://cloud.seebruecke.org/public.php/webdav/data/{}",
file
);
client.url(&url).map_err(|_| ())?;
client.username(include_str!("cloud_user.txt")).map_err(|_| ())?;
client.http_auth(easy::Auth::new().auto(true)).map_err(|_| ())?;
client.http_auth(easy::Auth::new().auto(true))
.map_err(|_| ())?;
client.ssl_cainfo_blob(include_bytes!("isrg-root-x1.pem"))
.map_err(|_| ())?;
Ok(client)
}
#[tauri::command]
pub async fn pull_data(state: State<'_, Mutex<AppState>>) -> Result<String, ()> {
pub async fn pull_data(
state: State<'_, Mutex<AppState>>,
) -> Result<String, ()> {
let mut client = data_client("")?;
client.custom_request("PROPFIND").map_err(|_| ())?;
client.perform().map_err(|_| ())?;
@ -76,7 +81,9 @@ pub async fn pull_data(state: State<'_, Mutex<AppState>>) -> Result<String, ()>
}
#[tauri::command]
pub async fn push_data(state: State<'_, Mutex<AppState>>) -> Result<String, ()> {
pub async fn push_data(
state: State<'_, Mutex<AppState>>,
) -> Result<String, ()> {
let state = state.lock().await;
let key_file = format!("{:016X}.key", state.id);
let mut client = data_client(&key_file)?;