Refactor
This commit is contained in:
parent
934c704cbf
commit
bd40e5c8d8
4 changed files with 47 additions and 48 deletions
|
@ -5,21 +5,7 @@ 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 }
|
||||
}
|
||||
}
|
||||
use crate::app_state::AppState;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Collector(Vec<u8>, Vec<u8>, usize);
|
||||
|
@ -71,7 +57,6 @@ impl easy::Handler for Collector {
|
|||
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);
|
||||
println!("{}", url);
|
||||
client.url(&url)
|
||||
.map_err(|_| ())?;
|
||||
client.username(include_str!("cloud_user.txt")).map_err(|_| ())?;
|
||||
|
@ -82,7 +67,7 @@ pub fn data_client(file: &str) -> Result<Easy2<Collector>, ()> {
|
|||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn pull_data(state: State<'_, Mutex<DoorState>>) -> 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(|_| ())?;
|
||||
|
@ -91,7 +76,7 @@ pub async fn pull_data(state: State<'_, Mutex<DoorState>>) -> Result<String, ()>
|
|||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn push_data(state: State<'_, Mutex<DoorState>>) -> 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)?;
|
||||
|
@ -100,10 +85,7 @@ pub async fn push_data(state: State<'_, Mutex<DoorState>>) -> Result<String, ()>
|
|||
client.get_mut().1.extend_from_slice(v_key.as_ref());
|
||||
client.in_filesize(v_key.as_ref().len() as u64);
|
||||
client.upload(true);
|
||||
println!("{:?}", client);
|
||||
let perf = client.perform();
|
||||
println!("{:?}", perf);
|
||||
println!("{:?}", client);
|
||||
let perf = client.perform().map_err(|_| ())?;
|
||||
let content = &client.get_ref().0;
|
||||
Ok(String::from_utf8_lossy(content).to_string())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue