Argh
This commit is contained in:
parent
51c76921a0
commit
bb7d09d1ef
6 changed files with 297 additions and 98 deletions
53
src-tauri/src/data_door.rs
Normal file
53
src-tauri/src/data_door.rs
Normal file
|
@ -0,0 +1,53 @@
|
|||
use chrono::offset::Utc;
|
||||
use curl::{easy, easy::Easy2};
|
||||
use rand::prelude::*;
|
||||
use ring_compat::signature::ed25519::SigningKey;
|
||||
use tauri::{Manager, State};
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
pub struct DoorState {
|
||||
last_sync: i64,
|
||||
id: u64,
|
||||
key: SigningKey,
|
||||
}
|
||||
|
||||
impl DoorState {
|
||||
pub fn new() -> Self {
|
||||
let mut rng = rand::thread_rng();
|
||||
let last_sync = i64::MIN;
|
||||
let id = rng.gen();
|
||||
let key = SigningKey::generate(&mut rng);
|
||||
DoorState { last_sync, id, key }
|
||||
}
|
||||
}
|
||||
|
||||
struct Collector(Vec<u8>);
|
||||
|
||||
impl easy::Handler for Collector {
|
||||
fn write(&mut self, data: &[u8]) -> Result<usize, easy::WriteError> {
|
||||
self.0.extend_from_slice(data);
|
||||
Ok(data.len())
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn pull_data(state: State<'_, Mutex<DoorState>>) -> Result<String, ()> {
|
||||
println!("Hiya");
|
||||
let mut client = Easy2::new(Collector(Vec::new()));
|
||||
client.custom_request("PROPFIND").map_err(|_| ())?;
|
||||
client.url("https://cloud.seebruecke.org/public.php/webdav/data/")
|
||||
.map_err(|_| ())?;
|
||||
client.username(include_str!("cloud_user.txt")).map_err(|_| ())?;
|
||||
client.http_auth(easy::Auth::new().auto(true)).map_err(|_| ())?;
|
||||
client.ssl_cainfo_blob(include_bytes!("isrg-root-x1.pem"))
|
||||
.map_err(|_| ())?;
|
||||
client.perform().map_err(|_| ())?;
|
||||
let content = client.get_ref();
|
||||
Ok(String::from_utf8_lossy(&content.0).to_string())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn push_data(state: State<'_, Mutex<DoorState>>) -> Result<(), ()> {
|
||||
let mut client = Easy2::new(Collector(Vec::new()));
|
||||
Ok(())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue